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.ArrayList; |
21 |
|
import java.util.Collection; |
22 |
|
import java.util.Iterator; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.apache.commons.betwixt.ElementDescriptor; |
26 |
|
import org.apache.commons.betwixt.XMLBeanInfo; |
27 |
|
import org.apache.commons.betwixt.XMLIntrospector; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
public class Schema { |
36 |
|
|
37 |
325 |
private List elements = new ArrayList(); |
38 |
325 |
private List complexTypes = new ArrayList(); |
39 |
325 |
private List simpleTypes = new ArrayList(); |
40 |
|
|
41 |
|
private XMLIntrospector introspector; |
42 |
|
|
43 |
|
public Schema() { |
44 |
78 |
this(new XMLIntrospector()); |
45 |
78 |
} |
46 |
|
|
47 |
325 |
public Schema(XMLIntrospector introspector) { |
48 |
325 |
this.introspector = introspector; |
49 |
325 |
} |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
public XMLBeanInfo introspect(Class type) throws IntrospectionException { |
58 |
442 |
return introspector.introspect(type); |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
public List getComplexTypes() { |
66 |
169 |
return complexTypes; |
67 |
|
} |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
public void addComplexType(GlobalComplexType complexType) { |
75 |
598 |
complexTypes.add(complexType); |
76 |
598 |
} |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
public List getElements() { |
84 |
169 |
return elements; |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
public void addElement(GlobalElement element) { |
92 |
325 |
elements.add(element); |
93 |
325 |
} |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
public List getSimpleTypes() { |
100 |
169 |
return simpleTypes; |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
public void addSimpleType(SimpleType simpleType) { |
108 |
0 |
simpleTypes.add(simpleType); |
109 |
0 |
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
public void addGlobalElementType(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor) throws IntrospectionException { |
117 |
|
|
118 |
|
|
119 |
494 |
GlobalElement element = new GlobalElement( |
120 |
247 |
elementDescriptor.getLocalName(), |
121 |
247 |
configuration.getSchemaTypeNamingStrategy().nameSchemaType(elementDescriptor)); |
122 |
247 |
addElement(element); |
123 |
247 |
addGlobalComplexType(configuration, elementDescriptor); |
124 |
247 |
} |
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
public GlobalComplexType addGlobalComplexType(TranscriptionConfiguration configuration, ElementDescriptor elementDescriptor) throws IntrospectionException { |
137 |
494 |
GlobalComplexType type = null; |
138 |
1378 |
for (Iterator it = complexTypes.iterator(); it.hasNext();) { |
139 |
416 |
GlobalComplexType complexType = (GlobalComplexType) it.next(); |
140 |
416 |
if (complexType.matches( elementDescriptor )) { |
141 |
26 |
type = complexType; |
142 |
26 |
break; |
143 |
|
} |
144 |
|
} |
145 |
494 |
if (type == null) { |
146 |
468 |
type = new GlobalComplexType(configuration, elementDescriptor, this); |
147 |
468 |
addComplexType(type); |
148 |
468 |
type.fill(configuration, elementDescriptor, this); |
149 |
|
} |
150 |
494 |
return type; |
151 |
|
} |
152 |
|
|
153 |
|
public boolean equals(Object obj) { |
154 |
78 |
boolean result = false; |
155 |
78 |
if (obj instanceof Schema) { |
156 |
78 |
Schema schema = (Schema) obj; |
157 |
78 |
result = |
158 |
78 |
equalContents(elements, schema.elements) && |
159 |
78 |
equalContents(complexTypes, schema.complexTypes) && |
160 |
78 |
equalContents(simpleTypes, schema.simpleTypes); |
161 |
|
} |
162 |
78 |
return result; |
163 |
|
} |
164 |
|
|
165 |
|
private boolean equalContents(Collection one, Collection two) |
166 |
|
{ |
167 |
|
|
168 |
234 |
if (one.size() != two.size()) { |
169 |
0 |
return false; |
170 |
|
} |
171 |
676 |
for (Iterator it=one.iterator();it.hasNext();) { |
172 |
208 |
Object object = it.next(); |
173 |
208 |
if (!two.contains(object)) { |
174 |
0 |
return false; |
175 |
|
} |
176 |
|
} |
177 |
234 |
return true; |
178 |
|
} |
179 |
|
|
180 |
|
public int hashCode() { |
181 |
338 |
return 0; |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
public String toString() { |
187 |
0 |
StringBuffer buffer = new StringBuffer(); |
188 |
0 |
buffer.append("<?xml version='1.0'?>"); |
189 |
0 |
buffer.append("<xsd:schema xmlns:xsd='http://www.w3c.org/2001/XMLSchema'>"); |
190 |
|
|
191 |
0 |
for (Iterator it=simpleTypes.iterator(); it.hasNext();) { |
192 |
0 |
buffer.append(it.next()); |
193 |
|
} |
194 |
|
|
195 |
0 |
for (Iterator it=complexTypes.iterator(); it.hasNext();) { |
196 |
0 |
buffer.append(it.next()); |
197 |
|
} |
198 |
|
|
199 |
|
|
200 |
0 |
for (Iterator it=elements.iterator(); it.hasNext();) { |
201 |
0 |
buffer.append(it.next()); |
202 |
|
} |
203 |
0 |
buffer.append("</xsd:schema>"); |
204 |
0 |
return buffer.toString(); |
205 |
|
} |
206 |
|
} |