1
2
3
4
5 package de.mindcrimeilab.xsanalyzer.rules.constraints;
6
7 import java.util.ArrayList;
8 import java.util.List;
9 import java.util.Observable;
10
11 import org.apache.xerces.xs.XSConstants;
12 import org.apache.xerces.xs.XSObject;
13 import org.apache.xerces.xs.XSTypeDefinition;
14 import org.springframework.core.closure.Constraint;
15
16 import de.mindcrimeilab.util.Accessor;
17
18
19
20
21
22
23
24
25
26 public class SchemaTypeConstraint extends Observable implements Constraint {
27
28 private final List<Short> visibleTypes;
29
30 private Accessor accessor;
31
32 public SchemaTypeConstraint() {
33 super();
34 visibleTypes = new ArrayList<Short>();
35 visibleTypes.add(XSConstants.ELEMENT_DECLARATION);
36 visibleTypes.add(XSConstants.ATTRIBUTE_DECLARATION);
37 visibleTypes.add(XSConstants.MODEL_GROUP_DEFINITION);
38 visibleTypes.add(XSTypeDefinition.COMPLEX_TYPE);
39 visibleTypes.add(XSTypeDefinition.SIMPLE_TYPE);
40 accessor = null;
41 }
42
43 public SchemaTypeConstraint(Accessor accessor) {
44 this();
45 this.accessor = accessor;
46
47 }
48
49 @Override
50 public boolean test(Object argument) {
51 final XSObject testObject;
52 if (argument instanceof XSObject) {
53 testObject = (XSObject) argument;
54 }
55 else {
56 testObject = (XSObject) accessor.getValue(argument);
57 }
58
59 short type = (testObject).getType();
60 if (type == XSConstants.TYPE_DEFINITION) {
61 type = ((XSTypeDefinition) testObject).getTypeCategory();
62 }
63
64 return visibleTypes.contains(type);
65 }
66
67
68
69
70
71
72 private boolean test0(final Object object) {
73 boolean passesTest = false;
74
75 return passesTest;
76 }
77
78
79
80
81
82
83
84
85
86 public void setFilter(short type, boolean filtered) {
87 if (filtered) {
88 visibleTypes.remove((Short) type);
89 }
90 else {
91 if (!visibleTypes.contains(type)) {
92 visibleTypes.add(type);
93 }
94 }
95 setChanged();
96 notifyObservers();
97 }
98 }