1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.mindcrimeilab.xsanalyzer;
19
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.apache.xerces.impl.xs.util.XSObjectListImpl;
25 import org.apache.xerces.xs.XSObject;
26 import org.apache.xerces.xs.XSObjectList;
27 import org.apache.xerces.xs.XSTypeDefinition;
28
29 import de.mindcrimeilab.xsanalyzer.util.XSModelHelper;
30
31
32
33
34
35
36
37 public class TypeUsageWorker extends AbstractXsComponentWorker implements XsComponentWorker {
38
39
40 private final Map<XSObject, XSObjectListImpl> usedBy;
41
42 public TypeUsageWorker() {
43 super();
44 usedBy = new HashMap<XSObject, XSObjectListImpl>();
45 }
46
47
48
49
50
51
52 public Map<XSObject, ? extends XSObjectList> getUsedBy() {
53 return Collections.unmodifiableMap(usedBy);
54 }
55
56
57
58
59
60
61
62 @Override
63 public void execute(XSObject object, XSObject parent) {
64 final XSTypeDefinition type = XSModelHelper.getBaseType(object);
65 if (null == type) { return; }
66
67 addUsedByType(object, type);
68
69 }
70
71
72
73
74
75
76 @Override
77 public boolean isSupported(XSObject object) {
78
79 return true;
80 }
81
82
83
84
85
86
87
88
89
90 private void addUsedByType(XSObject element, XSTypeDefinition type) {
91
92 if (null == element) { return; }
93
94
95 if (XSModelHelper.isSameTypeDefinition(element, type)) { return; }
96
97 if (usedBy.containsKey(type)) {
98 final XSObjectListImpl objectList = usedBy.get(type);
99 for (int i = 0; i < objectList.getLength(); ++i) {
100 XSObject object = objectList.item(i);
101
102 if (XSModelHelper.isSameTypeDefinition(object, element)) { return; }
103 }
104 objectList.add(element);
105 }
106 else {
107 final XSObjectListImpl xsoList = new XSObjectListImpl();
108 xsoList.add(element);
109 usedBy.put(type, xsoList);
110 }
111 }
112
113 }