author | mkos |
Sun, 30 Dec 2012 00:00:00 +0100 | |
changeset 22678 | ac1ea46be942 |
parent 12009 | 4abb694f273a |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
22678
ac1ea46be942
8029237: Update copyright year to match last edit in jaxws repository for 2012
mkos
parents:
12009
diff
changeset
|
2 |
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
12009 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.xml.internal.xsom.impl; |
|
27 |
||
28 |
import com.sun.xml.internal.xsom.SCD; |
|
29 |
import com.sun.xml.internal.xsom.XSAttGroupDecl; |
|
30 |
import com.sun.xml.internal.xsom.XSAttributeDecl; |
|
31 |
import com.sun.xml.internal.xsom.XSAttributeUse; |
|
32 |
import com.sun.xml.internal.xsom.XSComplexType; |
|
33 |
import com.sun.xml.internal.xsom.XSComponent; |
|
34 |
import com.sun.xml.internal.xsom.XSContentType; |
|
35 |
import com.sun.xml.internal.xsom.XSElementDecl; |
|
36 |
import com.sun.xml.internal.xsom.XSFacet; |
|
37 |
import com.sun.xml.internal.xsom.XSIdentityConstraint; |
|
38 |
import com.sun.xml.internal.xsom.XSListSimpleType; |
|
39 |
import com.sun.xml.internal.xsom.XSModelGroup; |
|
40 |
import com.sun.xml.internal.xsom.XSModelGroupDecl; |
|
41 |
import com.sun.xml.internal.xsom.XSNotation; |
|
42 |
import com.sun.xml.internal.xsom.XSParticle; |
|
43 |
import com.sun.xml.internal.xsom.XSRestrictionSimpleType; |
|
44 |
import com.sun.xml.internal.xsom.XSSchema; |
|
45 |
import com.sun.xml.internal.xsom.XSSchemaSet; |
|
46 |
import com.sun.xml.internal.xsom.XSSimpleType; |
|
47 |
import com.sun.xml.internal.xsom.XSType; |
|
48 |
import com.sun.xml.internal.xsom.XSUnionSimpleType; |
|
49 |
import com.sun.xml.internal.xsom.XSVariety; |
|
50 |
import com.sun.xml.internal.xsom.XSWildcard; |
|
51 |
import com.sun.xml.internal.xsom.impl.scd.Iterators; |
|
52 |
import com.sun.xml.internal.xsom.visitor.XSContentTypeFunction; |
|
53 |
import com.sun.xml.internal.xsom.visitor.XSContentTypeVisitor; |
|
54 |
import com.sun.xml.internal.xsom.visitor.XSFunction; |
|
55 |
import com.sun.xml.internal.xsom.visitor.XSSimpleTypeFunction; |
|
56 |
import com.sun.xml.internal.xsom.visitor.XSSimpleTypeVisitor; |
|
57 |
import com.sun.xml.internal.xsom.visitor.XSVisitor; |
|
58 |
import org.xml.sax.Locator; |
|
59 |
||
60 |
import javax.xml.namespace.NamespaceContext; |
|
61 |
import java.text.ParseException; |
|
62 |
import java.util.ArrayList; |
|
63 |
import java.util.Collection; |
|
64 |
import java.util.Collections; |
|
65 |
import java.util.HashMap; |
|
66 |
import java.util.Iterator; |
|
67 |
import java.util.List; |
|
68 |
import java.util.Map; |
|
69 |
import java.util.Vector; |
|
70 |
||
71 |
public class SchemaSetImpl implements XSSchemaSet |
|
72 |
{ |
|
73 |
private final Map<String,XSSchema> schemas = new HashMap<String,XSSchema>(); |
|
74 |
private final Vector<XSSchema> schemas2 = new Vector<XSSchema>(); |
|
75 |
private final List<XSSchema> readonlySchemaList = Collections.unmodifiableList(schemas2); |
|
76 |
||
77 |
/** |
|
78 |
* Gets a reference to the existing schema or creates a new one |
|
79 |
* if none exists yet. |
|
80 |
*/ |
|
81 |
public SchemaImpl createSchema(String targetNamespace, Locator location) { |
|
82 |
SchemaImpl obj = (SchemaImpl)schemas.get(targetNamespace); |
|
83 |
if (obj == null) { |
|
84 |
obj = new SchemaImpl(this, location, targetNamespace); |
|
85 |
schemas.put(targetNamespace, obj); |
|
86 |
schemas2.add(obj); |
|
87 |
} |
|
88 |
return obj; |
|
89 |
} |
|
90 |
||
91 |
public int getSchemaSize() { |
|
92 |
return schemas.size(); |
|
93 |
} |
|
94 |
public XSSchema getSchema(String targetNamespace) { |
|
95 |
return schemas.get(targetNamespace); |
|
96 |
} |
|
97 |
public XSSchema getSchema(int idx) { |
|
98 |
return schemas2.get(idx); |
|
99 |
} |
|
100 |
public Iterator<XSSchema> iterateSchema() { |
|
101 |
return schemas2.iterator(); |
|
102 |
} |
|
103 |
||
104 |
public final Collection<XSSchema> getSchemas() { |
|
105 |
return readonlySchemaList; |
|
106 |
} |
|
107 |
||
108 |
public XSType getType(String ns, String localName) { |
|
109 |
XSSchema schema = getSchema(ns); |
|
110 |
if(schema==null) return null; |
|
111 |
||
112 |
return schema.getType(localName); |
|
113 |
} |
|
114 |
||
115 |
public XSSimpleType getSimpleType( String ns, String localName ) { |
|
116 |
XSSchema schema = getSchema(ns); |
|
117 |
if(schema==null) return null; |
|
118 |
||
119 |
return schema.getSimpleType(localName); |
|
120 |
} |
|
121 |
||
122 |
public XSElementDecl getElementDecl( String ns, String localName ) { |
|
123 |
XSSchema schema = getSchema(ns); |
|
124 |
if(schema==null) return null; |
|
125 |
||
126 |
return schema.getElementDecl(localName); |
|
127 |
} |
|
128 |
||
129 |
public XSAttributeDecl getAttributeDecl( String ns, String localName ) { |
|
130 |
XSSchema schema = getSchema(ns); |
|
131 |
if(schema==null) return null; |
|
132 |
||
133 |
return schema.getAttributeDecl(localName); |
|
134 |
} |
|
135 |
||
136 |
public XSModelGroupDecl getModelGroupDecl( String ns, String localName ) { |
|
137 |
XSSchema schema = getSchema(ns); |
|
138 |
if(schema==null) return null; |
|
139 |
||
140 |
return schema.getModelGroupDecl(localName); |
|
141 |
} |
|
142 |
||
143 |
public XSAttGroupDecl getAttGroupDecl( String ns, String localName ) { |
|
144 |
XSSchema schema = getSchema(ns); |
|
145 |
if(schema==null) return null; |
|
146 |
||
147 |
return schema.getAttGroupDecl(localName); |
|
148 |
} |
|
149 |
||
150 |
public XSComplexType getComplexType( String ns, String localName ) { |
|
151 |
XSSchema schema = getSchema(ns); |
|
152 |
if(schema==null) return null; |
|
153 |
||
154 |
return schema.getComplexType(localName); |
|
155 |
} |
|
156 |
||
157 |
public XSIdentityConstraint getIdentityConstraint(String ns, String localName) { |
|
158 |
XSSchema schema = getSchema(ns); |
|
159 |
if(schema==null) return null; |
|
160 |
||
161 |
return schema.getIdentityConstraint(localName); |
|
162 |
} |
|
163 |
||
164 |
public Iterator<XSElementDecl> iterateElementDecls() { |
|
165 |
return new Iterators.Map<XSElementDecl,XSSchema>(iterateSchema()) { |
|
166 |
protected Iterator<XSElementDecl> apply(XSSchema u) { |
|
167 |
return u.iterateElementDecls(); |
|
168 |
} |
|
169 |
}; |
|
170 |
} |
|
171 |
||
172 |
public Iterator<XSType> iterateTypes() { |
|
173 |
return new Iterators.Map<XSType,XSSchema>(iterateSchema()) { |
|
174 |
protected Iterator<XSType> apply(XSSchema u) { |
|
175 |
return u.iterateTypes(); |
|
176 |
} |
|
177 |
}; |
|
178 |
} |
|
179 |
||
180 |
public Iterator<XSAttributeDecl> iterateAttributeDecls() { |
|
181 |
return new Iterators.Map<XSAttributeDecl,XSSchema>(iterateSchema()) { |
|
182 |
protected Iterator<XSAttributeDecl> apply(XSSchema u) { |
|
183 |
return u.iterateAttributeDecls(); |
|
184 |
} |
|
185 |
}; |
|
186 |
} |
|
187 |
public Iterator<XSAttGroupDecl> iterateAttGroupDecls() { |
|
188 |
return new Iterators.Map<XSAttGroupDecl,XSSchema>(iterateSchema()) { |
|
189 |
protected Iterator<XSAttGroupDecl> apply(XSSchema u) { |
|
190 |
return u.iterateAttGroupDecls(); |
|
191 |
} |
|
192 |
}; |
|
193 |
} |
|
194 |
public Iterator<XSModelGroupDecl> iterateModelGroupDecls() { |
|
195 |
return new Iterators.Map<XSModelGroupDecl,XSSchema>(iterateSchema()) { |
|
196 |
protected Iterator<XSModelGroupDecl> apply(XSSchema u) { |
|
197 |
return u.iterateModelGroupDecls(); |
|
198 |
} |
|
199 |
}; |
|
200 |
} |
|
201 |
public Iterator<XSSimpleType> iterateSimpleTypes() { |
|
202 |
return new Iterators.Map<XSSimpleType,XSSchema>(iterateSchema()) { |
|
203 |
protected Iterator<XSSimpleType> apply(XSSchema u) { |
|
204 |
return u.iterateSimpleTypes(); |
|
205 |
} |
|
206 |
}; |
|
207 |
} |
|
208 |
public Iterator<XSComplexType> iterateComplexTypes() { |
|
209 |
return new Iterators.Map<XSComplexType,XSSchema>(iterateSchema()) { |
|
210 |
protected Iterator<XSComplexType> apply(XSSchema u) { |
|
211 |
return u.iterateComplexTypes(); |
|
212 |
} |
|
213 |
}; |
|
214 |
} |
|
215 |
public Iterator<XSNotation> iterateNotations() { |
|
216 |
return new Iterators.Map<XSNotation,XSSchema>(iterateSchema()) { |
|
217 |
protected Iterator<XSNotation> apply(XSSchema u) { |
|
218 |
return u.iterateNotations(); |
|
219 |
} |
|
220 |
}; |
|
221 |
} |
|
222 |
||
223 |
public Iterator<XSIdentityConstraint> iterateIdentityConstraints() { |
|
224 |
return new Iterators.Map<XSIdentityConstraint,XSSchema>(iterateSchema()) { |
|
225 |
protected Iterator<XSIdentityConstraint> apply(XSSchema u) { |
|
226 |
return u.getIdentityConstraints().values().iterator(); |
|
227 |
} |
|
228 |
}; |
|
229 |
} |
|
230 |
||
231 |
public Collection<XSComponent> select(String scd, NamespaceContext nsContext) { |
|
232 |
try { |
|
233 |
return SCD.create(scd,nsContext).select(this); |
|
234 |
} catch (ParseException e) { |
|
235 |
throw new IllegalArgumentException(e); |
|
236 |
} |
|
237 |
} |
|
238 |
||
239 |
public XSComponent selectSingle(String scd, NamespaceContext nsContext) { |
|
240 |
try { |
|
241 |
return SCD.create(scd,nsContext).selectSingle(this); |
|
242 |
} catch (ParseException e) { |
|
243 |
throw new IllegalArgumentException(e); |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
||
248 |
public final EmptyImpl empty = new EmptyImpl(); |
|
249 |
public XSContentType getEmpty() { return empty; } |
|
250 |
||
251 |
public XSSimpleType getAnySimpleType() { return anySimpleType; } |
|
252 |
public final AnySimpleType anySimpleType = new AnySimpleType(); |
|
253 |
private class AnySimpleType extends DeclarationImpl |
|
254 |
implements XSRestrictionSimpleType, Ref.SimpleType { |
|
255 |
||
256 |
AnySimpleType() { |
|
257 |
super(null,null,null,null,"http://www.w3.org/2001/XMLSchema","anySimpleType",false); |
|
258 |
} |
|
259 |
public SchemaImpl getOwnerSchema() { |
|
260 |
return createSchema("http://www.w3.org/2001/XMLSchema",null); |
|
261 |
} |
|
262 |
public XSSimpleType asSimpleType() { return this; } |
|
263 |
public XSComplexType asComplexType() { return null; } |
|
264 |
||
265 |
public boolean isDerivedFrom(XSType t) { |
|
266 |
return t==this || t==anyType; |
|
267 |
} |
|
268 |
||
269 |
public boolean isSimpleType() { return true; } |
|
270 |
public boolean isComplexType() { return false; } |
|
271 |
public XSContentType asEmpty() { return null; } |
|
272 |
public XSParticle asParticle() { return null; } |
|
273 |
public XSType getBaseType() { return anyType; } |
|
274 |
public XSSimpleType getSimpleBaseType() { return null; } |
|
275 |
public int getDerivationMethod() { return RESTRICTION; } |
|
276 |
public Iterator<XSFacet> iterateDeclaredFacets() { return Iterators.empty(); } |
|
277 |
public Collection<? extends XSFacet> getDeclaredFacets() { return Collections.EMPTY_LIST; } |
|
278 |
public void visit( XSSimpleTypeVisitor visitor ) {visitor.restrictionSimpleType(this); } |
|
279 |
public void visit( XSContentTypeVisitor visitor ) {visitor.simpleType(this); } |
|
280 |
public void visit( XSVisitor visitor ) {visitor.simpleType(this); } |
|
281 |
public <T> T apply( XSSimpleTypeFunction<T> f ) {return f.restrictionSimpleType(this); } |
|
282 |
public <T> T apply( XSContentTypeFunction<T> f ) { return f.simpleType(this); } |
|
283 |
public <T> T apply( XSFunction<T> f ) { return f.simpleType(this); } |
|
284 |
public XSVariety getVariety() { return XSVariety.ATOMIC; } |
|
285 |
public XSSimpleType getPrimitiveType() {return this;} |
|
286 |
public boolean isPrimitive() {return true;} |
|
287 |
public XSListSimpleType getBaseListType() {return null;} |
|
288 |
public XSUnionSimpleType getBaseUnionType() {return null;} |
|
289 |
public XSFacet getFacet(String name) { return null; } |
|
290 |
public List<XSFacet> getFacets( String name ) { return Collections.EMPTY_LIST; } |
|
291 |
public XSFacet getDeclaredFacet(String name) { return null; } |
|
292 |
public List<XSFacet> getDeclaredFacets(String name) { return Collections.EMPTY_LIST; } |
|
293 |
||
294 |
public boolean isRestriction() { return true; } |
|
295 |
public boolean isList() { return false; } |
|
296 |
public boolean isUnion() { return false; } |
|
297 |
public boolean isFinal(XSVariety v) { return false; } |
|
298 |
public XSRestrictionSimpleType asRestriction() { return this; } |
|
299 |
public XSListSimpleType asList() { return null; } |
|
300 |
public XSUnionSimpleType asUnion() { return null; } |
|
301 |
public XSSimpleType getType() { return this; } // Ref.SimpleType implementation |
|
302 |
public XSSimpleType getRedefinedBy() { return null; } |
|
303 |
public int getRedefinedCount() { return 0; } |
|
304 |
||
305 |
public XSType[] listSubstitutables() { |
|
306 |
return Util.listSubstitutables(this); |
|
307 |
} |
|
308 |
} |
|
309 |
||
310 |
public XSComplexType getAnyType() { return anyType; } |
|
311 |
public final AnyType anyType = new AnyType(); |
|
312 |
private class AnyType extends DeclarationImpl implements XSComplexType, Ref.Type { |
|
313 |
AnyType() { |
|
314 |
super(null,null,null,null,"http://www.w3.org/2001/XMLSchema","anyType",false); |
|
315 |
} |
|
316 |
public SchemaImpl getOwnerSchema() { |
|
317 |
return createSchema("http://www.w3.org/2001/XMLSchema",null); |
|
318 |
} |
|
319 |
public boolean isAbstract() { return false; } |
|
320 |
public XSWildcard getAttributeWildcard() { return anyWildcard; } |
|
321 |
public XSAttributeUse getAttributeUse( String nsURI, String localName ) { return null; } |
|
322 |
public Iterator<XSAttributeUse> iterateAttributeUses() { return Iterators.empty(); } |
|
323 |
public XSAttributeUse getDeclaredAttributeUse( String nsURI, String localName ) { return null; } |
|
324 |
public Iterator<XSAttributeUse> iterateDeclaredAttributeUses() { return Iterators.empty(); } |
|
325 |
public Iterator<XSAttGroupDecl> iterateAttGroups() { return Iterators.empty(); } |
|
326 |
public Collection<XSAttributeUse> getAttributeUses() { return Collections.EMPTY_LIST; } |
|
327 |
public Collection<? extends XSAttributeUse> getDeclaredAttributeUses() { return Collections.EMPTY_LIST; } |
|
328 |
public Collection<? extends XSAttGroupDecl> getAttGroups() { return Collections.EMPTY_LIST; } |
|
329 |
public boolean isFinal( int i ) { return false; } |
|
330 |
public boolean isSubstitutionProhibited( int i ) { return false; } |
|
331 |
public boolean isMixed() { return true; } |
|
332 |
public XSContentType getContentType() { return contentType; } |
|
333 |
public XSContentType getExplicitContent() { return null; } |
|
334 |
public XSType getBaseType() { return this; } |
|
335 |
public XSSimpleType asSimpleType() { return null; } |
|
336 |
public XSComplexType asComplexType() { return this; } |
|
337 |
||
338 |
public boolean isDerivedFrom(XSType t) { |
|
339 |
return t==this; |
|
340 |
} |
|
341 |
||
342 |
public boolean isSimpleType() { return false; } |
|
343 |
public boolean isComplexType() { return true; } |
|
344 |
public XSContentType asEmpty() { return null; } |
|
345 |
public int getDerivationMethod() { return XSType.RESTRICTION; } |
|
346 |
||
347 |
public XSElementDecl getScope() { return null; } |
|
348 |
public void visit( XSVisitor visitor ) { visitor.complexType(this); } |
|
349 |
public <T> T apply( XSFunction<T> f ) { return f.complexType(this); } |
|
350 |
||
351 |
public XSType getType() { return this; } // Ref.Type implementation |
|
352 |
||
353 |
public XSComplexType getRedefinedBy() { return null; } |
|
354 |
public int getRedefinedCount() { return 0; } |
|
355 |
||
356 |
public XSType[] listSubstitutables() { |
|
357 |
return Util.listSubstitutables(this); |
|
358 |
} |
|
359 |
||
360 |
private final WildcardImpl anyWildcard = new WildcardImpl.Any(null,null,null,null,XSWildcard.SKIP); |
|
361 |
private final XSContentType contentType = new ParticleImpl( null, null, |
|
362 |
new ModelGroupImpl(null, null, null, null,XSModelGroup.SEQUENCE, new ParticleImpl[]{ |
|
363 |
new ParticleImpl( null, null, |
|
364 |
anyWildcard, null, |
|
365 |
XSParticle.UNBOUNDED, 0 ) |
|
366 |
}) |
|
367 |
,null,1,1); |
|
368 |
public List<XSComplexType> getSubtypes() { |
|
369 |
ArrayList subtypeList = new ArrayList(); |
|
370 |
Iterator<XSComplexType> cTypes = getRoot().iterateComplexTypes(); |
|
371 |
while (cTypes.hasNext()) { |
|
372 |
XSComplexType cType= cTypes.next(); |
|
373 |
XSType base = cType.getBaseType(); |
|
374 |
if ((base != null) && (base.equals(this))) { |
|
375 |
subtypeList.add(cType); |
|
376 |
} |
|
377 |
} |
|
378 |
return subtypeList; |
|
379 |
} |
|
380 |
||
381 |
public List<XSElementDecl> getElementDecls() { |
|
382 |
ArrayList declList = new ArrayList(); |
|
383 |
XSSchemaSet schemaSet = getRoot(); |
|
384 |
for (XSSchema sch : schemaSet.getSchemas()) { |
|
385 |
for (XSElementDecl decl : sch.getElementDecls().values()) { |
|
386 |
if (decl.getType().equals(this)) { |
|
387 |
declList.add(decl); |
|
388 |
} |
|
389 |
} |
|
390 |
} |
|
391 |
return declList; |
|
392 |
} |
|
393 |
} |
|
394 |
} |