author | joehw |
Mon, 13 Oct 2014 14:09:03 -0700 | |
changeset 27111 | 7a491d709b83 |
parent 25868 | 686eef1e7a79 |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
5 |
/* |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
7 |
* contributor license agreements. See the NOTICE file distributed with |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
8 |
* this work for additional information regarding copyright ownership. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
10 |
* (the "License"); you may not use this file except in compliance with |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
11 |
* the License. You may obtain a copy of the License at |
12005 | 12 |
* |
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
14 |
* |
|
15 |
* Unless required by applicable law or agreed to in writing, software |
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
18 |
* See the License for the specific language governing permissions and |
|
19 |
* limitations under the License. |
|
20 |
*/ |
|
21 |
||
22 |
package com.sun.org.apache.xerces.internal.impl.xs; |
|
23 |
||
24 |
import java.util.Collections; |
|
25 |
import java.util.Comparator; |
|
26 |
import java.util.Vector; |
|
27 |
||
28 |
import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; |
|
29 |
import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException; |
|
30 |
import com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo; |
|
31 |
import com.sun.org.apache.xerces.internal.impl.dv.ValidationContext; |
|
32 |
import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType; |
|
33 |
import com.sun.org.apache.xerces.internal.impl.xs.models.CMBuilder; |
|
34 |
import com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator; |
|
35 |
import com.sun.org.apache.xerces.internal.impl.xs.util.SimpleLocator; |
|
36 |
import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl; |
|
37 |
import com.sun.org.apache.xerces.internal.util.SymbolHash; |
|
38 |
import com.sun.org.apache.xerces.internal.xs.XSConstants; |
|
39 |
import com.sun.org.apache.xerces.internal.xs.XSObjectList; |
|
40 |
import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; |
|
41 |
||
42 |
/** |
|
43 |
* Constaints shared by traversers and validator |
|
44 |
* |
|
45 |
* @xerces.internal |
|
46 |
* |
|
47 |
* @author Sandy Gao, IBM |
|
48 |
* |
|
49 |
*/ |
|
50 |
public class XSConstraints { |
|
51 |
||
52 |
// IHR: Visited on 2006-11-17 |
|
53 |
// Added a boolean return value to particleValidRestriction (it was a void function) |
|
54 |
// to help the checkRecurseLax to know when expansion has happened and no order is required |
|
55 |
// (IHR@xbrl.org) (Ignacio@Hernandez-Ros.com) |
|
56 |
||
57 |
static final int OCCURRENCE_UNKNOWN = SchemaSymbols.OCCURRENCE_UNBOUNDED-1; |
|
58 |
static final XSSimpleType STRING_TYPE = (XSSimpleType)SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_STRING); |
|
59 |
||
60 |
private static XSParticleDecl fEmptyParticle = null; |
|
61 |
public static XSParticleDecl getEmptySequence() { |
|
62 |
if (fEmptyParticle == null) { |
|
63 |
XSModelGroupImpl group = new XSModelGroupImpl(); |
|
64 |
group.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE; |
|
65 |
group.fParticleCount = 0; |
|
66 |
group.fParticles = null; |
|
67 |
group.fAnnotations = XSObjectListImpl.EMPTY_LIST; |
|
68 |
XSParticleDecl particle = new XSParticleDecl(); |
|
69 |
particle.fType = XSParticleDecl.PARTICLE_MODELGROUP; |
|
70 |
particle.fValue = group; |
|
71 |
particle.fAnnotations = XSObjectListImpl.EMPTY_LIST; |
|
72 |
fEmptyParticle = particle; |
|
73 |
} |
|
74 |
return fEmptyParticle; |
|
75 |
} |
|
76 |
||
77 |
private static final Comparator ELEMENT_PARTICLE_COMPARATOR = new Comparator() { |
|
78 |
||
79 |
public int compare(Object o1, Object o2) { |
|
80 |
XSParticleDecl pDecl1 = (XSParticleDecl) o1; |
|
81 |
XSParticleDecl pDecl2 = (XSParticleDecl) o2; |
|
82 |
XSElementDecl decl1 = (XSElementDecl) pDecl1.fValue; |
|
83 |
XSElementDecl decl2 = (XSElementDecl) pDecl2.fValue; |
|
84 |
||
85 |
String namespace1 = decl1.getNamespace(); |
|
86 |
String namespace2 = decl2.getNamespace(); |
|
87 |
String name1 = decl1.getName(); |
|
88 |
String name2 = decl2.getName(); |
|
89 |
||
90 |
boolean sameNamespace = (namespace1 == namespace2); |
|
91 |
int namespaceComparison = 0; |
|
92 |
||
93 |
if (!sameNamespace) { |
|
94 |
if (namespace1 != null) { |
|
95 |
if (namespace2 != null){ |
|
96 |
namespaceComparison = namespace1.compareTo(namespace2); |
|
97 |
} |
|
98 |
else { |
|
99 |
namespaceComparison = 1; |
|
100 |
} |
|
101 |
} |
|
102 |
else { |
|
103 |
namespaceComparison = -1; |
|
104 |
} |
|
105 |
} |
|
106 |
//This assumes that the names are never null. |
|
107 |
return namespaceComparison != 0 ? namespaceComparison : name1.compareTo(name2); |
|
108 |
} |
|
109 |
}; |
|
110 |
||
111 |
/** |
|
112 |
* check whether derived is valid derived from base, given a subset |
|
113 |
* of {restriction, extension}.B |
|
114 |
*/ |
|
115 |
public static boolean checkTypeDerivationOk(XSTypeDefinition derived, XSTypeDefinition base, short block) { |
|
116 |
// if derived is anyType, then it's valid only if base is anyType too |
|
117 |
if (derived == SchemaGrammar.fAnyType) |
|
118 |
return derived == base; |
|
119 |
// if derived is anySimpleType, then it's valid only if the base |
|
120 |
// is ur-type |
|
121 |
if (derived == SchemaGrammar.fAnySimpleType) { |
|
122 |
return (base == SchemaGrammar.fAnyType || |
|
123 |
base == SchemaGrammar.fAnySimpleType); |
|
124 |
} |
|
125 |
||
126 |
// if derived is simple type |
|
127 |
if (derived.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { |
|
128 |
// if base is complex type |
|
129 |
if (base.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { |
|
130 |
// if base is anyType, change base to anySimpleType, |
|
131 |
// otherwise, not valid |
|
132 |
if (base == SchemaGrammar.fAnyType) |
|
133 |
base = SchemaGrammar.fAnySimpleType; |
|
134 |
else |
|
135 |
return false; |
|
136 |
} |
|
137 |
return checkSimpleDerivation((XSSimpleType)derived, |
|
138 |
(XSSimpleType)base, block); |
|
139 |
} |
|
140 |
else { |
|
141 |
return checkComplexDerivation((XSComplexTypeDecl)derived, base, block); |
|
142 |
} |
|
143 |
} |
|
144 |
||
145 |
/** |
|
146 |
* check whether simple type derived is valid derived from base, |
|
147 |
* given a subset of {restriction, extension}. |
|
148 |
*/ |
|
149 |
public static boolean checkSimpleDerivationOk(XSSimpleType derived, XSTypeDefinition base, short block) { |
|
150 |
// if derived is anySimpleType, then it's valid only if the base |
|
151 |
// is ur-type |
|
152 |
if (derived == SchemaGrammar.fAnySimpleType) { |
|
153 |
return (base == SchemaGrammar.fAnyType || |
|
154 |
base == SchemaGrammar.fAnySimpleType); |
|
155 |
} |
|
156 |
||
157 |
// if base is complex type |
|
158 |
if (base.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { |
|
159 |
// if base is anyType, change base to anySimpleType, |
|
160 |
// otherwise, not valid |
|
161 |
if (base == SchemaGrammar.fAnyType) |
|
162 |
base = SchemaGrammar.fAnySimpleType; |
|
163 |
else |
|
164 |
return false; |
|
165 |
} |
|
166 |
return checkSimpleDerivation((XSSimpleType)derived, |
|
167 |
(XSSimpleType)base, block); |
|
168 |
} |
|
169 |
||
170 |
/** |
|
171 |
* check whether complex type derived is valid derived from base, |
|
172 |
* given a subset of {restriction, extension}. |
|
173 |
*/ |
|
174 |
public static boolean checkComplexDerivationOk(XSComplexTypeDecl derived, XSTypeDefinition base, short block) { |
|
175 |
// if derived is anyType, then it's valid only if base is anyType too |
|
176 |
if (derived == SchemaGrammar.fAnyType) |
|
177 |
return derived == base; |
|
178 |
return checkComplexDerivation((XSComplexTypeDecl)derived, base, block); |
|
179 |
} |
|
180 |
||
181 |
/** |
|
182 |
* Note: this will be a private method, and it assumes that derived is not |
|
183 |
* anySimpleType, and base is not anyType. Another method will be |
|
184 |
* introduced for public use, which will call this method. |
|
185 |
*/ |
|
186 |
private static boolean checkSimpleDerivation(XSSimpleType derived, XSSimpleType base, short block) { |
|
187 |
// 1 They are the same type definition. |
|
188 |
if (derived == base) |
|
189 |
return true; |
|
190 |
||
191 |
// 2 All of the following must be true: |
|
192 |
// 2.1 restriction is not in the subset, or in the {final} of its own {base type definition}; |
|
193 |
if ((block & XSConstants.DERIVATION_RESTRICTION) != 0 || |
|
194 |
(derived.getBaseType().getFinal() & XSConstants.DERIVATION_RESTRICTION) != 0) { |
|
195 |
return false; |
|
196 |
} |
|
197 |
||
198 |
// 2.2 One of the following must be true: |
|
199 |
// 2.2.1 D's base type definition is B. |
|
200 |
XSSimpleType directBase = (XSSimpleType)derived.getBaseType(); |
|
201 |
if (directBase == base) |
|
202 |
return true; |
|
203 |
||
204 |
// 2.2.2 D's base type definition is not the simple ur-type definition and is validly derived from B given the subset, as defined by this constraint. |
|
205 |
if (directBase != SchemaGrammar.fAnySimpleType && |
|
206 |
checkSimpleDerivation(directBase, base, block)) { |
|
207 |
return true; |
|
208 |
} |
|
209 |
||
210 |
// 2.2.3 D's {variety} is list or union and B is the simple ur-type definition. |
|
211 |
if ((derived.getVariety() == XSSimpleType.VARIETY_LIST || |
|
212 |
derived.getVariety() == XSSimpleType.VARIETY_UNION) && |
|
213 |
base == SchemaGrammar.fAnySimpleType) { |
|
214 |
return true; |
|
215 |
} |
|
216 |
||
217 |
// 2.2.4 B's {variety} is union and D is validly derived from a type definition in B's {member type definitions} given the subset, as defined by this constraint. |
|
218 |
if (base.getVariety() == XSSimpleType.VARIETY_UNION) { |
|
219 |
XSObjectList subUnionMemberDV = base.getMemberTypes(); |
|
220 |
int subUnionSize = subUnionMemberDV.getLength(); |
|
221 |
for (int i=0; i<subUnionSize; i++) { |
|
222 |
base = (XSSimpleType)subUnionMemberDV.item(i); |
|
223 |
if (checkSimpleDerivation(derived, base, block)) |
|
224 |
return true; |
|
225 |
} |
|
226 |
} |
|
227 |
||
228 |
return false; |
|
229 |
} |
|
230 |
||
231 |
/** |
|
232 |
* Note: this will be a private method, and it assumes that derived is not |
|
233 |
* anyType. Another method will be introduced for public use, |
|
234 |
* which will call this method. |
|
235 |
*/ |
|
236 |
private static boolean checkComplexDerivation(XSComplexTypeDecl derived, XSTypeDefinition base, short block) { |
|
237 |
// 2.1 B and D must be the same type definition. |
|
238 |
if (derived == base) |
|
239 |
return true; |
|
240 |
||
241 |
// 1 If B and D are not the same type definition, then the {derivation method} of D must not be in the subset. |
|
242 |
if ((derived.fDerivedBy & block) != 0) |
|
243 |
return false; |
|
244 |
||
245 |
// 2 One of the following must be true: |
|
246 |
XSTypeDefinition directBase = derived.fBaseType; |
|
247 |
// 2.2 B must be D's {base type definition}. |
|
248 |
if (directBase == base) |
|
249 |
return true; |
|
250 |
||
251 |
// 2.3 All of the following must be true: |
|
252 |
// 2.3.1 D's {base type definition} must not be the ur-type definition. |
|
253 |
if (directBase == SchemaGrammar.fAnyType || |
|
254 |
directBase == SchemaGrammar.fAnySimpleType) { |
|
255 |
return false; |
|
256 |
} |
|
257 |
||
258 |
// 2.3.2 The appropriate case among the following must be true: |
|
259 |
// 2.3.2.1 If D's {base type definition} is complex, then it must be validly derived from B given the subset as defined by this constraint. |
|
260 |
if (directBase.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) |
|
261 |
return checkComplexDerivation((XSComplexTypeDecl)directBase, base, block); |
|
262 |
||
263 |
// 2.3.2.2 If D's {base type definition} is simple, then it must be validly derived from B given the subset as defined in Type Derivation OK (Simple) (3.14.6). |
|
264 |
if (directBase.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { |
|
265 |
// if base is complex type |
|
266 |
if (base.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { |
|
267 |
// if base is anyType, change base to anySimpleType, |
|
268 |
// otherwise, not valid |
|
269 |
if (base == SchemaGrammar.fAnyType) |
|
270 |
base = SchemaGrammar.fAnySimpleType; |
|
271 |
else |
|
272 |
return false; |
|
273 |
} |
|
274 |
return checkSimpleDerivation((XSSimpleType)directBase, |
|
275 |
(XSSimpleType)base, block); |
|
276 |
} |
|
277 |
||
278 |
return false; |
|
279 |
} |
|
280 |
||
281 |
/** |
|
282 |
* check whether a value is a valid default for some type |
|
283 |
* returns the compiled form of the value |
|
284 |
* The parameter value could be either a String or a ValidatedInfo object |
|
285 |
*/ |
|
286 |
public static Object ElementDefaultValidImmediate(XSTypeDefinition type, String value, ValidationContext context, ValidatedInfo vinfo) { |
|
287 |
||
288 |
XSSimpleType dv = null; |
|
289 |
||
290 |
// e-props-correct |
|
291 |
// For a string to be a valid default with respect to a type definition the appropriate case among the following must be true: |
|
292 |
// 1 If the type definition is a simple type definition, then the string must be valid with respect to that definition as defined by String Valid (3.14.4). |
|
293 |
if (type.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { |
|
294 |
dv = (XSSimpleType)type; |
|
295 |
} |
|
296 |
||
297 |
// 2 If the type definition is a complex type definition, then all of the following must be true: |
|
298 |
else { |
|
299 |
// 2.1 its {content type} must be a simple type definition or mixed. |
|
300 |
XSComplexTypeDecl ctype = (XSComplexTypeDecl)type; |
|
301 |
// 2.2 The appropriate case among the following must be true: |
|
302 |
// 2.2.1 If the {content type} is a simple type definition, then the string must be valid with respect to that simple type definition as defined by String Valid (3.14.4). |
|
303 |
if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_SIMPLE) { |
|
304 |
dv = ctype.fXSSimpleType; |
|
305 |
} |
|
306 |
// 2.2.2 If the {content type} is mixed, then the {content type}'s particle must be emptiable as defined by Particle Emptiable (3.9.6). |
|
307 |
else if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_MIXED) { |
|
308 |
if (!((XSParticleDecl)ctype.getParticle()).emptiable()) |
|
309 |
return null; |
|
310 |
} |
|
311 |
else { |
|
312 |
return null; |
|
313 |
} |
|
314 |
} |
|
315 |
||
316 |
// get the simple type declaration, and validate |
|
317 |
Object actualValue = null; |
|
318 |
if (dv == null) { |
|
319 |
// complex type with mixed. to make sure that we store correct |
|
320 |
// information in vinfo and return the correct value, we use |
|
321 |
// "string" type for validation |
|
322 |
dv = STRING_TYPE; |
|
323 |
} |
|
324 |
try { |
|
325 |
// validate the original lexical rep, and set the actual value |
|
326 |
actualValue = dv.validate(value, context, vinfo); |
|
327 |
// validate the canonical lexical rep |
|
328 |
if (vinfo != null) |
|
329 |
actualValue = dv.validate(vinfo.stringValue(), context, vinfo); |
|
330 |
} catch (InvalidDatatypeValueException ide) { |
|
331 |
return null; |
|
332 |
} |
|
333 |
||
334 |
return actualValue; |
|
335 |
} |
|
336 |
||
337 |
static void reportSchemaError(XMLErrorReporter errorReporter, |
|
338 |
SimpleLocator loc, |
|
339 |
String key, Object[] args) { |
|
340 |
if (loc != null) { |
|
341 |
errorReporter.reportError(loc, XSMessageFormatter.SCHEMA_DOMAIN, |
|
342 |
key, args, XMLErrorReporter.SEVERITY_ERROR); |
|
343 |
} |
|
344 |
else { |
|
345 |
errorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, |
|
346 |
key, args, XMLErrorReporter.SEVERITY_ERROR); |
|
347 |
} |
|
348 |
} |
|
349 |
||
350 |
/** |
|
351 |
* used to check the 3 constraints against each complex type |
|
352 |
* (should be each model group): |
|
353 |
* Unique Particle Attribution, Particle Derivation (Restriction), |
|
354 |
* Element Declrations Consistent. |
|
355 |
*/ |
|
356 |
public static void fullSchemaChecking(XSGrammarBucket grammarBucket, |
|
357 |
SubstitutionGroupHandler SGHandler, |
|
358 |
CMBuilder cmBuilder, |
|
359 |
XMLErrorReporter errorReporter) { |
|
360 |
// get all grammars, and put all substitution group information |
|
361 |
// in the substitution group handler |
|
362 |
SchemaGrammar[] grammars = grammarBucket.getGrammars(); |
|
363 |
for (int i = grammars.length-1; i >= 0; i--) { |
|
364 |
SGHandler.addSubstitutionGroup(grammars[i].getSubstitutionGroups()); |
|
365 |
} |
|
366 |
||
367 |
XSParticleDecl fakeDerived = new XSParticleDecl(); |
|
368 |
XSParticleDecl fakeBase = new XSParticleDecl(); |
|
369 |
fakeDerived.fType = XSParticleDecl.PARTICLE_MODELGROUP; |
|
370 |
fakeBase.fType = XSParticleDecl.PARTICLE_MODELGROUP; |
|
371 |
// before worrying about complexTypes, let's get |
|
372 |
// groups redefined by restriction out of the way. |
|
373 |
for (int g = grammars.length-1; g >= 0; g--) { |
|
374 |
XSGroupDecl [] redefinedGroups = grammars[g].getRedefinedGroupDecls(); |
|
375 |
SimpleLocator [] rgLocators = grammars[g].getRGLocators(); |
|
376 |
for(int i=0; i<redefinedGroups.length; ) { |
|
377 |
XSGroupDecl derivedGrp = redefinedGroups[i++]; |
|
378 |
XSModelGroupImpl derivedMG = derivedGrp.fModelGroup; |
|
379 |
XSGroupDecl baseGrp = redefinedGroups[i++]; |
|
380 |
XSModelGroupImpl baseMG = baseGrp.fModelGroup; |
|
381 |
fakeDerived.fValue = derivedMG; |
|
382 |
fakeBase.fValue = baseMG; |
|
383 |
if(baseMG == null) { |
|
384 |
if(derivedMG != null) { // can't be a restriction! |
|
385 |
reportSchemaError(errorReporter, rgLocators[i/2-1], |
|
386 |
"src-redefine.6.2.2", |
|
387 |
new Object[]{derivedGrp.fName, "rcase-Recurse.2"}); |
|
388 |
} |
|
389 |
} else if (derivedMG == null) { |
|
390 |
if (!fakeBase.emptiable()) { |
|
391 |
reportSchemaError(errorReporter, rgLocators[i/2-1], |
|
392 |
"src-redefine.6.2.2", |
|
393 |
new Object[]{derivedGrp.fName, "rcase-Recurse.2"}); |
|
394 |
} |
|
395 |
} else { |
|
396 |
try { |
|
397 |
particleValidRestriction(fakeDerived, SGHandler, fakeBase, SGHandler); |
|
398 |
} catch (XMLSchemaException e) { |
|
399 |
String key = e.getKey(); |
|
400 |
reportSchemaError(errorReporter, rgLocators[i/2-1], |
|
401 |
key, |
|
402 |
e.getArgs()); |
|
403 |
reportSchemaError(errorReporter, rgLocators[i/2-1], |
|
404 |
"src-redefine.6.2.2", |
|
405 |
new Object[]{derivedGrp.fName, key}); |
|
406 |
} |
|
407 |
} |
|
408 |
} |
|
409 |
} |
|
410 |
||
411 |
// for each complex type, check the 3 constraints. |
|
412 |
// types need to be checked |
|
413 |
XSComplexTypeDecl[] types; |
|
414 |
SimpleLocator [] ctLocators; |
|
415 |
// to hold the errors |
|
416 |
// REVISIT: do we want to report all errors? or just one? |
|
417 |
//XMLSchemaError1D errors = new XMLSchemaError1D(); |
|
418 |
// whether need to check this type again; |
|
419 |
// whether only do UPA checking |
|
420 |
boolean further, fullChecked; |
|
421 |
// if do all checkings, how many need to be checked again. |
|
422 |
int keepType; |
|
423 |
// i: grammar; j: type; k: error |
|
424 |
// for all grammars |
|
425 |
SymbolHash elemTable = new SymbolHash(); |
|
426 |
for (int i = grammars.length-1, j; i >= 0; i--) { |
|
427 |
// get whether to skip EDC, and types need to be checked |
|
428 |
keepType = 0; |
|
429 |
fullChecked = grammars[i].fFullChecked; |
|
430 |
types = grammars[i].getUncheckedComplexTypeDecls(); |
|
431 |
ctLocators = grammars[i].getUncheckedCTLocators(); |
|
432 |
// for each type |
|
433 |
for (j = 0; j < types.length; j++) { |
|
434 |
// if we've already full-checked this grammar, then |
|
435 |
// skip the EDC constraint |
|
436 |
if (!fullChecked) { |
|
437 |
// 1. Element Decl Consistent |
|
438 |
if (types[j].fParticle!=null) { |
|
439 |
elemTable.clear(); |
|
440 |
try { |
|
441 |
checkElementDeclsConsistent(types[j], types[j].fParticle, |
|
442 |
elemTable, SGHandler); |
|
443 |
} |
|
444 |
catch (XMLSchemaException e) { |
|
445 |
reportSchemaError(errorReporter, ctLocators[j], |
|
446 |
e.getKey(), |
|
447 |
e.getArgs()); |
|
448 |
} |
|
449 |
} |
|
450 |
} |
|
451 |
||
452 |
// 2. Particle Derivation |
|
453 |
||
454 |
if (types[j].fBaseType != null && |
|
455 |
types[j].fBaseType != SchemaGrammar.fAnyType && |
|
456 |
types[j].fDerivedBy == XSConstants.DERIVATION_RESTRICTION && |
|
457 |
(types[j].fBaseType instanceof XSComplexTypeDecl)) { |
|
458 |
||
459 |
XSParticleDecl derivedParticle=types[j].fParticle; |
|
460 |
XSParticleDecl baseParticle= |
|
461 |
((XSComplexTypeDecl)(types[j].fBaseType)).fParticle; |
|
462 |
if (derivedParticle==null) { |
|
463 |
if (baseParticle!=null && !baseParticle.emptiable()) { |
|
464 |
reportSchemaError(errorReporter,ctLocators[j], |
|
465 |
"derivation-ok-restriction.5.3.2", |
|
466 |
new Object[]{types[j].fName, types[j].fBaseType.getName()}); |
|
467 |
} |
|
468 |
} |
|
469 |
else if (baseParticle!=null) { |
|
470 |
try { |
|
471 |
particleValidRestriction(types[j].fParticle, |
|
472 |
SGHandler, |
|
473 |
((XSComplexTypeDecl)(types[j].fBaseType)).fParticle, |
|
474 |
SGHandler); |
|
475 |
} catch (XMLSchemaException e) { |
|
476 |
reportSchemaError(errorReporter, ctLocators[j], |
|
477 |
e.getKey(), |
|
478 |
e.getArgs()); |
|
479 |
reportSchemaError(errorReporter, ctLocators[j], |
|
480 |
"derivation-ok-restriction.5.4.2", |
|
481 |
new Object[]{types[j].fName}); |
|
482 |
} |
|
483 |
} |
|
484 |
else { |
|
485 |
reportSchemaError(errorReporter, ctLocators[j], |
|
486 |
"derivation-ok-restriction.5.4.2", |
|
487 |
new Object[]{types[j].fName}); |
|
488 |
} |
|
489 |
} |
|
490 |
// 3. UPA |
|
491 |
// get the content model and check UPA |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
25868
diff
changeset
|
492 |
XSCMValidator cm = types[j].getContentModel(cmBuilder, true); |
12005 | 493 |
further = false; |
494 |
if (cm != null) { |
|
495 |
try { |
|
496 |
further = cm.checkUniqueParticleAttribution(SGHandler); |
|
497 |
} catch (XMLSchemaException e) { |
|
498 |
reportSchemaError(errorReporter, ctLocators[j], |
|
499 |
e.getKey(), |
|
500 |
e.getArgs()); |
|
501 |
} |
|
502 |
} |
|
503 |
// now report all errors |
|
504 |
// REVISIT: do we want to report all errors? or just one? |
|
505 |
/*for (k = errors.getErrorCodeNum()-1; k >= 0; k--) { |
|
506 |
reportSchemaError(errorReporter, ctLocators[j], |
|
507 |
errors.getErrorCode(k), |
|
508 |
errors.getArgs(k)); |
|
509 |
}*/ |
|
510 |
||
511 |
// if we are doing all checkings, and this one needs further |
|
512 |
// checking, store it in the type array. |
|
513 |
if (!fullChecked && further) |
|
514 |
types[keepType++] = types[j]; |
|
515 |
||
516 |
// clear errors for the next type. |
|
517 |
// REVISIT: do we want to report all errors? or just one? |
|
518 |
//errors.clear(); |
|
519 |
} |
|
520 |
// we've done with the types in this grammar. if we are checking |
|
521 |
// all constraints, need to trim type array to a proper size: |
|
522 |
// only contain those need further checking. |
|
523 |
// and mark this grammar that it only needs UPA checking. |
|
524 |
if (!fullChecked) { |
|
525 |
grammars[i].setUncheckedTypeNum(keepType); |
|
526 |
grammars[i].fFullChecked = true; |
|
527 |
} |
|
528 |
} |
|
529 |
} |
|
530 |
||
531 |
/* |
|
532 |
Check that a given particle is a valid restriction of a base particle. |
|
533 |
*/ |
|
534 |
||
535 |
public static void checkElementDeclsConsistent(XSComplexTypeDecl type, |
|
536 |
XSParticleDecl particle, |
|
537 |
SymbolHash elemDeclHash, |
|
538 |
SubstitutionGroupHandler sgHandler) |
|
539 |
throws XMLSchemaException { |
|
540 |
||
541 |
// check for elements in the tree with the same name and namespace |
|
542 |
||
543 |
int pType = particle.fType; |
|
544 |
||
545 |
if (pType == XSParticleDecl.PARTICLE_WILDCARD) |
|
546 |
return; |
|
547 |
||
548 |
if (pType == XSParticleDecl.PARTICLE_ELEMENT) { |
|
549 |
XSElementDecl elem = (XSElementDecl)(particle.fValue); |
|
550 |
findElemInTable(type, elem, elemDeclHash); |
|
551 |
||
552 |
if (elem.fScope == XSConstants.SCOPE_GLOBAL) { |
|
553 |
// Check for subsitution groups. |
|
554 |
XSElementDecl[] subGroup = sgHandler.getSubstitutionGroup(elem); |
|
555 |
for (int i = 0; i < subGroup.length; i++) { |
|
556 |
findElemInTable(type, subGroup[i], elemDeclHash); |
|
557 |
} |
|
558 |
} |
|
559 |
return; |
|
560 |
} |
|
561 |
||
562 |
XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue; |
|
563 |
for (int i = 0; i < group.fParticleCount; i++) |
|
564 |
checkElementDeclsConsistent(type, group.fParticles[i], elemDeclHash, sgHandler); |
|
565 |
} |
|
566 |
||
567 |
public static void findElemInTable(XSComplexTypeDecl type, XSElementDecl elem, |
|
568 |
SymbolHash elemDeclHash) |
|
569 |
throws XMLSchemaException { |
|
570 |
||
571 |
// How can we avoid this concat? LM. |
|
572 |
String name = elem.fName + "," + elem.fTargetNamespace; |
|
573 |
||
574 |
XSElementDecl existingElem = null; |
|
575 |
if ((existingElem = (XSElementDecl)(elemDeclHash.get(name))) == null) { |
|
576 |
// just add it in |
|
577 |
elemDeclHash.put(name, elem); |
|
578 |
} |
|
579 |
else { |
|
580 |
// If this is the same check element, we're O.K. |
|
581 |
if (elem == existingElem) |
|
582 |
return; |
|
583 |
||
584 |
if (elem.fType != existingElem.fType) { |
|
585 |
// Types are not the same |
|
586 |
throw new XMLSchemaException("cos-element-consistent", |
|
587 |
new Object[] {type.fName, elem.fName}); |
|
588 |
||
589 |
} |
|
590 |
} |
|
591 |
} |
|
592 |
||
593 |
// Check that a given particle is a valid restriction of a base particle. |
|
594 |
// |
|
595 |
// IHR: 2006/11/17 |
|
596 |
// Returns a boolean indicating if there has been expansion of substitution group |
|
597 |
// in the bParticle. |
|
598 |
// With this information the checkRecurseLax function knows when is |
|
599 |
// to keep the order and when to ignore it. |
|
600 |
private static boolean particleValidRestriction(XSParticleDecl dParticle, |
|
601 |
SubstitutionGroupHandler dSGHandler, |
|
602 |
XSParticleDecl bParticle, |
|
603 |
SubstitutionGroupHandler bSGHandler) |
|
604 |
throws XMLSchemaException { |
|
605 |
return particleValidRestriction(dParticle, dSGHandler, bParticle, bSGHandler, true); |
|
606 |
} |
|
607 |
||
608 |
private static boolean particleValidRestriction(XSParticleDecl dParticle, |
|
609 |
SubstitutionGroupHandler dSGHandler, |
|
610 |
XSParticleDecl bParticle, |
|
611 |
SubstitutionGroupHandler bSGHandler, |
|
612 |
boolean checkWCOccurrence) |
|
613 |
throws XMLSchemaException { |
|
614 |
||
615 |
Vector dChildren = null; |
|
616 |
Vector bChildren = null; |
|
617 |
int dMinEffectiveTotalRange=OCCURRENCE_UNKNOWN; |
|
618 |
int dMaxEffectiveTotalRange=OCCURRENCE_UNKNOWN; |
|
619 |
||
620 |
// By default there has been no expansion |
|
621 |
boolean bExpansionHappened = false; |
|
622 |
||
623 |
// Check for empty particles. If either base or derived particle is empty, |
|
624 |
// (and the other isn't) it's an error. |
|
625 |
if (dParticle.isEmpty() && !bParticle.emptiable()) { |
|
626 |
throw new XMLSchemaException("cos-particle-restrict.a", null); |
|
627 |
} |
|
628 |
else if (!dParticle.isEmpty() && bParticle.isEmpty()) { |
|
629 |
throw new XMLSchemaException("cos-particle-restrict.b", null); |
|
630 |
} |
|
631 |
||
632 |
// |
|
633 |
// Do setup prior to invoking the Particle (Restriction) cases. |
|
634 |
// This involves: |
|
635 |
// - removing pointless occurrences for groups, and retrieving a vector of |
|
636 |
// non-pointless children |
|
637 |
// - turning top-level elements with substitution groups into CHOICE groups. |
|
638 |
// |
|
639 |
||
640 |
short dType = dParticle.fType; |
|
641 |
// |
|
642 |
// Handle pointless groups for the derived particle |
|
643 |
// |
|
644 |
if (dType == XSParticleDecl.PARTICLE_MODELGROUP) { |
|
645 |
dType = ((XSModelGroupImpl)dParticle.fValue).fCompositor; |
|
646 |
||
647 |
// Find a group, starting with this particle, with more than 1 child. There |
|
648 |
// may be none, and the particle of interest trivially becomes an element or |
|
649 |
// wildcard. |
|
650 |
XSParticleDecl dtmp = getNonUnaryGroup(dParticle); |
|
651 |
if (dtmp != dParticle) { |
|
652 |
// Particle has been replaced. Retrieve new type info. |
|
653 |
dParticle = dtmp; |
|
654 |
dType = dParticle.fType; |
|
655 |
if (dType == XSParticleDecl.PARTICLE_MODELGROUP) |
|
656 |
dType = ((XSModelGroupImpl)dParticle.fValue).fCompositor; |
|
657 |
} |
|
658 |
||
659 |
// Fill in a vector with the children of the particle, removing any |
|
660 |
// pointless model groups in the process. |
|
661 |
dChildren = removePointlessChildren(dParticle); |
|
662 |
} |
|
663 |
||
664 |
int dMinOccurs = dParticle.fMinOccurs; |
|
665 |
int dMaxOccurs = dParticle.fMaxOccurs; |
|
666 |
||
667 |
// |
|
668 |
// For elements which are the heads of substitution groups, treat as CHOICE |
|
669 |
// |
|
670 |
if (dSGHandler != null && dType == XSParticleDecl.PARTICLE_ELEMENT) { |
|
671 |
XSElementDecl dElement = (XSElementDecl)dParticle.fValue; |
|
672 |
||
673 |
if (dElement.fScope == XSConstants.SCOPE_GLOBAL) { |
|
674 |
// Check for subsitution groups. Treat any element that has a |
|
675 |
// subsitution group as a choice. Fill in the children vector with the |
|
676 |
// members of the substitution group |
|
677 |
XSElementDecl[] subGroup = dSGHandler.getSubstitutionGroup(dElement); |
|
678 |
if (subGroup.length >0 ) { |
|
679 |
// Now, set the type to be CHOICE. The "group" will have the same |
|
680 |
// occurrence information as the original particle. |
|
681 |
dType = XSModelGroupImpl.MODELGROUP_CHOICE; |
|
682 |
dMinEffectiveTotalRange = dMinOccurs; |
|
683 |
dMaxEffectiveTotalRange = dMaxOccurs; |
|
684 |
||
685 |
// Fill in the vector of children |
|
686 |
dChildren = new Vector(subGroup.length+1); |
|
687 |
for (int i = 0; i < subGroup.length; i++) { |
|
688 |
addElementToParticleVector(dChildren, subGroup[i]); |
|
689 |
} |
|
690 |
addElementToParticleVector(dChildren, dElement); |
|
691 |
Collections.sort(dChildren, ELEMENT_PARTICLE_COMPARATOR); |
|
692 |
||
693 |
// Set the handler to null, to indicate that we've finished handling |
|
694 |
// substitution groups for this particle. |
|
695 |
dSGHandler = null; |
|
696 |
} |
|
697 |
} |
|
698 |
} |
|
699 |
||
700 |
short bType = bParticle.fType; |
|
701 |
// |
|
702 |
// Handle pointless groups for the base particle |
|
703 |
// |
|
704 |
if (bType == XSParticleDecl.PARTICLE_MODELGROUP) { |
|
705 |
bType = ((XSModelGroupImpl)bParticle.fValue).fCompositor; |
|
706 |
||
707 |
// Find a group, starting with this particle, with more than 1 child. There |
|
708 |
// may be none, and the particle of interest trivially becomes an element or |
|
709 |
// wildcard. |
|
710 |
XSParticleDecl btmp = getNonUnaryGroup(bParticle); |
|
711 |
if (btmp != bParticle) { |
|
712 |
// Particle has been replaced. Retrieve new type info. |
|
713 |
bParticle = btmp; |
|
714 |
bType = bParticle.fType; |
|
715 |
if (bType == XSParticleDecl.PARTICLE_MODELGROUP) |
|
716 |
bType = ((XSModelGroupImpl)bParticle.fValue).fCompositor; |
|
717 |
} |
|
718 |
||
719 |
// Fill in a vector with the children of the particle, removing any |
|
720 |
// pointless model groups in the process. |
|
721 |
bChildren = removePointlessChildren(bParticle); |
|
722 |
} |
|
723 |
||
724 |
int bMinOccurs = bParticle.fMinOccurs; |
|
725 |
int bMaxOccurs = bParticle.fMaxOccurs; |
|
726 |
||
727 |
if (bSGHandler != null && bType == XSParticleDecl.PARTICLE_ELEMENT) { |
|
728 |
XSElementDecl bElement = (XSElementDecl)bParticle.fValue; |
|
729 |
||
730 |
if (bElement.fScope == XSConstants.SCOPE_GLOBAL) { |
|
731 |
// Check for subsitution groups. Treat any element that has a |
|
732 |
// subsitution group as a choice. Fill in the children vector with the |
|
733 |
// members of the substitution group |
|
734 |
XSElementDecl[] bsubGroup = bSGHandler.getSubstitutionGroup(bElement); |
|
735 |
if (bsubGroup.length >0 ) { |
|
736 |
// Now, set the type to be CHOICE |
|
737 |
bType = XSModelGroupImpl.MODELGROUP_CHOICE; |
|
738 |
||
739 |
bChildren = new Vector(bsubGroup.length+1); |
|
740 |
for (int i = 0; i < bsubGroup.length; i++) { |
|
741 |
addElementToParticleVector(bChildren, bsubGroup[i]); |
|
742 |
} |
|
743 |
addElementToParticleVector(bChildren, bElement); |
|
744 |
Collections.sort(bChildren, ELEMENT_PARTICLE_COMPARATOR); |
|
745 |
// Set the handler to null, to indicate that we've finished handling |
|
746 |
// substitution groups for this particle. |
|
747 |
bSGHandler = null; |
|
748 |
||
749 |
// if we are here expansion of bParticle happened |
|
750 |
bExpansionHappened = true; |
|
751 |
} |
|
752 |
} |
|
753 |
} |
|
754 |
||
755 |
// |
|
756 |
// O.K. - Figure out which particle derivation rule applies and call it |
|
757 |
// |
|
758 |
switch (dType) { |
|
759 |
case XSParticleDecl.PARTICLE_ELEMENT: |
|
760 |
{ |
|
761 |
switch (bType) { |
|
762 |
||
763 |
// Elt:Elt NameAndTypeOK |
|
764 |
case XSParticleDecl.PARTICLE_ELEMENT: |
|
765 |
{ |
|
766 |
checkNameAndTypeOK((XSElementDecl)dParticle.fValue,dMinOccurs,dMaxOccurs, |
|
767 |
(XSElementDecl)bParticle.fValue,bMinOccurs,bMaxOccurs); |
|
768 |
return bExpansionHappened; |
|
769 |
} |
|
770 |
||
771 |
// Elt:Any NSCompat |
|
772 |
case XSParticleDecl.PARTICLE_WILDCARD: |
|
773 |
{ |
|
774 |
checkNSCompat((XSElementDecl)dParticle.fValue,dMinOccurs,dMaxOccurs, |
|
775 |
(XSWildcardDecl)bParticle.fValue,bMinOccurs,bMaxOccurs, |
|
776 |
checkWCOccurrence); |
|
777 |
return bExpansionHappened; |
|
778 |
} |
|
779 |
||
780 |
// Elt:All RecurseAsIfGroup |
|
781 |
case XSModelGroupImpl.MODELGROUP_CHOICE: |
|
782 |
{ |
|
783 |
// Treat the element as if it were in a group of the same type |
|
784 |
// as the base Particle |
|
785 |
dChildren = new Vector(); |
|
786 |
dChildren.addElement(dParticle); |
|
787 |
||
788 |
checkRecurseLax(dChildren, 1, 1, dSGHandler, |
|
789 |
bChildren, bMinOccurs, bMaxOccurs, bSGHandler); |
|
790 |
return bExpansionHappened; |
|
791 |
} |
|
792 |
case XSModelGroupImpl.MODELGROUP_SEQUENCE: |
|
793 |
case XSModelGroupImpl.MODELGROUP_ALL: |
|
794 |
{ |
|
795 |
// Treat the element as if it were in a group of the same type |
|
796 |
// as the base Particle |
|
797 |
dChildren = new Vector(); |
|
798 |
dChildren.addElement(dParticle); |
|
799 |
||
800 |
checkRecurse(dChildren, 1, 1, dSGHandler, |
|
801 |
bChildren, bMinOccurs, bMaxOccurs, bSGHandler); |
|
802 |
return bExpansionHappened; |
|
803 |
} |
|
804 |
||
805 |
default: |
|
806 |
{ |
|
807 |
throw new XMLSchemaException("Internal-Error", |
|
808 |
new Object[]{"in particleValidRestriction"}); |
|
809 |
} |
|
810 |
} |
|
811 |
} |
|
812 |
||
813 |
case XSParticleDecl.PARTICLE_WILDCARD: |
|
814 |
{ |
|
815 |
switch (bType) { |
|
816 |
||
817 |
// Any:Any NSSubset |
|
818 |
case XSParticleDecl.PARTICLE_WILDCARD: |
|
819 |
{ |
|
820 |
checkNSSubset((XSWildcardDecl)dParticle.fValue, dMinOccurs, dMaxOccurs, |
|
821 |
(XSWildcardDecl)bParticle.fValue, bMinOccurs, bMaxOccurs); |
|
822 |
return bExpansionHappened; |
|
823 |
} |
|
824 |
||
825 |
case XSModelGroupImpl.MODELGROUP_CHOICE: |
|
826 |
case XSModelGroupImpl.MODELGROUP_SEQUENCE: |
|
827 |
case XSModelGroupImpl.MODELGROUP_ALL: |
|
828 |
case XSParticleDecl.PARTICLE_ELEMENT: |
|
829 |
{ |
|
830 |
throw new XMLSchemaException("cos-particle-restrict.2", |
|
831 |
new Object[]{"any:choice,sequence,all,elt"}); |
|
832 |
} |
|
833 |
||
834 |
default: |
|
835 |
{ |
|
836 |
throw new XMLSchemaException("Internal-Error", |
|
837 |
new Object[]{"in particleValidRestriction"}); |
|
838 |
} |
|
839 |
} |
|
840 |
} |
|
841 |
||
842 |
case XSModelGroupImpl.MODELGROUP_ALL: |
|
843 |
{ |
|
844 |
switch (bType) { |
|
845 |
||
846 |
// All:Any NSRecurseCheckCardinality |
|
847 |
case XSParticleDecl.PARTICLE_WILDCARD: |
|
848 |
{ |
|
849 |
if (dMinEffectiveTotalRange == OCCURRENCE_UNKNOWN) |
|
850 |
dMinEffectiveTotalRange = dParticle.minEffectiveTotalRange(); |
|
851 |
if (dMaxEffectiveTotalRange == OCCURRENCE_UNKNOWN) |
|
852 |
dMaxEffectiveTotalRange = dParticle.maxEffectiveTotalRange(); |
|
853 |
||
854 |
checkNSRecurseCheckCardinality(dChildren, dMinEffectiveTotalRange, |
|
855 |
dMaxEffectiveTotalRange, |
|
856 |
dSGHandler, |
|
857 |
bParticle,bMinOccurs,bMaxOccurs, |
|
858 |
checkWCOccurrence); |
|
859 |
||
860 |
return bExpansionHappened; |
|
861 |
} |
|
862 |
||
863 |
case XSModelGroupImpl.MODELGROUP_ALL: |
|
864 |
{ |
|
865 |
checkRecurse(dChildren, dMinOccurs, dMaxOccurs, dSGHandler, |
|
866 |
bChildren, bMinOccurs, bMaxOccurs, bSGHandler); |
|
867 |
return bExpansionHappened; |
|
868 |
} |
|
869 |
||
870 |
case XSModelGroupImpl.MODELGROUP_CHOICE: |
|
871 |
case XSModelGroupImpl.MODELGROUP_SEQUENCE: |
|
872 |
case XSParticleDecl.PARTICLE_ELEMENT: |
|
873 |
{ |
|
874 |
throw new XMLSchemaException("cos-particle-restrict.2", |
|
875 |
new Object[]{"all:choice,sequence,elt"}); |
|
876 |
} |
|
877 |
||
878 |
default: |
|
879 |
{ |
|
880 |
throw new XMLSchemaException("Internal-Error", |
|
881 |
new Object[]{"in particleValidRestriction"}); |
|
882 |
} |
|
883 |
} |
|
884 |
} |
|
885 |
||
886 |
case XSModelGroupImpl.MODELGROUP_CHOICE: |
|
887 |
{ |
|
888 |
switch (bType) { |
|
889 |
||
890 |
// Choice:Any NSRecurseCheckCardinality |
|
891 |
case XSParticleDecl.PARTICLE_WILDCARD: |
|
892 |
{ |
|
893 |
if (dMinEffectiveTotalRange == OCCURRENCE_UNKNOWN) |
|
894 |
dMinEffectiveTotalRange = dParticle.minEffectiveTotalRange(); |
|
895 |
if (dMaxEffectiveTotalRange == OCCURRENCE_UNKNOWN) |
|
896 |
dMaxEffectiveTotalRange = dParticle.maxEffectiveTotalRange(); |
|
897 |
||
898 |
checkNSRecurseCheckCardinality(dChildren, dMinEffectiveTotalRange, |
|
899 |
dMaxEffectiveTotalRange, |
|
900 |
dSGHandler, |
|
901 |
bParticle,bMinOccurs,bMaxOccurs, |
|
902 |
checkWCOccurrence); |
|
903 |
return bExpansionHappened; |
|
904 |
} |
|
905 |
||
906 |
case XSModelGroupImpl.MODELGROUP_CHOICE: |
|
907 |
{ |
|
908 |
checkRecurseLax(dChildren, dMinOccurs, dMaxOccurs, dSGHandler, |
|
909 |
bChildren, bMinOccurs, bMaxOccurs, bSGHandler); |
|
910 |
return bExpansionHappened; |
|
911 |
} |
|
912 |
||
913 |
case XSModelGroupImpl.MODELGROUP_ALL: |
|
914 |
case XSModelGroupImpl.MODELGROUP_SEQUENCE: |
|
915 |
case XSParticleDecl.PARTICLE_ELEMENT: |
|
916 |
{ |
|
917 |
throw new XMLSchemaException("cos-particle-restrict.2", |
|
918 |
new Object[]{"choice:all,sequence,elt"}); |
|
919 |
} |
|
920 |
||
921 |
default: |
|
922 |
{ |
|
923 |
throw new XMLSchemaException("Internal-Error", |
|
924 |
new Object[]{"in particleValidRestriction"}); |
|
925 |
} |
|
926 |
} |
|
927 |
} |
|
928 |
||
929 |
||
930 |
case XSModelGroupImpl.MODELGROUP_SEQUENCE: |
|
931 |
{ |
|
932 |
switch (bType) { |
|
933 |
||
934 |
// Choice:Any NSRecurseCheckCardinality |
|
935 |
case XSParticleDecl.PARTICLE_WILDCARD: |
|
936 |
{ |
|
937 |
if (dMinEffectiveTotalRange == OCCURRENCE_UNKNOWN) |
|
938 |
dMinEffectiveTotalRange = dParticle.minEffectiveTotalRange(); |
|
939 |
if (dMaxEffectiveTotalRange == OCCURRENCE_UNKNOWN) |
|
940 |
dMaxEffectiveTotalRange = dParticle.maxEffectiveTotalRange(); |
|
941 |
||
942 |
checkNSRecurseCheckCardinality(dChildren, dMinEffectiveTotalRange, |
|
943 |
dMaxEffectiveTotalRange, |
|
944 |
dSGHandler, |
|
945 |
bParticle,bMinOccurs,bMaxOccurs, |
|
946 |
checkWCOccurrence); |
|
947 |
return bExpansionHappened; |
|
948 |
} |
|
949 |
||
950 |
case XSModelGroupImpl.MODELGROUP_ALL: |
|
951 |
{ |
|
952 |
checkRecurseUnordered(dChildren, dMinOccurs, dMaxOccurs, dSGHandler, |
|
953 |
bChildren, bMinOccurs, bMaxOccurs, bSGHandler); |
|
954 |
return bExpansionHappened; |
|
955 |
} |
|
956 |
||
957 |
case XSModelGroupImpl.MODELGROUP_SEQUENCE: |
|
958 |
{ |
|
959 |
checkRecurse(dChildren, dMinOccurs, dMaxOccurs, dSGHandler, |
|
960 |
bChildren, bMinOccurs, bMaxOccurs, bSGHandler); |
|
961 |
return bExpansionHappened; |
|
962 |
} |
|
963 |
||
964 |
case XSModelGroupImpl.MODELGROUP_CHOICE: |
|
965 |
{ |
|
966 |
int min1 = dMinOccurs * dChildren.size(); |
|
967 |
int max1 = (dMaxOccurs == SchemaSymbols.OCCURRENCE_UNBOUNDED)? |
|
968 |
dMaxOccurs : dMaxOccurs * dChildren.size(); |
|
969 |
checkMapAndSum(dChildren, min1, max1, dSGHandler, |
|
970 |
bChildren, bMinOccurs, bMaxOccurs, bSGHandler); |
|
971 |
return bExpansionHappened; |
|
972 |
} |
|
973 |
||
974 |
case XSParticleDecl.PARTICLE_ELEMENT: |
|
975 |
{ |
|
976 |
throw new XMLSchemaException("cos-particle-restrict.2", |
|
977 |
new Object[]{"seq:elt"}); |
|
978 |
} |
|
979 |
||
980 |
default: |
|
981 |
{ |
|
982 |
throw new XMLSchemaException("Internal-Error", |
|
983 |
new Object[]{"in particleValidRestriction"}); |
|
984 |
} |
|
985 |
} |
|
986 |
} |
|
987 |
||
988 |
} |
|
989 |
||
990 |
return bExpansionHappened; |
|
991 |
} |
|
992 |
||
993 |
private static void addElementToParticleVector (Vector v, XSElementDecl d) { |
|
994 |
||
995 |
XSParticleDecl p = new XSParticleDecl(); |
|
996 |
p.fValue = d; |
|
997 |
p.fType = XSParticleDecl.PARTICLE_ELEMENT; |
|
998 |
v.addElement(p); |
|
999 |
||
1000 |
} |
|
1001 |
||
1002 |
private static XSParticleDecl getNonUnaryGroup(XSParticleDecl p) { |
|
1003 |
||
1004 |
if (p.fType == XSParticleDecl.PARTICLE_ELEMENT || |
|
1005 |
p.fType == XSParticleDecl.PARTICLE_WILDCARD) |
|
1006 |
return p; |
|
1007 |
||
1008 |
if (p.fMinOccurs==1 && p.fMaxOccurs==1 && |
|
1009 |
p.fValue!=null && ((XSModelGroupImpl)p.fValue).fParticleCount == 1) |
|
1010 |
return getNonUnaryGroup(((XSModelGroupImpl)p.fValue).fParticles[0]); |
|
1011 |
else |
|
1012 |
return p; |
|
1013 |
} |
|
1014 |
||
1015 |
private static Vector removePointlessChildren(XSParticleDecl p) { |
|
1016 |
||
1017 |
if (p.fType == XSParticleDecl.PARTICLE_ELEMENT || |
|
1018 |
p.fType == XSParticleDecl.PARTICLE_WILDCARD) |
|
1019 |
return null; |
|
1020 |
||
1021 |
Vector children = new Vector(); |
|
1022 |
||
1023 |
XSModelGroupImpl group = (XSModelGroupImpl)p.fValue; |
|
1024 |
for (int i = 0; i < group.fParticleCount; i++) |
|
1025 |
gatherChildren(group.fCompositor, group.fParticles[i], children); |
|
1026 |
||
1027 |
return children; |
|
1028 |
} |
|
1029 |
||
1030 |
||
1031 |
private static void gatherChildren(int parentType, XSParticleDecl p, Vector children) { |
|
1032 |
||
1033 |
int min = p.fMinOccurs; |
|
1034 |
int max = p.fMaxOccurs; |
|
1035 |
int type = p.fType; |
|
1036 |
if (type == XSParticleDecl.PARTICLE_MODELGROUP) |
|
1037 |
type = ((XSModelGroupImpl)p.fValue).fCompositor; |
|
1038 |
||
1039 |
if (type == XSParticleDecl.PARTICLE_ELEMENT || |
|
1040 |
type== XSParticleDecl.PARTICLE_WILDCARD) { |
|
1041 |
children.addElement(p); |
|
1042 |
return; |
|
1043 |
} |
|
1044 |
||
1045 |
if (! (min==1 && max==1)) { |
|
1046 |
children.addElement(p); |
|
1047 |
} |
|
1048 |
else if (parentType == type) { |
|
1049 |
XSModelGroupImpl group = (XSModelGroupImpl)p.fValue; |
|
1050 |
for (int i = 0; i < group.fParticleCount; i++) |
|
1051 |
gatherChildren(type, group.fParticles[i], children); |
|
1052 |
} |
|
1053 |
else if (!p.isEmpty()) { |
|
1054 |
children.addElement(p); |
|
1055 |
} |
|
1056 |
||
1057 |
} |
|
1058 |
||
1059 |
private static void checkNameAndTypeOK(XSElementDecl dElement, int dMin, int dMax, |
|
1060 |
XSElementDecl bElement, int bMin, int bMax) |
|
1061 |
throws XMLSchemaException { |
|
1062 |
||
1063 |
||
1064 |
// |
|
1065 |
// Check that the names are the same |
|
1066 |
// |
|
1067 |
if (dElement.fName != bElement.fName || |
|
1068 |
dElement.fTargetNamespace != bElement.fTargetNamespace) { |
|
1069 |
throw new XMLSchemaException( |
|
1070 |
"rcase-NameAndTypeOK.1",new Object[]{dElement.fName, |
|
1071 |
dElement.fTargetNamespace, bElement.fName, bElement.fTargetNamespace}); |
|
1072 |
} |
|
1073 |
||
1074 |
// |
|
1075 |
// Check nillable |
|
1076 |
// |
|
1077 |
if (!bElement.getNillable() && dElement.getNillable()) { |
|
1078 |
throw new XMLSchemaException("rcase-NameAndTypeOK.2", |
|
1079 |
new Object[]{dElement.fName}); |
|
1080 |
} |
|
1081 |
||
1082 |
// |
|
1083 |
// Check occurrence range |
|
1084 |
// |
|
1085 |
if (!checkOccurrenceRange(dMin, dMax, bMin, bMax)) { |
|
1086 |
throw new XMLSchemaException("rcase-NameAndTypeOK.3", |
|
1087 |
new Object[]{ |
|
1088 |
dElement.fName, |
|
1089 |
Integer.toString(dMin), |
|
1090 |
dMax==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(dMax), |
|
1091 |
Integer.toString(bMin), |
|
1092 |
bMax==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(bMax)}); |
|
1093 |
} |
|
1094 |
||
1095 |
// |
|
1096 |
// Check for consistent fixed values |
|
1097 |
// |
|
1098 |
if (bElement.getConstraintType() == XSConstants.VC_FIXED) { |
|
1099 |
// derived one has to have a fixed value |
|
1100 |
if (dElement.getConstraintType() != XSConstants.VC_FIXED) { |
|
1101 |
throw new XMLSchemaException("rcase-NameAndTypeOK.4.a", |
|
1102 |
new Object[]{dElement.fName, bElement.fDefault.stringValue()}); |
|
1103 |
} |
|
1104 |
||
1105 |
// get simple type |
|
1106 |
boolean isSimple = false; |
|
1107 |
if (dElement.fType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE || |
|
1108 |
((XSComplexTypeDecl)dElement.fType).fContentType == XSComplexTypeDecl.CONTENTTYPE_SIMPLE) { |
|
1109 |
isSimple = true; |
|
1110 |
} |
|
1111 |
||
1112 |
// if there is no simple type, then compare based on string |
|
1113 |
if (!isSimple && !bElement.fDefault.normalizedValue.equals(dElement.fDefault.normalizedValue) || |
|
1114 |
isSimple && !bElement.fDefault.actualValue.equals(dElement.fDefault.actualValue)) { |
|
1115 |
throw new XMLSchemaException("rcase-NameAndTypeOK.4.b", |
|
1116 |
new Object[]{dElement.fName, |
|
1117 |
dElement.fDefault.stringValue(), |
|
1118 |
bElement.fDefault.stringValue()}); |
|
1119 |
} |
|
1120 |
} |
|
1121 |
||
1122 |
// |
|
1123 |
// Check identity constraints |
|
1124 |
// |
|
1125 |
checkIDConstraintRestriction(dElement, bElement); |
|
1126 |
||
1127 |
// |
|
1128 |
// Check for disallowed substitutions |
|
1129 |
// |
|
1130 |
int blockSet1 = dElement.fBlock; |
|
1131 |
int blockSet2 = bElement.fBlock; |
|
1132 |
if (((blockSet1 & blockSet2)!=blockSet2) || |
|
1133 |
(blockSet1==XSConstants.DERIVATION_NONE && blockSet2!=XSConstants.DERIVATION_NONE)) |
|
1134 |
throw new XMLSchemaException("rcase-NameAndTypeOK.6", |
|
1135 |
new Object[]{dElement.fName}); |
|
1136 |
||
1137 |
||
1138 |
// |
|
1139 |
// Check that the derived element's type is derived from the base's. |
|
1140 |
// |
|
1141 |
if (!checkTypeDerivationOk(dElement.fType, bElement.fType, |
|
1142 |
(short)(XSConstants.DERIVATION_EXTENSION|XSConstants.DERIVATION_LIST|XSConstants.DERIVATION_UNION))) { |
|
1143 |
throw new XMLSchemaException("rcase-NameAndTypeOK.7", |
|
1144 |
new Object[]{dElement.fName, dElement.fType.getName(), bElement.fType.getName()}); |
|
1145 |
} |
|
1146 |
||
1147 |
} |
|
1148 |
||
1149 |
||
1150 |
private static void checkIDConstraintRestriction(XSElementDecl derivedElemDecl, |
|
1151 |
XSElementDecl baseElemDecl) |
|
1152 |
throws XMLSchemaException { |
|
1153 |
// TODO |
|
1154 |
} // checkIDConstraintRestriction |
|
1155 |
||
1156 |
||
1157 |
private static boolean checkOccurrenceRange(int min1, int max1, int min2, int max2) { |
|
1158 |
||
1159 |
if ((min1 >= min2) && |
|
1160 |
((max2==SchemaSymbols.OCCURRENCE_UNBOUNDED) || |
|
1161 |
(max1!=SchemaSymbols.OCCURRENCE_UNBOUNDED && max1<=max2))) |
|
1162 |
return true; |
|
1163 |
else |
|
1164 |
return false; |
|
1165 |
} |
|
1166 |
||
1167 |
private static void checkNSCompat(XSElementDecl elem, int min1, int max1, |
|
1168 |
XSWildcardDecl wildcard, int min2, int max2, |
|
1169 |
boolean checkWCOccurrence) |
|
1170 |
throws XMLSchemaException { |
|
1171 |
||
1172 |
// check Occurrence ranges |
|
1173 |
if (checkWCOccurrence && !checkOccurrenceRange(min1,max1,min2,max2)) { |
|
1174 |
throw new XMLSchemaException("rcase-NSCompat.2", |
|
1175 |
new Object[]{ |
|
1176 |
elem.fName, |
|
1177 |
Integer.toString(min1), |
|
1178 |
max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1), |
|
1179 |
Integer.toString(min2), |
|
1180 |
max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)}); |
|
1181 |
} |
|
1182 |
||
1183 |
// check wildcard allows namespace of element |
|
1184 |
if (!wildcard.allowNamespace(elem.fTargetNamespace)) { |
|
1185 |
throw new XMLSchemaException("rcase-NSCompat.1", |
|
1186 |
new Object[]{elem.fName,elem.fTargetNamespace}); |
|
1187 |
} |
|
1188 |
||
1189 |
} |
|
1190 |
||
1191 |
private static void checkNSSubset(XSWildcardDecl dWildcard, int min1, int max1, |
|
1192 |
XSWildcardDecl bWildcard, int min2, int max2) |
|
1193 |
throws XMLSchemaException { |
|
1194 |
||
1195 |
// check Occurrence ranges |
|
1196 |
if (!checkOccurrenceRange(min1,max1,min2,max2)) { |
|
1197 |
throw new XMLSchemaException("rcase-NSSubset.2", new Object[]{ |
|
1198 |
Integer.toString(min1), |
|
1199 |
max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1), |
|
1200 |
Integer.toString(min2), |
|
1201 |
max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)}); |
|
1202 |
} |
|
1203 |
||
1204 |
// check wildcard subset |
|
1205 |
if (!dWildcard.isSubsetOf(bWildcard)) { |
|
1206 |
throw new XMLSchemaException("rcase-NSSubset.1", null); |
|
1207 |
} |
|
1208 |
||
1209 |
if (dWildcard.weakerProcessContents(bWildcard)) { |
|
1210 |
throw new XMLSchemaException("rcase-NSSubset.3", |
|
1211 |
new Object[]{dWildcard.getProcessContentsAsString(), |
|
1212 |
bWildcard.getProcessContentsAsString()}); |
|
1213 |
} |
|
1214 |
||
1215 |
} |
|
1216 |
||
1217 |
||
1218 |
private static void checkNSRecurseCheckCardinality(Vector children, int min1, int max1, |
|
1219 |
SubstitutionGroupHandler dSGHandler, |
|
1220 |
XSParticleDecl wildcard, int min2, int max2, |
|
1221 |
boolean checkWCOccurrence) |
|
1222 |
throws XMLSchemaException { |
|
1223 |
||
1224 |
||
1225 |
// check Occurrence ranges |
|
1226 |
if (checkWCOccurrence && !checkOccurrenceRange(min1,max1,min2,max2)) { |
|
1227 |
throw new XMLSchemaException("rcase-NSRecurseCheckCardinality.2", new Object[]{ |
|
1228 |
Integer.toString(min1), |
|
1229 |
max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1), |
|
1230 |
Integer.toString(min2), |
|
1231 |
max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)}); |
|
1232 |
} |
|
1233 |
||
1234 |
// Check that each member of the group is a valid restriction of the wildcard |
|
1235 |
int count = children.size(); |
|
1236 |
try { |
|
1237 |
for (int i = 0; i < count; i++) { |
|
1238 |
XSParticleDecl particle1 = (XSParticleDecl)children.elementAt(i); |
|
1239 |
particleValidRestriction(particle1, dSGHandler, wildcard, null, false); |
|
1240 |
||
1241 |
} |
|
1242 |
} |
|
1243 |
// REVISIT: should we really just ignore original cause of this error? |
|
1244 |
// how can we report it? |
|
1245 |
catch (XMLSchemaException e) { |
|
1246 |
throw new XMLSchemaException("rcase-NSRecurseCheckCardinality.1", null); |
|
1247 |
} |
|
1248 |
||
1249 |
} |
|
1250 |
||
1251 |
private static void checkRecurse(Vector dChildren, int min1, int max1, |
|
1252 |
SubstitutionGroupHandler dSGHandler, |
|
1253 |
Vector bChildren, int min2, int max2, |
|
1254 |
SubstitutionGroupHandler bSGHandler) |
|
1255 |
throws XMLSchemaException { |
|
1256 |
||
1257 |
// check Occurrence ranges |
|
1258 |
if (!checkOccurrenceRange(min1,max1,min2,max2)) { |
|
1259 |
throw new XMLSchemaException("rcase-Recurse.1", new Object[]{ |
|
1260 |
Integer.toString(min1), |
|
1261 |
max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1), |
|
1262 |
Integer.toString(min2), |
|
1263 |
max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)}); |
|
1264 |
} |
|
1265 |
||
1266 |
int count1= dChildren.size(); |
|
1267 |
int count2= bChildren.size(); |
|
1268 |
||
1269 |
int current = 0; |
|
1270 |
label: for (int i = 0; i<count1; i++) { |
|
1271 |
||
1272 |
XSParticleDecl particle1 = (XSParticleDecl)dChildren.elementAt(i); |
|
1273 |
for (int j = current; j<count2; j++) { |
|
1274 |
XSParticleDecl particle2 = (XSParticleDecl)bChildren.elementAt(j); |
|
1275 |
current +=1; |
|
1276 |
try { |
|
1277 |
particleValidRestriction(particle1, dSGHandler, particle2, bSGHandler); |
|
1278 |
continue label; |
|
1279 |
} |
|
1280 |
catch (XMLSchemaException e) { |
|
1281 |
if (!particle2.emptiable()) |
|
1282 |
throw new XMLSchemaException("rcase-Recurse.2", null); |
|
1283 |
} |
|
1284 |
} |
|
1285 |
throw new XMLSchemaException("rcase-Recurse.2", null); |
|
1286 |
} |
|
1287 |
||
1288 |
// Now, see if there are some elements in the base we didn't match up |
|
1289 |
for (int j=current; j < count2; j++) { |
|
1290 |
XSParticleDecl particle2 = (XSParticleDecl)bChildren.elementAt(j); |
|
1291 |
if (!particle2.emptiable()) { |
|
1292 |
throw new XMLSchemaException("rcase-Recurse.2", null); |
|
1293 |
} |
|
1294 |
} |
|
1295 |
||
1296 |
} |
|
1297 |
||
1298 |
private static void checkRecurseUnordered(Vector dChildren, int min1, int max1, |
|
1299 |
SubstitutionGroupHandler dSGHandler, |
|
1300 |
Vector bChildren, int min2, int max2, |
|
1301 |
SubstitutionGroupHandler bSGHandler) |
|
1302 |
throws XMLSchemaException { |
|
1303 |
||
1304 |
||
1305 |
// check Occurrence ranges |
|
1306 |
if (!checkOccurrenceRange(min1,max1,min2,max2)) { |
|
1307 |
throw new XMLSchemaException("rcase-RecurseUnordered.1", new Object[]{ |
|
1308 |
Integer.toString(min1), |
|
1309 |
max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1), |
|
1310 |
Integer.toString(min2), |
|
1311 |
max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)}); |
|
1312 |
} |
|
1313 |
||
1314 |
int count1= dChildren.size(); |
|
1315 |
int count2 = bChildren.size(); |
|
1316 |
||
1317 |
boolean foundIt[] = new boolean[count2]; |
|
1318 |
||
1319 |
label: for (int i = 0; i<count1; i++) { |
|
1320 |
XSParticleDecl particle1 = (XSParticleDecl)dChildren.elementAt(i); |
|
1321 |
||
1322 |
for (int j = 0; j<count2; j++) { |
|
1323 |
XSParticleDecl particle2 = (XSParticleDecl)bChildren.elementAt(j); |
|
1324 |
try { |
|
1325 |
particleValidRestriction(particle1, dSGHandler, particle2, bSGHandler); |
|
1326 |
if (foundIt[j]) |
|
1327 |
throw new XMLSchemaException("rcase-RecurseUnordered.2", null); |
|
1328 |
else |
|
1329 |
foundIt[j]=true; |
|
1330 |
||
1331 |
continue label; |
|
1332 |
} |
|
1333 |
catch (XMLSchemaException e) { |
|
1334 |
} |
|
1335 |
} |
|
1336 |
// didn't find a match. Detect an error |
|
1337 |
throw new XMLSchemaException("rcase-RecurseUnordered.2", null); |
|
1338 |
} |
|
1339 |
||
1340 |
// Now, see if there are some elements in the base we didn't match up |
|
1341 |
for (int j=0; j < count2; j++) { |
|
1342 |
XSParticleDecl particle2 = (XSParticleDecl)bChildren.elementAt(j); |
|
1343 |
if (!foundIt[j] && !particle2.emptiable()) { |
|
1344 |
throw new XMLSchemaException("rcase-RecurseUnordered.2", null); |
|
1345 |
} |
|
1346 |
} |
|
1347 |
||
1348 |
} |
|
1349 |
||
1350 |
private static void checkRecurseLax(Vector dChildren, int min1, int max1, |
|
1351 |
SubstitutionGroupHandler dSGHandler, |
|
1352 |
Vector bChildren, int min2, int max2, |
|
1353 |
SubstitutionGroupHandler bSGHandler) |
|
1354 |
throws XMLSchemaException { |
|
1355 |
||
1356 |
// check Occurrence ranges |
|
1357 |
if (!checkOccurrenceRange(min1,max1,min2,max2)) { |
|
1358 |
throw new XMLSchemaException("rcase-RecurseLax.1", new Object[]{ |
|
1359 |
Integer.toString(min1), |
|
1360 |
max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1), |
|
1361 |
Integer.toString(min2), |
|
1362 |
max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)}); |
|
1363 |
} |
|
1364 |
||
1365 |
int count1= dChildren.size(); |
|
1366 |
int count2 = bChildren.size(); |
|
1367 |
||
1368 |
int current = 0; |
|
1369 |
label: for (int i = 0; i<count1; i++) { |
|
1370 |
||
1371 |
XSParticleDecl particle1 = (XSParticleDecl)dChildren.elementAt(i); |
|
1372 |
for (int j = current; j<count2; j++) { |
|
1373 |
XSParticleDecl particle2 = (XSParticleDecl)bChildren.elementAt(j); |
|
1374 |
current +=1; |
|
1375 |
try { |
|
1376 |
// IHR: go back one element on b list because the next element may match |
|
1377 |
// this as well. |
|
1378 |
if (particleValidRestriction(particle1, dSGHandler, particle2, bSGHandler)) |
|
1379 |
current--; |
|
1380 |
continue label; |
|
1381 |
} |
|
1382 |
catch (XMLSchemaException e) { |
|
1383 |
} |
|
1384 |
} |
|
1385 |
// didn't find a match. Detect an error |
|
1386 |
throw new XMLSchemaException("rcase-RecurseLax.2", null); |
|
1387 |
||
1388 |
} |
|
1389 |
||
1390 |
} |
|
1391 |
||
1392 |
private static void checkMapAndSum(Vector dChildren, int min1, int max1, |
|
1393 |
SubstitutionGroupHandler dSGHandler, |
|
1394 |
Vector bChildren, int min2, int max2, |
|
1395 |
SubstitutionGroupHandler bSGHandler) |
|
1396 |
throws XMLSchemaException { |
|
1397 |
||
1398 |
// See if the sequence group is a valid restriction of the choice |
|
1399 |
||
1400 |
// Here is an example of a valid restriction: |
|
1401 |
// <choice minOccurs="2"> |
|
1402 |
// <a/> |
|
1403 |
// <b/> |
|
1404 |
// <c/> |
|
1405 |
// </choice> |
|
1406 |
// |
|
1407 |
// <sequence> |
|
1408 |
// <b/> |
|
1409 |
// <a/> |
|
1410 |
// </sequence> |
|
1411 |
||
1412 |
// check Occurrence ranges |
|
1413 |
if (!checkOccurrenceRange(min1,max1,min2,max2)) { |
|
1414 |
throw new XMLSchemaException("rcase-MapAndSum.2", |
|
1415 |
new Object[]{Integer.toString(min1), |
|
1416 |
max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1), |
|
1417 |
Integer.toString(min2), |
|
1418 |
max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)}); |
|
1419 |
} |
|
1420 |
||
1421 |
int count1 = dChildren.size(); |
|
1422 |
int count2 = bChildren.size(); |
|
1423 |
||
1424 |
label: for (int i = 0; i<count1; i++) { |
|
1425 |
||
1426 |
XSParticleDecl particle1 = (XSParticleDecl)dChildren.elementAt(i); |
|
1427 |
for (int j = 0; j<count2; j++) { |
|
1428 |
XSParticleDecl particle2 = (XSParticleDecl)bChildren.elementAt(j); |
|
1429 |
try { |
|
1430 |
particleValidRestriction(particle1, dSGHandler, particle2, bSGHandler); |
|
1431 |
continue label; |
|
1432 |
} |
|
1433 |
catch (XMLSchemaException e) { |
|
1434 |
} |
|
1435 |
} |
|
1436 |
// didn't find a match. Detect an error |
|
1437 |
throw new XMLSchemaException("rcase-MapAndSum.1", null); |
|
1438 |
} |
|
1439 |
} |
|
1440 |
// to check whether two element overlap, as defined in constraint UPA |
|
1441 |
public static boolean overlapUPA(XSElementDecl element1, |
|
1442 |
XSElementDecl element2, |
|
1443 |
SubstitutionGroupHandler sgHandler) { |
|
1444 |
// if the two element have the same name and namespace, |
|
1445 |
if (element1.fName == element2.fName && |
|
1446 |
element1.fTargetNamespace == element2.fTargetNamespace) { |
|
1447 |
return true; |
|
1448 |
} |
|
1449 |
||
1450 |
// or if there is an element decl in element1's substitution group, |
|
1451 |
// who has the same name/namespace with element2 |
|
1452 |
XSElementDecl[] subGroup = sgHandler.getSubstitutionGroup(element1); |
|
1453 |
for (int i = subGroup.length-1; i >= 0; i--) { |
|
1454 |
if (subGroup[i].fName == element2.fName && |
|
1455 |
subGroup[i].fTargetNamespace == element2.fTargetNamespace) { |
|
1456 |
return true; |
|
1457 |
} |
|
1458 |
} |
|
1459 |
||
1460 |
// or if there is an element decl in element2's substitution group, |
|
1461 |
// who has the same name/namespace with element1 |
|
1462 |
subGroup = sgHandler.getSubstitutionGroup(element2); |
|
1463 |
for (int i = subGroup.length-1; i >= 0; i--) { |
|
1464 |
if (subGroup[i].fName == element1.fName && |
|
1465 |
subGroup[i].fTargetNamespace == element1.fTargetNamespace) { |
|
1466 |
return true; |
|
1467 |
} |
|
1468 |
} |
|
1469 |
||
1470 |
return false; |
|
1471 |
} |
|
1472 |
||
1473 |
// to check whether an element overlaps with a wildcard, |
|
1474 |
// as defined in constraint UPA |
|
1475 |
public static boolean overlapUPA(XSElementDecl element, |
|
1476 |
XSWildcardDecl wildcard, |
|
1477 |
SubstitutionGroupHandler sgHandler) { |
|
1478 |
// if the wildcard allows the element |
|
1479 |
if (wildcard.allowNamespace(element.fTargetNamespace)) |
|
1480 |
return true; |
|
1481 |
||
1482 |
// or if the wildcard allows any element in the substitution group |
|
1483 |
XSElementDecl[] subGroup = sgHandler.getSubstitutionGroup(element); |
|
1484 |
for (int i = subGroup.length-1; i >= 0; i--) { |
|
1485 |
if (wildcard.allowNamespace(subGroup[i].fTargetNamespace)) |
|
1486 |
return true; |
|
1487 |
} |
|
1488 |
||
1489 |
return false; |
|
1490 |
} |
|
1491 |
||
1492 |
public static boolean overlapUPA(XSWildcardDecl wildcard1, |
|
1493 |
XSWildcardDecl wildcard2) { |
|
1494 |
// if the intersection of the two wildcard is not empty list |
|
1495 |
XSWildcardDecl intersect = wildcard1.performIntersectionWith(wildcard2, wildcard1.fProcessContents); |
|
1496 |
if (intersect == null || |
|
1497 |
intersect.fType != XSWildcardDecl.NSCONSTRAINT_LIST || |
|
1498 |
intersect.fNamespaceList.length != 0) { |
|
1499 |
return true; |
|
1500 |
} |
|
1501 |
||
1502 |
return false; |
|
1503 |
} |
|
1504 |
||
1505 |
// call one of the above methods according to the type of decls |
|
1506 |
public static boolean overlapUPA(Object decl1, Object decl2, |
|
1507 |
SubstitutionGroupHandler sgHandler) { |
|
1508 |
if (decl1 instanceof XSElementDecl) { |
|
1509 |
if (decl2 instanceof XSElementDecl) { |
|
1510 |
return overlapUPA((XSElementDecl)decl1, |
|
1511 |
(XSElementDecl)decl2, |
|
1512 |
sgHandler); |
|
1513 |
} |
|
1514 |
else { |
|
1515 |
return overlapUPA((XSElementDecl)decl1, |
|
1516 |
(XSWildcardDecl)decl2, |
|
1517 |
sgHandler); |
|
1518 |
} |
|
1519 |
} |
|
1520 |
else { |
|
1521 |
if (decl2 instanceof XSElementDecl) { |
|
1522 |
return overlapUPA((XSElementDecl)decl2, |
|
1523 |
(XSWildcardDecl)decl1, |
|
1524 |
sgHandler); |
|
1525 |
} |
|
1526 |
else { |
|
1527 |
return overlapUPA((XSWildcardDecl)decl1, |
|
1528 |
(XSWildcardDecl)decl2); |
|
1529 |
} |
|
1530 |
} |
|
1531 |
} |
|
1532 |
||
1533 |
} // class XSContraints |