1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.commons.betwixt.schema; |
18 |
|
|
19 |
|
import java.beans.IntrospectionException; |
20 |
|
import java.util.Collection; |
21 |
|
import java.util.Iterator; |
22 |
|
|
23 |
|
import org.apache.commons.betwixt.ElementDescriptor; |
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
public class GlobalComplexType extends ComplexType { |
32 |
|
|
33 |
|
private String name; |
34 |
|
private TranscriptionConfiguration configuration; |
35 |
|
|
36 |
130 |
public GlobalComplexType() {} |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
public GlobalComplexType(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException { |
43 |
468 |
super(configuration, elementDescriptor, schema); |
44 |
468 |
} |
45 |
|
|
46 |
|
protected void init(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException { |
47 |
468 |
this.configuration = configuration; |
48 |
468 |
setName(nameFromDescriptor( elementDescriptor )); |
49 |
468 |
} |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
protected void fill(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException |
60 |
|
{ |
61 |
468 |
elementDescriptor = fillDescriptor(elementDescriptor, schema); |
62 |
468 |
super.init(configuration, elementDescriptor, schema); |
63 |
468 |
} |
64 |
|
|
65 |
|
private String nameFromDescriptor( ElementDescriptor elementDescriptor ) { |
66 |
884 |
return configuration.getSchemaTypeNamingStrategy().nameSchemaType(elementDescriptor); |
67 |
|
} |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
public boolean matches(ElementDescriptor elementDescriptor) { |
76 |
416 |
String nameFromDescriptor = nameFromDescriptor ( elementDescriptor ); |
77 |
416 |
return nameFromDescriptor.equals(getName()); |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
public String getName() { |
85 |
1053 |
return name; |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
public void setName(String string) { |
93 |
598 |
name = string; |
94 |
598 |
} |
95 |
|
|
96 |
|
public boolean equals(Object obj) { |
97 |
4121 |
boolean result = false; |
98 |
4121 |
if (obj instanceof GlobalComplexType) { |
99 |
819 |
GlobalComplexType complexType = (GlobalComplexType) obj; |
100 |
1638 |
result = isEqual(name, complexType.name) && |
101 |
130 |
equalContents(attributes, complexType.attributes) && |
102 |
130 |
equalContents(elements, complexType.elements); |
103 |
|
|
104 |
|
} |
105 |
4121 |
return result; |
106 |
|
} |
107 |
|
|
108 |
|
public int hashCode() { |
109 |
676 |
return 0; |
110 |
|
} |
111 |
|
|
112 |
|
private boolean equalContents(Collection one, Collection two) |
113 |
|
{ |
114 |
|
|
115 |
260 |
if (one.size() != two.size()) { |
116 |
0 |
return false; |
117 |
|
} |
118 |
1131 |
for (Iterator it=one.iterator();it.hasNext();) { |
119 |
611 |
Object object = it.next(); |
120 |
611 |
if (!two.contains(object)) { |
121 |
0 |
return false; |
122 |
|
} |
123 |
|
} |
124 |
260 |
return true; |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
private boolean isEqual(String one, String two) { |
134 |
819 |
boolean result = false; |
135 |
819 |
if (one == null) { |
136 |
0 |
result = (two == null); |
137 |
|
} |
138 |
|
else |
139 |
|
{ |
140 |
819 |
result = one.equals(two); |
141 |
|
} |
142 |
|
|
143 |
819 |
return result; |
144 |
|
} |
145 |
|
|
146 |
|
public String toString() { |
147 |
0 |
StringBuffer buffer = new StringBuffer(); |
148 |
0 |
buffer.append("<xsd:complexType name='"); |
149 |
0 |
buffer.append(name); |
150 |
0 |
buffer.append("'>"); |
151 |
0 |
buffer.append("<xsd:sequence>"); |
152 |
0 |
for (Iterator it=elements.iterator(); it.hasNext();) { |
153 |
0 |
buffer.append(it.next()); |
154 |
|
} |
155 |
0 |
buffer.append("</xsd:sequence>"); |
156 |
|
|
157 |
0 |
for (Iterator it=attributes.iterator(); it.hasNext();) { |
158 |
0 |
buffer.append(it.next()); |
159 |
|
} |
160 |
0 |
buffer.append("</xsd:complexType>"); |
161 |
0 |
return buffer.toString(); |
162 |
|
} |
163 |
|
} |