author | joehw |
Sat, 18 Apr 2015 00:17:19 -0700 | |
changeset 33349 | 975138b77cff |
parent 27111 | 7a491d709b83 |
child 39907 | db51759e3695 |
permissions | -rw-r--r-- |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1 |
/* |
33349 | 2 |
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3 |
*/ |
12005 | 4 |
/* |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
5 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
6 |
* contributor license agreements. See the NOTICE file distributed with |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
7 |
* this work for additional information regarding copyright ownership. |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
8 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
9 |
* (the "License"); you may not use this file except in compliance with |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
10 |
* the License. You may obtain a copy of the License at |
12005 | 11 |
* |
12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13 |
* |
|
14 |
* Unless required by applicable law or agreed to in writing, software |
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17 |
* See the License for the specific language governing permissions and |
|
18 |
* limitations under the License. |
|
19 |
*/ |
|
20 |
||
21 |
package com.sun.org.apache.xerces.internal.impl.xs; |
|
22 |
||
23 |
import com.sun.org.apache.xerces.internal.impl.Constants; |
|
24 |
import com.sun.org.apache.xerces.internal.impl.RevalidationHandler; |
|
25 |
import com.sun.org.apache.xerces.internal.impl.XMLEntityManager; |
|
26 |
import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; |
|
27 |
import com.sun.org.apache.xerces.internal.impl.dv.DatatypeException; |
|
28 |
import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException; |
|
29 |
import com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo; |
|
30 |
import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType; |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
31 |
import com.sun.org.apache.xerces.internal.impl.dv.xs.XSSimpleTypeDecl; |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
32 |
import com.sun.org.apache.xerces.internal.impl.validation.ConfigurableValidationState; |
12005 | 33 |
import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager; |
34 |
import com.sun.org.apache.xerces.internal.impl.validation.ValidationState; |
|
35 |
import com.sun.org.apache.xerces.internal.impl.xs.identity.Field; |
|
36 |
import com.sun.org.apache.xerces.internal.impl.xs.identity.FieldActivator; |
|
37 |
import com.sun.org.apache.xerces.internal.impl.xs.identity.IdentityConstraint; |
|
38 |
import com.sun.org.apache.xerces.internal.impl.xs.identity.KeyRef; |
|
39 |
import com.sun.org.apache.xerces.internal.impl.xs.identity.Selector; |
|
40 |
import com.sun.org.apache.xerces.internal.impl.xs.identity.UniqueOrKey; |
|
41 |
import com.sun.org.apache.xerces.internal.impl.xs.identity.ValueStore; |
|
42 |
import com.sun.org.apache.xerces.internal.impl.xs.identity.XPathMatcher; |
|
43 |
import com.sun.org.apache.xerces.internal.impl.xs.models.CMBuilder; |
|
44 |
import com.sun.org.apache.xerces.internal.impl.xs.models.CMNodeFactory; |
|
45 |
import com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator; |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
46 |
import com.sun.org.apache.xerces.internal.impl.xs.util.XS10TypeHelper; |
33349 | 47 |
import com.sun.org.apache.xerces.internal.parsers.XMLParser; |
12005 | 48 |
import com.sun.org.apache.xerces.internal.util.AugmentationsImpl; |
49 |
import com.sun.org.apache.xerces.internal.util.IntStack; |
|
50 |
import com.sun.org.apache.xerces.internal.util.SymbolTable; |
|
33349 | 51 |
import com.sun.org.apache.xerces.internal.util.URI.MalformedURIException; |
12005 | 52 |
import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl; |
53 |
import com.sun.org.apache.xerces.internal.util.XMLChar; |
|
54 |
import com.sun.org.apache.xerces.internal.util.XMLSymbols; |
|
55 |
import com.sun.org.apache.xerces.internal.xni.Augmentations; |
|
56 |
import com.sun.org.apache.xerces.internal.xni.NamespaceContext; |
|
57 |
import com.sun.org.apache.xerces.internal.xni.QName; |
|
58 |
import com.sun.org.apache.xerces.internal.xni.XMLAttributes; |
|
59 |
import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; |
|
60 |
import com.sun.org.apache.xerces.internal.xni.XMLLocator; |
|
61 |
import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; |
|
62 |
import com.sun.org.apache.xerces.internal.xni.XMLString; |
|
63 |
import com.sun.org.apache.xerces.internal.xni.XNIException; |
|
64 |
import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription; |
|
65 |
import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; |
|
66 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; |
|
67 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; |
|
68 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; |
|
69 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentFilter; |
|
70 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource; |
|
71 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver; |
|
72 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; |
|
73 |
import com.sun.org.apache.xerces.internal.xs.AttributePSVI; |
|
74 |
import com.sun.org.apache.xerces.internal.xs.ElementPSVI; |
|
75 |
import com.sun.org.apache.xerces.internal.xs.ShortList; |
|
76 |
import com.sun.org.apache.xerces.internal.xs.StringList; |
|
77 |
import com.sun.org.apache.xerces.internal.xs.XSConstants; |
|
78 |
import com.sun.org.apache.xerces.internal.xs.XSObjectList; |
|
79 |
import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; |
|
33349 | 80 |
import java.io.IOException; |
81 |
import java.util.ArrayList; |
|
82 |
import java.util.Collections; |
|
83 |
import java.util.HashMap; |
|
84 |
import java.util.Iterator; |
|
85 |
import java.util.Map; |
|
86 |
import java.util.Stack; |
|
87 |
import java.util.Vector; |
|
88 |
import javax.xml.XMLConstants; |
|
12005 | 89 |
|
90 |
/** |
|
91 |
* The XML Schema validator. The validator implements a document |
|
92 |
* filter: receiving document events from the scanner; validating |
|
93 |
* the content and structure; augmenting the InfoSet, if applicable; |
|
94 |
* and notifying the parser of the information resulting from the |
|
95 |
* validation process. |
|
96 |
* <p> |
|
97 |
* This component requires the following features and properties from the |
|
98 |
* component manager that uses it: |
|
99 |
* <ul> |
|
100 |
* <li>http://xml.org/sax/features/validation</li> |
|
101 |
* <li>http://apache.org/xml/properties/internal/symbol-table</li> |
|
102 |
* <li>http://apache.org/xml/properties/internal/error-reporter</li> |
|
103 |
* <li>http://apache.org/xml/properties/internal/entity-resolver</li> |
|
104 |
* </ul> |
|
105 |
* |
|
106 |
* @xerces.internal |
|
107 |
* |
|
108 |
* @author Sandy Gao IBM |
|
109 |
* @author Elena Litani IBM |
|
110 |
* @author Andy Clark IBM |
|
111 |
* @author Neeraj Bajaj, Sun Microsystems, inc. |
|
112 |
*/ |
|
113 |
public class XMLSchemaValidator |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
114 |
implements XMLComponent, XMLDocumentFilter, FieldActivator, RevalidationHandler, XSElementDeclHelper { |
12005 | 115 |
|
116 |
// |
|
117 |
// Constants |
|
118 |
// |
|
119 |
private static final boolean DEBUG = false; |
|
120 |
||
121 |
// feature identifiers |
|
122 |
||
123 |
/** Feature identifier: validation. */ |
|
124 |
protected static final String VALIDATION = |
|
125 |
Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; |
|
126 |
||
127 |
/** Feature identifier: validation. */ |
|
128 |
protected static final String SCHEMA_VALIDATION = |
|
129 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE; |
|
130 |
||
131 |
/** Feature identifier: schema full checking*/ |
|
132 |
protected static final String SCHEMA_FULL_CHECKING = |
|
133 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING; |
|
134 |
||
135 |
/** Feature identifier: dynamic validation. */ |
|
136 |
protected static final String DYNAMIC_VALIDATION = |
|
137 |
Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE; |
|
138 |
||
139 |
/** Feature identifier: expose schema normalized value */ |
|
140 |
protected static final String NORMALIZE_DATA = |
|
141 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE; |
|
142 |
||
143 |
/** Feature identifier: send element default value via characters() */ |
|
144 |
protected static final String SCHEMA_ELEMENT_DEFAULT = |
|
145 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT; |
|
146 |
||
147 |
/** Feature identifier: augment PSVI */ |
|
148 |
protected static final String SCHEMA_AUGMENT_PSVI = |
|
149 |
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI; |
|
150 |
||
151 |
/** Feature identifier: whether to recognize java encoding names */ |
|
152 |
protected static final String ALLOW_JAVA_ENCODINGS = |
|
153 |
Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE; |
|
154 |
||
155 |
/** Feature identifier: standard uri conformant feature. */ |
|
156 |
protected static final String STANDARD_URI_CONFORMANT_FEATURE = |
|
157 |
Constants.XERCES_FEATURE_PREFIX + Constants.STANDARD_URI_CONFORMANT_FEATURE; |
|
158 |
||
159 |
/** Feature: generate synthetic annotations */ |
|
160 |
protected static final String GENERATE_SYNTHETIC_ANNOTATIONS = |
|
161 |
Constants.XERCES_FEATURE_PREFIX + Constants.GENERATE_SYNTHETIC_ANNOTATIONS_FEATURE; |
|
162 |
||
163 |
/** Feature identifier: validate annotations. */ |
|
164 |
protected static final String VALIDATE_ANNOTATIONS = |
|
165 |
Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATE_ANNOTATIONS_FEATURE; |
|
166 |
||
167 |
/** Feature identifier: honour all schemaLocations */ |
|
168 |
protected static final String HONOUR_ALL_SCHEMALOCATIONS = |
|
169 |
Constants.XERCES_FEATURE_PREFIX + Constants.HONOUR_ALL_SCHEMALOCATIONS_FEATURE; |
|
170 |
||
171 |
/** Feature identifier: use grammar pool only */ |
|
172 |
protected static final String USE_GRAMMAR_POOL_ONLY = |
|
173 |
Constants.XERCES_FEATURE_PREFIX + Constants.USE_GRAMMAR_POOL_ONLY_FEATURE; |
|
174 |
||
175 |
/** Feature identifier: whether to continue parsing a schema after a fatal error is encountered */ |
|
176 |
protected static final String CONTINUE_AFTER_FATAL_ERROR = |
|
177 |
Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE; |
|
178 |
||
179 |
protected static final String PARSER_SETTINGS = |
|
180 |
Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS; |
|
181 |
||
182 |
/** Feature identifier: namespace growth */ |
|
183 |
protected static final String NAMESPACE_GROWTH = |
|
184 |
Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_GROWTH_FEATURE; |
|
185 |
||
186 |
/** Feature identifier: tolerate duplicates */ |
|
187 |
protected static final String TOLERATE_DUPLICATES = |
|
188 |
Constants.XERCES_FEATURE_PREFIX + Constants.TOLERATE_DUPLICATES_FEATURE; |
|
189 |
||
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
190 |
/** Feature identifier: whether to ignore xsi:type attributes until a global element declaration is encountered */ |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
191 |
protected static final String IGNORE_XSI_TYPE = |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
192 |
Constants.XERCES_FEATURE_PREFIX + Constants.IGNORE_XSI_TYPE_FEATURE; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
193 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
194 |
/** Feature identifier: whether to ignore ID/IDREF errors */ |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
195 |
protected static final String ID_IDREF_CHECKING = |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
196 |
Constants.XERCES_FEATURE_PREFIX + Constants.ID_IDREF_CHECKING_FEATURE; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
197 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
198 |
/** Feature identifier: whether to ignore unparsed entity errors */ |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
199 |
protected static final String UNPARSED_ENTITY_CHECKING = |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
200 |
Constants.XERCES_FEATURE_PREFIX + Constants.UNPARSED_ENTITY_CHECKING_FEATURE; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
201 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
202 |
/** Feature identifier: whether to ignore identity constraint errors */ |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
203 |
protected static final String IDENTITY_CONSTRAINT_CHECKING = |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
204 |
Constants.XERCES_FEATURE_PREFIX + Constants.IDC_CHECKING_FEATURE; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
205 |
|
12005 | 206 |
protected static final String REPORT_WHITESPACE = |
207 |
Constants.SUN_SCHEMA_FEATURE_PREFIX + Constants.SUN_REPORT_IGNORED_ELEMENT_CONTENT_WHITESPACE; |
|
208 |
||
209 |
// property identifiers |
|
210 |
||
211 |
/** Property identifier: symbol table. */ |
|
212 |
public static final String SYMBOL_TABLE = |
|
213 |
Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; |
|
214 |
||
215 |
/** Property identifier: error reporter. */ |
|
216 |
public static final String ERROR_REPORTER = |
|
217 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; |
|
218 |
||
219 |
/** Property identifier: entity resolver. */ |
|
220 |
public static final String ENTITY_RESOLVER = |
|
221 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; |
|
222 |
||
223 |
/** Property identifier: grammar pool. */ |
|
224 |
public static final String XMLGRAMMAR_POOL = |
|
225 |
Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; |
|
226 |
||
227 |
protected static final String VALIDATION_MANAGER = |
|
228 |
Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; |
|
229 |
||
230 |
protected static final String ENTITY_MANAGER = |
|
231 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; |
|
232 |
||
233 |
/** Property identifier: schema location. */ |
|
234 |
protected static final String SCHEMA_LOCATION = |
|
235 |
Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_LOCATION; |
|
236 |
||
237 |
/** Property identifier: no namespace schema location. */ |
|
238 |
protected static final String SCHEMA_NONS_LOCATION = |
|
239 |
Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION; |
|
240 |
||
241 |
/** Property identifier: JAXP schema source. */ |
|
242 |
protected static final String JAXP_SCHEMA_SOURCE = |
|
243 |
Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE; |
|
244 |
||
245 |
/** Property identifier: JAXP schema language. */ |
|
246 |
protected static final String JAXP_SCHEMA_LANGUAGE = |
|
247 |
Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE; |
|
248 |
||
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
249 |
/** Property identifier: root type definition. */ |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
250 |
protected static final String ROOT_TYPE_DEF = |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
251 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ROOT_TYPE_DEFINITION_PROPERTY; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
252 |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
253 |
/** Property identifier: root element declaration. */ |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
254 |
protected static final String ROOT_ELEMENT_DECL = |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
255 |
Constants.XERCES_PROPERTY_PREFIX + Constants.ROOT_ELEMENT_DECLARATION_PROPERTY; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
256 |
|
12005 | 257 |
/** Property identifier: Schema DV Factory */ |
258 |
protected static final String SCHEMA_DV_FACTORY = |
|
259 |
Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY; |
|
260 |
||
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
261 |
/** Property identifier: Security property manager. */ |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
262 |
private static final String XML_SECURITY_PROPERTY_MANAGER = |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
263 |
Constants.XML_SECURITY_PROPERTY_MANAGER; |
17534 | 264 |
|
12458 | 265 |
protected static final String USE_SERVICE_MECHANISM = Constants.ORACLE_FEATURE_SERVICE_MECHANISM; |
266 |
||
12005 | 267 |
// recognized features and properties |
268 |
||
269 |
/** Recognized features. */ |
|
270 |
private static final String[] RECOGNIZED_FEATURES = |
|
271 |
{ |
|
272 |
VALIDATION, |
|
273 |
SCHEMA_VALIDATION, |
|
274 |
DYNAMIC_VALIDATION, |
|
275 |
SCHEMA_FULL_CHECKING, |
|
276 |
ALLOW_JAVA_ENCODINGS, |
|
277 |
CONTINUE_AFTER_FATAL_ERROR, |
|
278 |
STANDARD_URI_CONFORMANT_FEATURE, |
|
279 |
GENERATE_SYNTHETIC_ANNOTATIONS, |
|
280 |
VALIDATE_ANNOTATIONS, |
|
281 |
HONOUR_ALL_SCHEMALOCATIONS, |
|
282 |
USE_GRAMMAR_POOL_ONLY, |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
283 |
IGNORE_XSI_TYPE, |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
284 |
ID_IDREF_CHECKING, |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
285 |
IDENTITY_CONSTRAINT_CHECKING, |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
286 |
UNPARSED_ENTITY_CHECKING, |
12005 | 287 |
NAMESPACE_GROWTH, |
12458 | 288 |
TOLERATE_DUPLICATES, |
289 |
USE_SERVICE_MECHANISM |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
290 |
}; |
12005 | 291 |
|
292 |
/** Feature defaults. */ |
|
293 |
private static final Boolean[] FEATURE_DEFAULTS = { null, |
|
294 |
// NOTE: The following defaults are nulled out on purpose. |
|
295 |
// If they are set, then when the XML Schema validator |
|
296 |
// is constructed dynamically, these values may override |
|
297 |
// those set by the application. This goes against the |
|
298 |
// whole purpose of XMLComponent#getFeatureDefault but |
|
299 |
// it can't be helped in this case. -Ac |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
300 |
// NOTE: Instead of adding default values here, add them (and |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
301 |
// the corresponding recognized features) to the objects |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
302 |
// that have an XMLSchemaValidator instance as a member, |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
303 |
// such as the parser configurations. -PM |
12005 | 304 |
null, //Boolean.FALSE, |
305 |
null, //Boolean.FALSE, |
|
306 |
null, //Boolean.FALSE, |
|
307 |
null, //Boolean.FALSE, |
|
308 |
null, //Boolean.FALSE, |
|
309 |
null, |
|
310 |
null, |
|
311 |
null, |
|
312 |
null, |
|
313 |
null, |
|
314 |
null, |
|
12458 | 315 |
null, |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
316 |
null, |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
317 |
null, |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
318 |
null, |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
319 |
null, |
12458 | 320 |
Boolean.TRUE |
12005 | 321 |
}; |
322 |
||
323 |
/** Recognized properties. */ |
|
324 |
private static final String[] RECOGNIZED_PROPERTIES = |
|
325 |
{ |
|
326 |
SYMBOL_TABLE, |
|
327 |
ERROR_REPORTER, |
|
328 |
ENTITY_RESOLVER, |
|
329 |
VALIDATION_MANAGER, |
|
330 |
SCHEMA_LOCATION, |
|
331 |
SCHEMA_NONS_LOCATION, |
|
332 |
JAXP_SCHEMA_SOURCE, |
|
333 |
JAXP_SCHEMA_LANGUAGE, |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
334 |
ROOT_TYPE_DEF, |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
335 |
ROOT_ELEMENT_DECL, |
12005 | 336 |
SCHEMA_DV_FACTORY, |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
17534
diff
changeset
|
337 |
XML_SECURITY_PROPERTY_MANAGER |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
338 |
}; |
12005 | 339 |
|
340 |
/** Property defaults. */ |
|
341 |
private static final Object[] PROPERTY_DEFAULTS = |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
342 |
{ null, null, null, null, null, null, null, null, null, null, null, null}; |
12005 | 343 |
|
344 |
// this is the number of valuestores of each kind |
|
345 |
// we expect an element to have. It's almost |
|
346 |
// never > 1; so leave it at that. |
|
347 |
protected static final int ID_CONSTRAINT_NUM = 1; |
|
348 |
||
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
349 |
// xsi:* attribute declarations |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
350 |
static final XSAttributeDecl XSI_TYPE = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_TYPE); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
351 |
static final XSAttributeDecl XSI_NIL = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NIL); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
352 |
static final XSAttributeDecl XSI_SCHEMALOCATION = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_SCHEMALOCATION); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
353 |
static final XSAttributeDecl XSI_NONAMESPACESCHEMALOCATION = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
354 |
|
12005 | 355 |
// |
356 |
// Data |
|
357 |
// |
|
358 |
||
359 |
/** current PSVI element info */ |
|
360 |
protected ElementPSVImpl fCurrentPSVI = new ElementPSVImpl(); |
|
361 |
||
362 |
// since it is the responsibility of each component to an |
|
363 |
// Augmentations parameter if one is null, to save ourselves from |
|
364 |
// having to create this object continually, it is created here. |
|
365 |
// If it is not present in calls that we're passing on, we *must* |
|
366 |
// clear this before we introduce it into the pipeline. |
|
367 |
protected final AugmentationsImpl fAugmentations = new AugmentationsImpl(); |
|
368 |
||
369 |
// this is included for the convenience of handleEndElement |
|
370 |
protected XMLString fDefaultValue; |
|
371 |
||
372 |
// Validation features |
|
373 |
protected boolean fDynamicValidation = false; |
|
374 |
protected boolean fSchemaDynamicValidation = false; |
|
375 |
protected boolean fDoValidation = false; |
|
376 |
protected boolean fFullChecking = false; |
|
377 |
protected boolean fNormalizeData = true; |
|
378 |
protected boolean fSchemaElementDefault = true; |
|
379 |
protected boolean fAugPSVI = true; |
|
380 |
protected boolean fIdConstraint = false; |
|
381 |
protected boolean fUseGrammarPoolOnly = false; |
|
382 |
||
383 |
// Namespace growth feature |
|
384 |
protected boolean fNamespaceGrowth = false; |
|
385 |
||
386 |
/** Schema type: None, DTD, Schema */ |
|
387 |
private String fSchemaType = null; |
|
388 |
||
389 |
// to indicate whether we are in the scope of entity reference or CData |
|
390 |
protected boolean fEntityRef = false; |
|
391 |
protected boolean fInCDATA = false; |
|
392 |
||
393 |
// Did we see only whitespace in element content? |
|
394 |
protected boolean fSawOnlyWhitespaceInElementContent = false; |
|
395 |
||
396 |
// properties |
|
397 |
||
398 |
/** Symbol table. */ |
|
399 |
protected SymbolTable fSymbolTable; |
|
400 |
||
401 |
/** |
|
402 |
* While parsing a document, keep the location of the document. |
|
403 |
*/ |
|
404 |
private XMLLocator fLocator; |
|
405 |
||
406 |
/** |
|
407 |
* A wrapper of the standard error reporter. We'll store all schema errors |
|
408 |
* in this wrapper object, so that we can get all errors (error codes) of |
|
409 |
* a specific element. This is useful for PSVI. |
|
410 |
*/ |
|
411 |
protected final class XSIErrorReporter { |
|
412 |
||
413 |
// the error reporter property |
|
414 |
XMLErrorReporter fErrorReporter; |
|
415 |
||
416 |
// store error codes; starting position of the errors for each element; |
|
417 |
// number of element (depth); and whether to record error |
|
418 |
Vector fErrors = new Vector(); |
|
419 |
int[] fContext = new int[INITIAL_STACK_SIZE]; |
|
420 |
int fContextCount; |
|
421 |
||
422 |
// set the external error reporter, clear errors |
|
423 |
public void reset(XMLErrorReporter errorReporter) { |
|
424 |
fErrorReporter = errorReporter; |
|
425 |
fErrors.removeAllElements(); |
|
426 |
fContextCount = 0; |
|
427 |
} |
|
428 |
||
429 |
// should be called when starting process an element or an attribute. |
|
430 |
// store the starting position for the current context |
|
431 |
public void pushContext() { |
|
432 |
if (!fAugPSVI) { |
|
433 |
return; |
|
434 |
} |
|
435 |
// resize array if necessary |
|
436 |
if (fContextCount == fContext.length) { |
|
437 |
int newSize = fContextCount + INC_STACK_SIZE; |
|
438 |
int[] newArray = new int[newSize]; |
|
439 |
System.arraycopy(fContext, 0, newArray, 0, fContextCount); |
|
440 |
fContext = newArray; |
|
441 |
} |
|
442 |
||
443 |
fContext[fContextCount++] = fErrors.size(); |
|
444 |
} |
|
445 |
||
446 |
// should be called on endElement: get all errors of the current element |
|
447 |
public String[] popContext() { |
|
448 |
if (!fAugPSVI) { |
|
449 |
return null; |
|
450 |
} |
|
451 |
// get starting position of the current element |
|
452 |
int contextPos = fContext[--fContextCount]; |
|
453 |
// number of errors of the current element |
|
454 |
int size = fErrors.size() - contextPos; |
|
455 |
// if no errors, return null |
|
456 |
if (size == 0) |
|
457 |
return null; |
|
458 |
// copy errors from the list to an string array |
|
459 |
String[] errors = new String[size]; |
|
460 |
for (int i = 0; i < size; i++) { |
|
461 |
errors[i] = (String) fErrors.elementAt(contextPos + i); |
|
462 |
} |
|
463 |
// remove errors of the current element |
|
464 |
fErrors.setSize(contextPos); |
|
465 |
return errors; |
|
466 |
} |
|
467 |
||
468 |
// should be called when an attribute is done: get all errors of |
|
469 |
// this attribute, but leave the errors to the containing element |
|
470 |
// also called after an element was strictly assessed. |
|
471 |
public String[] mergeContext() { |
|
472 |
if (!fAugPSVI) { |
|
473 |
return null; |
|
474 |
} |
|
475 |
// get starting position of the current element |
|
476 |
int contextPos = fContext[--fContextCount]; |
|
477 |
// number of errors of the current element |
|
478 |
int size = fErrors.size() - contextPos; |
|
479 |
// if no errors, return null |
|
480 |
if (size == 0) |
|
481 |
return null; |
|
482 |
// copy errors from the list to an string array |
|
483 |
String[] errors = new String[size]; |
|
484 |
for (int i = 0; i < size; i++) { |
|
485 |
errors[i] = (String) fErrors.elementAt(contextPos + i); |
|
486 |
} |
|
487 |
// don't resize the vector: leave the errors for this attribute |
|
488 |
// to the containing element |
|
489 |
return errors; |
|
490 |
} |
|
491 |
||
492 |
public void reportError(String domain, String key, Object[] arguments, short severity) |
|
493 |
throws XNIException { |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
494 |
String message = fErrorReporter.reportError(domain, key, arguments, severity); |
12005 | 495 |
if (fAugPSVI) { |
496 |
fErrors.addElement(key); |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
497 |
fErrors.addElement(message); |
12005 | 498 |
} |
499 |
} // reportError(String,String,Object[],short) |
|
500 |
||
501 |
public void reportError( |
|
502 |
XMLLocator location, |
|
503 |
String domain, |
|
504 |
String key, |
|
505 |
Object[] arguments, |
|
506 |
short severity) |
|
507 |
throws XNIException { |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
508 |
String message = fErrorReporter.reportError(location, domain, key, arguments, severity); |
12005 | 509 |
if (fAugPSVI) { |
510 |
fErrors.addElement(key); |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
511 |
fErrors.addElement(message); |
12005 | 512 |
} |
513 |
} // reportError(XMLLocator,String,String,Object[],short) |
|
514 |
} |
|
515 |
||
516 |
/** Error reporter. */ |
|
517 |
protected final XSIErrorReporter fXSIErrorReporter = new XSIErrorReporter(); |
|
518 |
||
519 |
/** Entity resolver */ |
|
520 |
protected XMLEntityResolver fEntityResolver; |
|
521 |
||
522 |
// updated during reset |
|
523 |
protected ValidationManager fValidationManager = null; |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
524 |
protected ConfigurableValidationState fValidationState = new ConfigurableValidationState(); |
12005 | 525 |
protected XMLGrammarPool fGrammarPool; |
526 |
||
527 |
// schema location property values |
|
528 |
protected String fExternalSchemas = null; |
|
529 |
protected String fExternalNoNamespaceSchema = null; |
|
530 |
||
531 |
//JAXP Schema Source property |
|
532 |
protected Object fJaxpSchemaSource = null; |
|
533 |
||
534 |
/** Schema Grammar Description passed, to give a chance to application to supply the Grammar */ |
|
535 |
protected final XSDDescription fXSDDescription = new XSDDescription(); |
|
33349 | 536 |
protected final Map<String, XMLSchemaLoader.LocationArray> fLocationPairs = new HashMap<>(); |
12005 | 537 |
|
538 |
||
539 |
// handlers |
|
540 |
||
541 |
/** Document handler. */ |
|
542 |
protected XMLDocumentHandler fDocumentHandler; |
|
543 |
||
544 |
protected XMLDocumentSource fDocumentSource; |
|
545 |
||
546 |
boolean reportWhitespace = false; |
|
547 |
||
548 |
// |
|
549 |
// XMLComponent methods |
|
550 |
// |
|
551 |
||
552 |
/** |
|
553 |
* Returns a list of feature identifiers that are recognized by |
|
554 |
* this component. This method may return null if no features |
|
555 |
* are recognized by this component. |
|
556 |
*/ |
|
557 |
public String[] getRecognizedFeatures() { |
|
558 |
return (String[]) (RECOGNIZED_FEATURES.clone()); |
|
559 |
} // getRecognizedFeatures():String[] |
|
560 |
||
561 |
/** |
|
562 |
* Sets the state of a feature. This method is called by the component |
|
563 |
* manager any time after reset when a feature changes state. |
|
564 |
* <p> |
|
565 |
* <strong>Note:</strong> Components should silently ignore features |
|
566 |
* that do not affect the operation of the component. |
|
567 |
* |
|
568 |
* @param featureId The feature identifier. |
|
569 |
* @param state The state of the feature. |
|
570 |
* |
|
571 |
* @throws SAXNotRecognizedException The component should not throw |
|
572 |
* this exception. |
|
573 |
* @throws SAXNotSupportedException The component should not throw |
|
574 |
* this exception. |
|
575 |
*/ |
|
576 |
public void setFeature(String featureId, boolean state) throws XMLConfigurationException { |
|
577 |
} // setFeature(String,boolean) |
|
578 |
||
579 |
/** |
|
580 |
* Returns a list of property identifiers that are recognized by |
|
581 |
* this component. This method may return null if no properties |
|
582 |
* are recognized by this component. |
|
583 |
*/ |
|
584 |
public String[] getRecognizedProperties() { |
|
585 |
return (String[]) (RECOGNIZED_PROPERTIES.clone()); |
|
586 |
} // getRecognizedProperties():String[] |
|
587 |
||
588 |
/** |
|
589 |
* Sets the value of a property. This method is called by the component |
|
590 |
* manager any time after reset when a property changes value. |
|
591 |
* <p> |
|
592 |
* <strong>Note:</strong> Components should silently ignore properties |
|
593 |
* that do not affect the operation of the component. |
|
594 |
* |
|
595 |
* @param propertyId The property identifier. |
|
596 |
* @param value The value of the property. |
|
597 |
* |
|
598 |
* @throws SAXNotRecognizedException The component should not throw |
|
599 |
* this exception. |
|
600 |
* @throws SAXNotSupportedException The component should not throw |
|
601 |
* this exception. |
|
602 |
*/ |
|
603 |
public void setProperty(String propertyId, Object value) throws XMLConfigurationException { |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
604 |
if (propertyId.equals(ROOT_TYPE_DEF)) { |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
605 |
if (value == null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
606 |
fRootTypeQName = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
607 |
fRootTypeDefinition = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
608 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
609 |
else if (value instanceof javax.xml.namespace.QName) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
610 |
fRootTypeQName = (javax.xml.namespace.QName) value; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
611 |
fRootTypeDefinition = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
612 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
613 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
614 |
fRootTypeDefinition = (XSTypeDefinition) value; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
615 |
fRootTypeQName = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
616 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
617 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
618 |
else if (propertyId.equals(ROOT_ELEMENT_DECL)) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
619 |
if (value == null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
620 |
fRootElementDeclQName = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
621 |
fRootElementDeclaration = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
622 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
623 |
else if (value instanceof javax.xml.namespace.QName) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
624 |
fRootElementDeclQName = (javax.xml.namespace.QName) value; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
625 |
fRootElementDeclaration = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
626 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
627 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
628 |
fRootElementDeclaration = (XSElementDecl) value; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
629 |
fRootElementDeclQName = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
630 |
} |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
631 |
} |
12005 | 632 |
} // setProperty(String,Object) |
633 |
||
634 |
/** |
|
635 |
* Returns the default state for a feature, or null if this |
|
636 |
* component does not want to report a default value for this |
|
637 |
* feature. |
|
638 |
* |
|
639 |
* @param featureId The feature identifier. |
|
640 |
* |
|
641 |
* @since Xerces 2.2.0 |
|
642 |
*/ |
|
643 |
public Boolean getFeatureDefault(String featureId) { |
|
644 |
for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) { |
|
645 |
if (RECOGNIZED_FEATURES[i].equals(featureId)) { |
|
646 |
return FEATURE_DEFAULTS[i]; |
|
647 |
} |
|
648 |
} |
|
649 |
return null; |
|
650 |
} // getFeatureDefault(String):Boolean |
|
651 |
||
652 |
/** |
|
653 |
* Returns the default state for a property, or null if this |
|
654 |
* component does not want to report a default value for this |
|
655 |
* property. |
|
656 |
* |
|
657 |
* @param propertyId The property identifier. |
|
658 |
* |
|
659 |
* @since Xerces 2.2.0 |
|
660 |
*/ |
|
661 |
public Object getPropertyDefault(String propertyId) { |
|
662 |
for (int i = 0; i < RECOGNIZED_PROPERTIES.length; i++) { |
|
663 |
if (RECOGNIZED_PROPERTIES[i].equals(propertyId)) { |
|
664 |
return PROPERTY_DEFAULTS[i]; |
|
665 |
} |
|
666 |
} |
|
667 |
return null; |
|
668 |
} // getPropertyDefault(String):Object |
|
669 |
||
670 |
// |
|
671 |
// XMLDocumentSource methods |
|
672 |
// |
|
673 |
||
674 |
/** Sets the document handler to receive information about the document. */ |
|
675 |
public void setDocumentHandler(XMLDocumentHandler documentHandler) { |
|
676 |
fDocumentHandler = documentHandler; |
|
677 |
||
678 |
// Init reportWhitespace for this handler |
|
679 |
if (documentHandler instanceof XMLParser) { |
|
680 |
try { |
|
681 |
reportWhitespace = |
|
682 |
((XMLParser) documentHandler).getFeature(REPORT_WHITESPACE); |
|
683 |
} |
|
684 |
catch (Exception e) { |
|
685 |
reportWhitespace = false; |
|
686 |
} |
|
687 |
} |
|
688 |
} // setDocumentHandler(XMLDocumentHandler) |
|
689 |
||
690 |
/** Returns the document handler */ |
|
691 |
public XMLDocumentHandler getDocumentHandler() { |
|
692 |
return fDocumentHandler; |
|
693 |
} // setDocumentHandler(XMLDocumentHandler) |
|
694 |
||
695 |
// |
|
696 |
// XMLDocumentHandler methods |
|
697 |
// |
|
698 |
||
699 |
/** Sets the document source */ |
|
700 |
public void setDocumentSource(XMLDocumentSource source) { |
|
701 |
fDocumentSource = source; |
|
702 |
} // setDocumentSource |
|
703 |
||
704 |
/** Returns the document source */ |
|
705 |
public XMLDocumentSource getDocumentSource() { |
|
706 |
return fDocumentSource; |
|
707 |
} // getDocumentSource |
|
708 |
||
709 |
/** |
|
710 |
* The start of the document. |
|
711 |
* |
|
712 |
* @param locator The system identifier of the entity if the entity |
|
713 |
* is external, null otherwise. |
|
714 |
* @param encoding The auto-detected IANA encoding name of the entity |
|
715 |
* stream. This value will be null in those situations |
|
716 |
* where the entity encoding is not auto-detected (e.g. |
|
717 |
* internal entities or a document entity that is |
|
718 |
* parsed from a java.io.Reader). |
|
719 |
* @param namespaceContext |
|
720 |
* The namespace context in effect at the |
|
721 |
* start of this document. |
|
722 |
* This object represents the current context. |
|
723 |
* Implementors of this class are responsible |
|
724 |
* for copying the namespace bindings from the |
|
725 |
* the current context (and its parent contexts) |
|
726 |
* if that information is important. |
|
727 |
* @param augs Additional information that may include infoset augmentations |
|
728 |
* |
|
729 |
* @throws XNIException Thrown by handler to signal an error. |
|
730 |
*/ |
|
731 |
public void startDocument( |
|
732 |
XMLLocator locator, |
|
733 |
String encoding, |
|
734 |
NamespaceContext namespaceContext, |
|
735 |
Augmentations augs) |
|
736 |
throws XNIException { |
|
737 |
||
738 |
fValidationState.setNamespaceSupport(namespaceContext); |
|
739 |
fState4XsiType.setNamespaceSupport(namespaceContext); |
|
740 |
fState4ApplyDefault.setNamespaceSupport(namespaceContext); |
|
741 |
fLocator = locator; |
|
742 |
||
743 |
handleStartDocument(locator, encoding); |
|
744 |
// call handlers |
|
745 |
if (fDocumentHandler != null) { |
|
746 |
fDocumentHandler.startDocument(locator, encoding, namespaceContext, augs); |
|
747 |
} |
|
748 |
||
749 |
} // startDocument(XMLLocator,String) |
|
750 |
||
751 |
/** |
|
752 |
* Notifies of the presence of an XMLDecl line in the document. If |
|
753 |
* present, this method will be called immediately following the |
|
754 |
* startDocument call. |
|
755 |
* |
|
756 |
* @param version The XML version. |
|
757 |
* @param encoding The IANA encoding name of the document, or null if |
|
758 |
* not specified. |
|
759 |
* @param standalone The standalone value, or null if not specified. |
|
760 |
* @param augs Additional information that may include infoset augmentations |
|
761 |
* |
|
762 |
* @throws XNIException Thrown by handler to signal an error. |
|
763 |
*/ |
|
764 |
public void xmlDecl(String version, String encoding, String standalone, Augmentations augs) |
|
765 |
throws XNIException { |
|
766 |
||
767 |
// call handlers |
|
768 |
if (fDocumentHandler != null) { |
|
769 |
fDocumentHandler.xmlDecl(version, encoding, standalone, augs); |
|
770 |
} |
|
771 |
||
772 |
} // xmlDecl(String,String,String) |
|
773 |
||
774 |
/** |
|
775 |
* Notifies of the presence of the DOCTYPE line in the document. |
|
776 |
* |
|
777 |
* @param rootElement The name of the root element. |
|
778 |
* @param publicId The public identifier if an external DTD or null |
|
779 |
* if the external DTD is specified using SYSTEM. |
|
780 |
* @param systemId The system identifier if an external DTD, null |
|
781 |
* otherwise. |
|
782 |
* @param augs Additional information that may include infoset augmentations |
|
783 |
* |
|
784 |
* @throws XNIException Thrown by handler to signal an error. |
|
785 |
*/ |
|
786 |
public void doctypeDecl( |
|
787 |
String rootElement, |
|
788 |
String publicId, |
|
789 |
String systemId, |
|
790 |
Augmentations augs) |
|
791 |
throws XNIException { |
|
792 |
||
793 |
// call handlers |
|
794 |
if (fDocumentHandler != null) { |
|
795 |
fDocumentHandler.doctypeDecl(rootElement, publicId, systemId, augs); |
|
796 |
} |
|
797 |
||
798 |
} // doctypeDecl(String,String,String) |
|
799 |
||
800 |
/** |
|
801 |
* The start of an element. |
|
802 |
* |
|
803 |
* @param element The name of the element. |
|
804 |
* @param attributes The element attributes. |
|
805 |
* @param augs Additional information that may include infoset augmentations |
|
806 |
* |
|
807 |
* @throws XNIException Thrown by handler to signal an error. |
|
808 |
*/ |
|
809 |
public void startElement(QName element, XMLAttributes attributes, Augmentations augs) |
|
810 |
throws XNIException { |
|
811 |
||
812 |
Augmentations modifiedAugs = handleStartElement(element, attributes, augs); |
|
813 |
// call handlers |
|
814 |
if (fDocumentHandler != null) { |
|
815 |
fDocumentHandler.startElement(element, attributes, modifiedAugs); |
|
816 |
} |
|
817 |
||
818 |
} // startElement(QName,XMLAttributes, Augmentations) |
|
819 |
||
820 |
/** |
|
821 |
* An empty element. |
|
822 |
* |
|
823 |
* @param element The name of the element. |
|
824 |
* @param attributes The element attributes. |
|
825 |
* @param augs Additional information that may include infoset augmentations |
|
826 |
* |
|
827 |
* @throws XNIException Thrown by handler to signal an error. |
|
828 |
*/ |
|
829 |
public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) |
|
830 |
throws XNIException { |
|
831 |
||
832 |
Augmentations modifiedAugs = handleStartElement(element, attributes, augs); |
|
833 |
||
834 |
// in the case where there is a {value constraint}, and the element |
|
835 |
// doesn't have any text content, change emptyElement call to |
|
836 |
// start + characters + end |
|
837 |
fDefaultValue = null; |
|
838 |
// fElementDepth == -2 indicates that the schema validator was removed |
|
839 |
// from the pipeline. then we don't need to call handleEndElement. |
|
840 |
if (fElementDepth != -2) |
|
841 |
modifiedAugs = handleEndElement(element, modifiedAugs); |
|
842 |
||
843 |
// call handlers |
|
844 |
if (fDocumentHandler != null) { |
|
845 |
if (!fSchemaElementDefault || fDefaultValue == null) { |
|
846 |
fDocumentHandler.emptyElement(element, attributes, modifiedAugs); |
|
847 |
} else { |
|
848 |
fDocumentHandler.startElement(element, attributes, modifiedAugs); |
|
849 |
fDocumentHandler.characters(fDefaultValue, null); |
|
850 |
fDocumentHandler.endElement(element, modifiedAugs); |
|
851 |
} |
|
852 |
} |
|
853 |
} // emptyElement(QName,XMLAttributes, Augmentations) |
|
854 |
||
855 |
/** |
|
856 |
* Character content. |
|
857 |
* |
|
858 |
* @param text The content. |
|
859 |
* @param augs Additional information that may include infoset augmentations |
|
860 |
* |
|
861 |
* @throws XNIException Thrown by handler to signal an error. |
|
862 |
*/ |
|
863 |
public void characters(XMLString text, Augmentations augs) throws XNIException { |
|
864 |
text = handleCharacters(text); |
|
865 |
||
866 |
if (fSawOnlyWhitespaceInElementContent) { |
|
867 |
fSawOnlyWhitespaceInElementContent = false; |
|
868 |
if (!reportWhitespace) { |
|
869 |
ignorableWhitespace(text, augs); |
|
870 |
return; |
|
871 |
} |
|
872 |
} |
|
873 |
||
874 |
// call handlers |
|
875 |
if (fDocumentHandler != null) { |
|
876 |
if (fNormalizeData && fUnionType) { |
|
877 |
// for union types we can't normalize data |
|
878 |
// thus we only need to send augs information if any; |
|
879 |
// the normalized data for union will be send |
|
880 |
// after normalization is performed (at the endElement()) |
|
881 |
if (augs != null) |
|
882 |
fDocumentHandler.characters(fEmptyXMLStr, augs); |
|
883 |
} else { |
|
884 |
fDocumentHandler.characters(text, augs); |
|
885 |
} |
|
886 |
} |
|
887 |
||
888 |
} // characters(XMLString) |
|
889 |
||
890 |
/** |
|
891 |
* Ignorable whitespace. For this method to be called, the document |
|
892 |
* source must have some way of determining that the text containing |
|
893 |
* only whitespace characters should be considered ignorable. For |
|
894 |
* example, the validator can determine if a length of whitespace |
|
895 |
* characters in the document are ignorable based on the element |
|
896 |
* content model. |
|
897 |
* |
|
898 |
* @param text The ignorable whitespace. |
|
899 |
* @param augs Additional information that may include infoset augmentations |
|
900 |
* |
|
901 |
* @throws XNIException Thrown by handler to signal an error. |
|
902 |
*/ |
|
903 |
public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException { |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
904 |
|
12005 | 905 |
handleIgnorableWhitespace(text); |
906 |
// call handlers |
|
907 |
if (fDocumentHandler != null) { |
|
908 |
fDocumentHandler.ignorableWhitespace(text, augs); |
|
909 |
} |
|
910 |
||
911 |
} // ignorableWhitespace(XMLString) |
|
912 |
||
913 |
/** |
|
914 |
* The end of an element. |
|
915 |
* |
|
916 |
* @param element The name of the element. |
|
917 |
* @param augs Additional information that may include infoset augmentations |
|
918 |
* |
|
919 |
* @throws XNIException Thrown by handler to signal an error. |
|
920 |
*/ |
|
921 |
public void endElement(QName element, Augmentations augs) throws XNIException { |
|
922 |
||
923 |
// in the case where there is a {value constraint}, and the element |
|
924 |
// doesn't have any text content, add a characters call. |
|
925 |
fDefaultValue = null; |
|
926 |
Augmentations modifiedAugs = handleEndElement(element, augs); |
|
927 |
// call handlers |
|
928 |
if (fDocumentHandler != null) { |
|
929 |
if (!fSchemaElementDefault || fDefaultValue == null) { |
|
930 |
fDocumentHandler.endElement(element, modifiedAugs); |
|
931 |
} else { |
|
932 |
fDocumentHandler.characters(fDefaultValue, null); |
|
933 |
fDocumentHandler.endElement(element, modifiedAugs); |
|
934 |
} |
|
935 |
} |
|
936 |
} // endElement(QName, Augmentations) |
|
937 |
||
938 |
/** |
|
939 |
* The start of a CDATA section. |
|
940 |
* |
|
941 |
* @param augs Additional information that may include infoset augmentations |
|
942 |
* |
|
943 |
* @throws XNIException Thrown by handler to signal an error. |
|
944 |
*/ |
|
945 |
public void startCDATA(Augmentations augs) throws XNIException { |
|
946 |
||
947 |
// REVISIT: what should we do here if schema normalization is on?? |
|
948 |
fInCDATA = true; |
|
949 |
// call handlers |
|
950 |
if (fDocumentHandler != null) { |
|
951 |
fDocumentHandler.startCDATA(augs); |
|
952 |
} |
|
953 |
||
954 |
} // startCDATA() |
|
955 |
||
956 |
/** |
|
957 |
* The end of a CDATA section. |
|
958 |
* |
|
959 |
* @param augs Additional information that may include infoset augmentations |
|
960 |
* |
|
961 |
* @throws XNIException Thrown by handler to signal an error. |
|
962 |
*/ |
|
963 |
public void endCDATA(Augmentations augs) throws XNIException { |
|
964 |
||
965 |
// call handlers |
|
966 |
fInCDATA = false; |
|
967 |
if (fDocumentHandler != null) { |
|
968 |
fDocumentHandler.endCDATA(augs); |
|
969 |
} |
|
970 |
||
971 |
} // endCDATA() |
|
972 |
||
973 |
/** |
|
974 |
* The end of the document. |
|
975 |
* |
|
976 |
* @param augs Additional information that may include infoset augmentations |
|
977 |
* |
|
978 |
* @throws XNIException Thrown by handler to signal an error. |
|
979 |
*/ |
|
980 |
public void endDocument(Augmentations augs) throws XNIException { |
|
981 |
||
982 |
handleEndDocument(); |
|
983 |
||
984 |
// call handlers |
|
985 |
if (fDocumentHandler != null) { |
|
986 |
fDocumentHandler.endDocument(augs); |
|
987 |
} |
|
988 |
fLocator = null; |
|
989 |
||
990 |
} // endDocument(Augmentations) |
|
991 |
||
992 |
// |
|
993 |
// DOMRevalidationHandler methods |
|
994 |
// |
|
995 |
||
996 |
||
997 |
||
998 |
||
999 |
||
1000 |
public boolean characterData(String data, Augmentations augs) { |
|
1001 |
||
1002 |
fSawText = fSawText || data.length() > 0; |
|
1003 |
||
1004 |
// REVISIT: this methods basically duplicates implementation of |
|
1005 |
// handleCharacters(). We should be able to reuse some code |
|
1006 |
||
1007 |
// if whitespace == -1 skip normalization, because it is a complexType |
|
1008 |
// or a union type. |
|
1009 |
if (fNormalizeData && fWhiteSpace != -1 && fWhiteSpace != XSSimpleType.WS_PRESERVE) { |
|
1010 |
// normalize data |
|
1011 |
normalizeWhitespace(data, fWhiteSpace == XSSimpleType.WS_COLLAPSE); |
|
1012 |
fBuffer.append(fNormalizedStr.ch, fNormalizedStr.offset, fNormalizedStr.length); |
|
1013 |
} else { |
|
1014 |
if (fAppendBuffer) |
|
1015 |
fBuffer.append(data); |
|
1016 |
} |
|
1017 |
||
1018 |
// When it's a complex type with element-only content, we need to |
|
1019 |
// find out whether the content contains any non-whitespace character. |
|
1020 |
boolean allWhiteSpace = true; |
|
1021 |
if (fCurrentType != null |
|
1022 |
&& fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { |
|
1023 |
XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType; |
|
1024 |
if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT) { |
|
1025 |
// data outside of element content |
|
1026 |
for (int i = 0; i < data.length(); i++) { |
|
1027 |
if (!XMLChar.isSpace(data.charAt(i))) { |
|
1028 |
allWhiteSpace = false; |
|
1029 |
fSawCharacters = true; |
|
1030 |
break; |
|
1031 |
} |
|
1032 |
} |
|
1033 |
} |
|
1034 |
} |
|
1035 |
||
1036 |
return allWhiteSpace; |
|
1037 |
} |
|
1038 |
||
1039 |
public void elementDefault(String data) { |
|
1040 |
// no-op |
|
1041 |
} |
|
1042 |
||
1043 |
// |
|
1044 |
// XMLDocumentHandler and XMLDTDHandler methods |
|
1045 |
// |
|
1046 |
||
1047 |
/** |
|
1048 |
* This method notifies the start of a general entity. |
|
1049 |
* <p> |
|
1050 |
* <strong>Note:</strong> This method is not called for entity references |
|
1051 |
* appearing as part of attribute values. |
|
1052 |
* |
|
1053 |
* @param name The name of the general entity. |
|
1054 |
* @param identifier The resource identifier. |
|
1055 |
* @param encoding The auto-detected IANA encoding name of the entity |
|
1056 |
* stream. This value will be null in those situations |
|
1057 |
* where the entity encoding is not auto-detected (e.g. |
|
1058 |
* internal entities or a document entity that is |
|
1059 |
* parsed from a java.io.Reader). |
|
1060 |
* @param augs Additional information that may include infoset augmentations |
|
1061 |
* |
|
1062 |
* @exception XNIException Thrown by handler to signal an error. |
|
1063 |
*/ |
|
1064 |
public void startGeneralEntity( |
|
1065 |
String name, |
|
1066 |
XMLResourceIdentifier identifier, |
|
1067 |
String encoding, |
|
1068 |
Augmentations augs) |
|
1069 |
throws XNIException { |
|
1070 |
||
1071 |
// REVISIT: what should happen if normalize_data_ is on?? |
|
1072 |
fEntityRef = true; |
|
1073 |
// call handlers |
|
1074 |
if (fDocumentHandler != null) { |
|
1075 |
fDocumentHandler.startGeneralEntity(name, identifier, encoding, augs); |
|
1076 |
} |
|
1077 |
||
1078 |
} // startEntity(String,String,String,String,String) |
|
1079 |
||
1080 |
/** |
|
1081 |
* Notifies of the presence of a TextDecl line in an entity. If present, |
|
1082 |
* this method will be called immediately following the startEntity call. |
|
1083 |
* <p> |
|
1084 |
* <strong>Note:</strong> This method will never be called for the |
|
1085 |
* document entity; it is only called for external general entities |
|
1086 |
* referenced in document content. |
|
1087 |
* <p> |
|
1088 |
* <strong>Note:</strong> This method is not called for entity references |
|
1089 |
* appearing as part of attribute values. |
|
1090 |
* |
|
1091 |
* @param version The XML version, or null if not specified. |
|
1092 |
* @param encoding The IANA encoding name of the entity. |
|
1093 |
* @param augs Additional information that may include infoset augmentations |
|
1094 |
* |
|
1095 |
* @throws XNIException Thrown by handler to signal an error. |
|
1096 |
*/ |
|
1097 |
public void textDecl(String version, String encoding, Augmentations augs) throws XNIException { |
|
1098 |
||
1099 |
// call handlers |
|
1100 |
if (fDocumentHandler != null) { |
|
1101 |
fDocumentHandler.textDecl(version, encoding, augs); |
|
1102 |
} |
|
1103 |
||
1104 |
} // textDecl(String,String) |
|
1105 |
||
1106 |
/** |
|
1107 |
* A comment. |
|
1108 |
* |
|
1109 |
* @param text The text in the comment. |
|
1110 |
* @param augs Additional information that may include infoset augmentations |
|
1111 |
* |
|
1112 |
* @throws XNIException Thrown by application to signal an error. |
|
1113 |
*/ |
|
1114 |
public void comment(XMLString text, Augmentations augs) throws XNIException { |
|
1115 |
||
1116 |
// call handlers |
|
1117 |
if (fDocumentHandler != null) { |
|
1118 |
fDocumentHandler.comment(text, augs); |
|
1119 |
} |
|
1120 |
||
1121 |
} // comment(XMLString) |
|
1122 |
||
1123 |
/** |
|
1124 |
* A processing instruction. Processing instructions consist of a |
|
1125 |
* target name and, optionally, text data. The data is only meaningful |
|
1126 |
* to the application. |
|
1127 |
* <p> |
|
1128 |
* Typically, a processing instruction's data will contain a series |
|
1129 |
* of pseudo-attributes. These pseudo-attributes follow the form of |
|
1130 |
* element attributes but are <strong>not</strong> parsed or presented |
|
1131 |
* to the application as anything other than text. The application is |
|
1132 |
* responsible for parsing the data. |
|
1133 |
* |
|
1134 |
* @param target The target. |
|
1135 |
* @param data The data or null if none specified. |
|
1136 |
* @param augs Additional information that may include infoset augmentations |
|
1137 |
* |
|
1138 |
* @throws XNIException Thrown by handler to signal an error. |
|
1139 |
*/ |
|
1140 |
public void processingInstruction(String target, XMLString data, Augmentations augs) |
|
1141 |
throws XNIException { |
|
1142 |
||
1143 |
// call handlers |
|
1144 |
if (fDocumentHandler != null) { |
|
1145 |
fDocumentHandler.processingInstruction(target, data, augs); |
|
1146 |
} |
|
1147 |
||
1148 |
} // processingInstruction(String,XMLString) |
|
1149 |
||
1150 |
/** |
|
1151 |
* This method notifies the end of a general entity. |
|
1152 |
* <p> |
|
1153 |
* <strong>Note:</strong> This method is not called for entity references |
|
1154 |
* appearing as part of attribute values. |
|
1155 |
* |
|
1156 |
* @param name The name of the entity. |
|
1157 |
* @param augs Additional information that may include infoset augmentations |
|
1158 |
* |
|
1159 |
* @exception XNIException |
|
1160 |
* Thrown by handler to signal an error. |
|
1161 |
*/ |
|
1162 |
public void endGeneralEntity(String name, Augmentations augs) throws XNIException { |
|
1163 |
||
1164 |
// call handlers |
|
1165 |
fEntityRef = false; |
|
1166 |
if (fDocumentHandler != null) { |
|
1167 |
fDocumentHandler.endGeneralEntity(name, augs); |
|
1168 |
} |
|
1169 |
||
1170 |
} // endEntity(String) |
|
1171 |
||
1172 |
// constants |
|
1173 |
||
1174 |
static final int INITIAL_STACK_SIZE = 8; |
|
1175 |
static final int INC_STACK_SIZE = 8; |
|
1176 |
||
1177 |
// |
|
1178 |
// Data |
|
1179 |
// |
|
1180 |
||
1181 |
// Schema Normalization |
|
1182 |
||
1183 |
private static final boolean DEBUG_NORMALIZATION = false; |
|
1184 |
// temporary empty string buffer. |
|
1185 |
private final XMLString fEmptyXMLStr = new XMLString(null, 0, -1); |
|
1186 |
// temporary character buffer, and empty string buffer. |
|
1187 |
private static final int BUFFER_SIZE = 20; |
|
1188 |
private final XMLString fNormalizedStr = new XMLString(); |
|
1189 |
private boolean fFirstChunk = true; |
|
1190 |
// got first chunk in characters() (SAX) |
|
1191 |
private boolean fTrailing = false; // Previous chunk had a trailing space |
|
1192 |
private short fWhiteSpace = -1; //whiteSpace: preserve/replace/collapse |
|
1193 |
private boolean fUnionType = false; |
|
1194 |
||
1195 |
/** Schema grammar resolver. */ |
|
1196 |
private final XSGrammarBucket fGrammarBucket = new XSGrammarBucket(); |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1197 |
private final SubstitutionGroupHandler fSubGroupHandler = new SubstitutionGroupHandler(this); |
12005 | 1198 |
|
1199 |
/** the DV usd to convert xsi:type to a QName */ |
|
1200 |
// REVISIT: in new simple type design, make things in DVs static, |
|
1201 |
// so that we can QNameDV.getCompiledForm() |
|
1202 |
private final XSSimpleType fQNameDV = |
|
1203 |
(XSSimpleType) SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_QNAME); |
|
1204 |
||
1205 |
private final CMNodeFactory nodeFactory = new CMNodeFactory(); |
|
1206 |
/** used to build content models */ |
|
1207 |
// REVISIT: create decl pool, and pass it to each traversers |
|
1208 |
private final CMBuilder fCMBuilder = new CMBuilder(nodeFactory); |
|
1209 |
||
1210 |
// Schema grammar loader |
|
1211 |
private final XMLSchemaLoader fSchemaLoader = |
|
1212 |
new XMLSchemaLoader( |
|
1213 |
fXSIErrorReporter.fErrorReporter, |
|
1214 |
fGrammarBucket, |
|
1215 |
fSubGroupHandler, |
|
1216 |
fCMBuilder); |
|
1217 |
||
1218 |
// state |
|
1219 |
||
1220 |
/** String representation of the validation root. */ |
|
1221 |
// REVISIT: what do we store here? QName, XPATH, some ID? use rawname now. |
|
1222 |
private String fValidationRoot; |
|
1223 |
||
1224 |
/** Skip validation: anything below this level should be skipped */ |
|
1225 |
private int fSkipValidationDepth; |
|
1226 |
||
1227 |
/** anything above this level has validation_attempted != full */ |
|
1228 |
private int fNFullValidationDepth; |
|
1229 |
||
1230 |
/** anything above this level has validation_attempted != none */ |
|
1231 |
private int fNNoneValidationDepth; |
|
1232 |
||
1233 |
/** Element depth: -2: validator not in pipeline; >= -1 current depth. */ |
|
1234 |
private int fElementDepth; |
|
1235 |
||
1236 |
/** Seen sub elements. */ |
|
1237 |
private boolean fSubElement; |
|
1238 |
||
1239 |
/** Seen sub elements stack. */ |
|
1240 |
private boolean[] fSubElementStack = new boolean[INITIAL_STACK_SIZE]; |
|
1241 |
||
1242 |
/** Current element declaration. */ |
|
1243 |
private XSElementDecl fCurrentElemDecl; |
|
1244 |
||
1245 |
/** Element decl stack. */ |
|
1246 |
private XSElementDecl[] fElemDeclStack = new XSElementDecl[INITIAL_STACK_SIZE]; |
|
1247 |
||
1248 |
/** nil value of the current element */ |
|
1249 |
private boolean fNil; |
|
1250 |
||
1251 |
/** nil value stack */ |
|
1252 |
private boolean[] fNilStack = new boolean[INITIAL_STACK_SIZE]; |
|
1253 |
||
1254 |
/** notation value of the current element */ |
|
1255 |
private XSNotationDecl fNotation; |
|
1256 |
||
1257 |
/** notation stack */ |
|
1258 |
private XSNotationDecl[] fNotationStack = new XSNotationDecl[INITIAL_STACK_SIZE]; |
|
1259 |
||
1260 |
/** Current type. */ |
|
1261 |
private XSTypeDefinition fCurrentType; |
|
1262 |
||
1263 |
/** type stack. */ |
|
1264 |
private XSTypeDefinition[] fTypeStack = new XSTypeDefinition[INITIAL_STACK_SIZE]; |
|
1265 |
||
1266 |
/** Current content model. */ |
|
1267 |
private XSCMValidator fCurrentCM; |
|
1268 |
||
1269 |
/** Content model stack. */ |
|
1270 |
private XSCMValidator[] fCMStack = new XSCMValidator[INITIAL_STACK_SIZE]; |
|
1271 |
||
1272 |
/** the current state of the current content model */ |
|
1273 |
private int[] fCurrCMState; |
|
1274 |
||
1275 |
/** stack to hold content model states */ |
|
1276 |
private int[][] fCMStateStack = new int[INITIAL_STACK_SIZE][]; |
|
1277 |
||
1278 |
/** whether the curret element is strictly assessed */ |
|
1279 |
private boolean fStrictAssess = true; |
|
1280 |
||
1281 |
/** strict assess stack */ |
|
1282 |
private boolean[] fStrictAssessStack = new boolean[INITIAL_STACK_SIZE]; |
|
1283 |
||
1284 |
/** Temporary string buffers. */ |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1285 |
private final StringBuilder fBuffer = new StringBuilder(); |
12005 | 1286 |
|
1287 |
/** Whether need to append characters to fBuffer */ |
|
1288 |
private boolean fAppendBuffer = true; |
|
1289 |
||
1290 |
/** Did we see any character data? */ |
|
1291 |
private boolean fSawText = false; |
|
1292 |
||
1293 |
/** stack to record if we saw character data */ |
|
1294 |
private boolean[] fSawTextStack = new boolean[INITIAL_STACK_SIZE]; |
|
1295 |
||
1296 |
/** Did we see non-whitespace character data? */ |
|
1297 |
private boolean fSawCharacters = false; |
|
1298 |
||
1299 |
/** Stack to record if we saw character data outside of element content*/ |
|
1300 |
private boolean[] fStringContent = new boolean[INITIAL_STACK_SIZE]; |
|
1301 |
||
1302 |
/** temporary qname */ |
|
1303 |
private final QName fTempQName = new QName(); |
|
1304 |
||
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1305 |
/** value of the "root-type-definition" property. */ |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1306 |
private javax.xml.namespace.QName fRootTypeQName = null; |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1307 |
private XSTypeDefinition fRootTypeDefinition = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1308 |
|
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1309 |
/** value of the "root-element-declaration" property. */ |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1310 |
private javax.xml.namespace.QName fRootElementDeclQName = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1311 |
private XSElementDecl fRootElementDeclaration = null; |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1312 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1313 |
private int fIgnoreXSITypeDepth; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1314 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1315 |
private boolean fIDCChecking; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1316 |
|
12005 | 1317 |
/** temporary validated info */ |
1318 |
private ValidatedInfo fValidatedInfo = new ValidatedInfo(); |
|
1319 |
||
1320 |
// used to validate default/fixed values against xsi:type |
|
1321 |
// only need to check facets, so we set extraChecking to false (in reset) |
|
1322 |
private ValidationState fState4XsiType = new ValidationState(); |
|
1323 |
||
1324 |
// used to apply default/fixed values |
|
1325 |
// only need to check id/idref/entity, so we set checkFacets to false |
|
1326 |
private ValidationState fState4ApplyDefault = new ValidationState(); |
|
1327 |
||
1328 |
// identity constraint information |
|
1329 |
||
1330 |
/** |
|
1331 |
* Stack of active XPath matchers for identity constraints. All |
|
1332 |
* active XPath matchers are notified of startElement |
|
1333 |
* and endElement callbacks in order to perform their matches. |
|
1334 |
* <p> |
|
1335 |
* For each element with identity constraints, the selector of |
|
1336 |
* each identity constraint is activated. When the selector matches |
|
1337 |
* its XPath, then all the fields of the identity constraint are |
|
1338 |
* activated. |
|
1339 |
* <p> |
|
1340 |
* <strong>Note:</strong> Once the activation scope is left, the |
|
1341 |
* XPath matchers are automatically removed from the stack of |
|
1342 |
* active matchers and no longer receive callbacks. |
|
1343 |
*/ |
|
1344 |
protected XPathMatcherStack fMatcherStack = new XPathMatcherStack(); |
|
1345 |
||
1346 |
/** Cache of value stores for identity constraint fields. */ |
|
1347 |
protected ValueStoreCache fValueStoreCache = new ValueStoreCache(); |
|
1348 |
||
1349 |
// |
|
1350 |
// Constructors |
|
1351 |
// |
|
1352 |
||
1353 |
/** Default constructor. */ |
|
1354 |
public XMLSchemaValidator() { |
|
1355 |
fState4XsiType.setExtraChecking(false); |
|
1356 |
fState4ApplyDefault.setFacetChecking(false); |
|
1357 |
||
1358 |
} // <init>() |
|
1359 |
||
1360 |
/* |
|
1361 |
* Resets the component. The component can query the component manager |
|
1362 |
* about any features and properties that affect the operation of the |
|
1363 |
* component. |
|
1364 |
* |
|
1365 |
* @param componentManager The component manager. |
|
1366 |
* |
|
1367 |
* @throws SAXException Thrown by component on finitialization error. |
|
1368 |
* For example, if a feature or property is |
|
1369 |
* required for the operation of the component, the |
|
1370 |
* component manager may throw a |
|
1371 |
* SAXNotRecognizedException or a |
|
1372 |
* SAXNotSupportedException. |
|
1373 |
*/ |
|
1374 |
public void reset(XMLComponentManager componentManager) throws XMLConfigurationException { |
|
1375 |
||
1376 |
||
1377 |
fIdConstraint = false; |
|
1378 |
//reset XSDDescription |
|
1379 |
fLocationPairs.clear(); |
|
1380 |
||
1381 |
// cleanup id table |
|
1382 |
fValidationState.resetIDTables(); |
|
1383 |
||
1384 |
// reset schema loader |
|
1385 |
fSchemaLoader.reset(componentManager); |
|
1386 |
||
1387 |
// initialize state |
|
1388 |
fCurrentElemDecl = null; |
|
1389 |
fCurrentCM = null; |
|
1390 |
fCurrCMState = null; |
|
1391 |
fSkipValidationDepth = -1; |
|
1392 |
fNFullValidationDepth = -1; |
|
1393 |
fNNoneValidationDepth = -1; |
|
1394 |
fElementDepth = -1; |
|
1395 |
fSubElement = false; |
|
1396 |
fSchemaDynamicValidation = false; |
|
1397 |
||
1398 |
// datatype normalization |
|
1399 |
fEntityRef = false; |
|
1400 |
fInCDATA = false; |
|
1401 |
||
1402 |
fMatcherStack.clear(); |
|
1403 |
||
1404 |
// get error reporter |
|
1405 |
fXSIErrorReporter.reset((XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER)); |
|
1406 |
||
1407 |
boolean parser_settings = componentManager.getFeature(PARSER_SETTINGS, true); |
|
1408 |
||
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1409 |
if (!parser_settings) { |
12005 | 1410 |
// parser settings have not been changed |
1411 |
fValidationManager.addValidationState(fValidationState); |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1412 |
// the node limit on the SecurityManager may have changed so need to refresh. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1413 |
nodeFactory.reset(); |
12005 | 1414 |
// Re-parse external schema location properties. |
1415 |
XMLSchemaLoader.processExternalHints( |
|
1416 |
fExternalSchemas, |
|
1417 |
fExternalNoNamespaceSchema, |
|
1418 |
fLocationPairs, |
|
1419 |
fXSIErrorReporter.fErrorReporter); |
|
1420 |
return; |
|
1421 |
} |
|
1422 |
||
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1423 |
// pass the component manager to the factory.. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1424 |
nodeFactory.reset(componentManager); |
12005 | 1425 |
|
1426 |
// get symbol table. if it's a new one, add symbols to it. |
|
1427 |
SymbolTable symbolTable = (SymbolTable) componentManager.getProperty(SYMBOL_TABLE); |
|
1428 |
if (symbolTable != fSymbolTable) { |
|
1429 |
fSymbolTable = symbolTable; |
|
1430 |
} |
|
1431 |
||
1432 |
fNamespaceGrowth = componentManager.getFeature(NAMESPACE_GROWTH, false); |
|
1433 |
fDynamicValidation = componentManager.getFeature(DYNAMIC_VALIDATION, false); |
|
1434 |
||
1435 |
if (fDynamicValidation) { |
|
1436 |
fDoValidation = true; |
|
1437 |
} else { |
|
1438 |
fDoValidation = componentManager.getFeature(VALIDATION, false); |
|
1439 |
} |
|
1440 |
||
1441 |
if (fDoValidation) { |
|
1442 |
fDoValidation |= componentManager.getFeature(XMLSchemaValidator.SCHEMA_VALIDATION, false); |
|
1443 |
} |
|
1444 |
||
1445 |
fFullChecking = componentManager.getFeature(SCHEMA_FULL_CHECKING, false); |
|
1446 |
fNormalizeData = componentManager.getFeature(NORMALIZE_DATA, false); |
|
1447 |
fSchemaElementDefault = componentManager.getFeature(SCHEMA_ELEMENT_DEFAULT, false); |
|
1448 |
||
1449 |
fAugPSVI = componentManager.getFeature(SCHEMA_AUGMENT_PSVI, true); |
|
1450 |
||
1451 |
fSchemaType = |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1452 |
(String) componentManager.getProperty( |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1453 |
Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, null); |
12005 | 1454 |
|
1455 |
fUseGrammarPoolOnly = componentManager.getFeature(USE_GRAMMAR_POOL_ONLY, false); |
|
1456 |
||
1457 |
fEntityResolver = (XMLEntityResolver) componentManager.getProperty(ENTITY_MANAGER); |
|
1458 |
||
1459 |
fValidationManager = (ValidationManager) componentManager.getProperty(VALIDATION_MANAGER); |
|
1460 |
fValidationManager.addValidationState(fValidationState); |
|
1461 |
fValidationState.setSymbolTable(fSymbolTable); |
|
1462 |
||
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1463 |
try { |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1464 |
final Object rootType = componentManager.getProperty(ROOT_TYPE_DEF); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1465 |
if (rootType == null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1466 |
fRootTypeQName = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1467 |
fRootTypeDefinition = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1468 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1469 |
else if (rootType instanceof javax.xml.namespace.QName) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1470 |
fRootTypeQName = (javax.xml.namespace.QName) rootType; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1471 |
fRootTypeDefinition = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1472 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1473 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1474 |
fRootTypeDefinition = (XSTypeDefinition) rootType; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1475 |
fRootTypeQName = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1476 |
} |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1477 |
} |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1478 |
catch (XMLConfigurationException e) { |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1479 |
fRootTypeQName = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1480 |
fRootTypeDefinition = null; |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1481 |
} |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1482 |
|
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1483 |
try { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1484 |
final Object rootDecl = componentManager.getProperty(ROOT_ELEMENT_DECL); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1485 |
if (rootDecl == null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1486 |
fRootElementDeclQName = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1487 |
fRootElementDeclaration = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1488 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1489 |
else if (rootDecl instanceof javax.xml.namespace.QName) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1490 |
fRootElementDeclQName = (javax.xml.namespace.QName) rootDecl; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1491 |
fRootElementDeclaration = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1492 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1493 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1494 |
fRootElementDeclaration = (XSElementDecl) rootDecl; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1495 |
fRootElementDeclQName = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1496 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1497 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1498 |
catch (XMLConfigurationException e) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1499 |
fRootElementDeclQName = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1500 |
fRootElementDeclaration = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1501 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1502 |
|
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1503 |
boolean ignoreXSIType = componentManager.getFeature(IGNORE_XSI_TYPE, false); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1504 |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1505 |
// An initial value of -1 means that the root element considers itself |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1506 |
// below the depth where xsi:type stopped being ignored (which means that |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1507 |
// xsi:type attributes will not be ignored for the entire document) |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1508 |
fIgnoreXSITypeDepth = ignoreXSIType ? 0 : -1; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1509 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1510 |
try { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1511 |
fIDCChecking = componentManager.getFeature(IDENTITY_CONSTRAINT_CHECKING); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1512 |
} |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1513 |
catch (XMLConfigurationException e) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1514 |
fIDCChecking = true; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1515 |
} |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1516 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1517 |
try { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1518 |
fValidationState.setIdIdrefChecking(componentManager.getFeature(ID_IDREF_CHECKING)); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1519 |
} |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1520 |
catch (XMLConfigurationException e) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1521 |
fValidationState.setIdIdrefChecking(true); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1522 |
} |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1523 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1524 |
try { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1525 |
fValidationState.setUnparsedEntityChecking(componentManager.getFeature(UNPARSED_ENTITY_CHECKING)); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1526 |
} |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1527 |
catch (XMLConfigurationException e) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1528 |
fValidationState.setUnparsedEntityChecking(true); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1529 |
} |
12005 | 1530 |
|
1531 |
// get schema location properties |
|
1532 |
try { |
|
1533 |
fExternalSchemas = (String) componentManager.getProperty(SCHEMA_LOCATION); |
|
1534 |
fExternalNoNamespaceSchema = |
|
1535 |
(String) componentManager.getProperty(SCHEMA_NONS_LOCATION); |
|
1536 |
} catch (XMLConfigurationException e) { |
|
1537 |
fExternalSchemas = null; |
|
1538 |
fExternalNoNamespaceSchema = null; |
|
1539 |
} |
|
1540 |
||
1541 |
// store the external schema locations. they are set when reset is called, |
|
1542 |
// so any other schemaLocation declaration for the same namespace will be |
|
1543 |
// effectively ignored. becuase we choose to take first location hint |
|
1544 |
// available for a particular namespace. |
|
1545 |
XMLSchemaLoader.processExternalHints( |
|
1546 |
fExternalSchemas, |
|
1547 |
fExternalNoNamespaceSchema, |
|
1548 |
fLocationPairs, |
|
1549 |
fXSIErrorReporter.fErrorReporter); |
|
1550 |
||
1551 |
fJaxpSchemaSource = componentManager.getProperty(JAXP_SCHEMA_SOURCE, null); |
|
1552 |
||
1553 |
// clear grammars, and put the one for schema namespace there |
|
1554 |
fGrammarPool = (XMLGrammarPool) componentManager.getProperty(XMLGRAMMAR_POOL, null); |
|
1555 |
||
1556 |
fState4XsiType.setSymbolTable(symbolTable); |
|
1557 |
fState4ApplyDefault.setSymbolTable(symbolTable); |
|
1558 |
||
1559 |
} // reset(XMLComponentManager) |
|
1560 |
||
1561 |
// |
|
1562 |
// FieldActivator methods |
|
1563 |
// |
|
1564 |
||
1565 |
/** |
|
1566 |
* Start the value scope for the specified identity constraint. This |
|
1567 |
* method is called when the selector matches in order to initialize |
|
1568 |
* the value store. |
|
1569 |
* |
|
1570 |
* @param identityConstraint The identity constraint. |
|
1571 |
*/ |
|
1572 |
public void startValueScopeFor(IdentityConstraint identityConstraint, int initialDepth) { |
|
1573 |
||
1574 |
ValueStoreBase valueStore = |
|
1575 |
fValueStoreCache.getValueStoreFor(identityConstraint, initialDepth); |
|
1576 |
valueStore.startValueScope(); |
|
1577 |
||
1578 |
} // startValueScopeFor(IdentityConstraint identityConstraint) |
|
1579 |
||
1580 |
/** |
|
1581 |
* Request to activate the specified field. This method returns the |
|
1582 |
* matcher for the field. |
|
1583 |
* |
|
1584 |
* @param field The field to activate. |
|
1585 |
*/ |
|
1586 |
public XPathMatcher activateField(Field field, int initialDepth) { |
|
1587 |
ValueStore valueStore = |
|
1588 |
fValueStoreCache.getValueStoreFor(field.getIdentityConstraint(), initialDepth); |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1589 |
XPathMatcher matcher = field.createMatcher(valueStore); |
12005 | 1590 |
fMatcherStack.addMatcher(matcher); |
1591 |
matcher.startDocumentFragment(); |
|
1592 |
return matcher; |
|
1593 |
} // activateField(Field):XPathMatcher |
|
1594 |
||
1595 |
/** |
|
1596 |
* Ends the value scope for the specified identity constraint. |
|
1597 |
* |
|
1598 |
* @param identityConstraint The identity constraint. |
|
1599 |
*/ |
|
1600 |
public void endValueScopeFor(IdentityConstraint identityConstraint, int initialDepth) { |
|
1601 |
||
1602 |
ValueStoreBase valueStore = |
|
1603 |
fValueStoreCache.getValueStoreFor(identityConstraint, initialDepth); |
|
1604 |
valueStore.endValueScope(); |
|
1605 |
||
1606 |
} // endValueScopeFor(IdentityConstraint) |
|
1607 |
||
1608 |
// a utility method for Identity constraints |
|
1609 |
private void activateSelectorFor(IdentityConstraint ic) { |
|
1610 |
Selector selector = ic.getSelector(); |
|
1611 |
FieldActivator activator = this; |
|
1612 |
if (selector == null) |
|
1613 |
return; |
|
1614 |
XPathMatcher matcher = selector.createMatcher(activator, fElementDepth); |
|
1615 |
fMatcherStack.addMatcher(matcher); |
|
1616 |
matcher.startDocumentFragment(); |
|
1617 |
} |
|
1618 |
||
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1619 |
// Implements XSElementDeclHelper interface |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1620 |
public XSElementDecl getGlobalElementDecl(QName element) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1621 |
final SchemaGrammar sGrammar = |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1622 |
findSchemaGrammar( |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1623 |
XSDDescription.CONTEXT_ELEMENT, |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1624 |
element.uri, |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1625 |
null, |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1626 |
element, |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1627 |
null); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1628 |
if (sGrammar != null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1629 |
return sGrammar.getGlobalElementDecl(element.localpart); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1630 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1631 |
return null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1632 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1633 |
|
12005 | 1634 |
// |
1635 |
// Protected methods |
|
1636 |
// |
|
1637 |
||
1638 |
/** ensure element stack capacity */ |
|
1639 |
void ensureStackCapacity() { |
|
1640 |
||
1641 |
if (fElementDepth == fElemDeclStack.length) { |
|
1642 |
int newSize = fElementDepth + INC_STACK_SIZE; |
|
1643 |
boolean[] newArrayB = new boolean[newSize]; |
|
1644 |
System.arraycopy(fSubElementStack, 0, newArrayB, 0, fElementDepth); |
|
1645 |
fSubElementStack = newArrayB; |
|
1646 |
||
1647 |
XSElementDecl[] newArrayE = new XSElementDecl[newSize]; |
|
1648 |
System.arraycopy(fElemDeclStack, 0, newArrayE, 0, fElementDepth); |
|
1649 |
fElemDeclStack = newArrayE; |
|
1650 |
||
1651 |
newArrayB = new boolean[newSize]; |
|
1652 |
System.arraycopy(fNilStack, 0, newArrayB, 0, fElementDepth); |
|
1653 |
fNilStack = newArrayB; |
|
1654 |
||
1655 |
XSNotationDecl[] newArrayN = new XSNotationDecl[newSize]; |
|
1656 |
System.arraycopy(fNotationStack, 0, newArrayN, 0, fElementDepth); |
|
1657 |
fNotationStack = newArrayN; |
|
1658 |
||
1659 |
XSTypeDefinition[] newArrayT = new XSTypeDefinition[newSize]; |
|
1660 |
System.arraycopy(fTypeStack, 0, newArrayT, 0, fElementDepth); |
|
1661 |
fTypeStack = newArrayT; |
|
1662 |
||
1663 |
XSCMValidator[] newArrayC = new XSCMValidator[newSize]; |
|
1664 |
System.arraycopy(fCMStack, 0, newArrayC, 0, fElementDepth); |
|
1665 |
fCMStack = newArrayC; |
|
1666 |
||
1667 |
newArrayB = new boolean[newSize]; |
|
1668 |
System.arraycopy(fSawTextStack, 0, newArrayB, 0, fElementDepth); |
|
1669 |
fSawTextStack = newArrayB; |
|
1670 |
||
1671 |
newArrayB = new boolean[newSize]; |
|
1672 |
System.arraycopy(fStringContent, 0, newArrayB, 0, fElementDepth); |
|
1673 |
fStringContent = newArrayB; |
|
1674 |
||
1675 |
newArrayB = new boolean[newSize]; |
|
1676 |
System.arraycopy(fStrictAssessStack, 0, newArrayB, 0, fElementDepth); |
|
1677 |
fStrictAssessStack = newArrayB; |
|
1678 |
||
1679 |
int[][] newArrayIA = new int[newSize][]; |
|
1680 |
System.arraycopy(fCMStateStack, 0, newArrayIA, 0, fElementDepth); |
|
1681 |
fCMStateStack = newArrayIA; |
|
1682 |
} |
|
1683 |
||
1684 |
} // ensureStackCapacity |
|
1685 |
||
1686 |
// handle start document |
|
1687 |
void handleStartDocument(XMLLocator locator, String encoding) { |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1688 |
if (fIDCChecking) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1689 |
fValueStoreCache.startDocument(); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1690 |
} |
12005 | 1691 |
if (fAugPSVI) { |
1692 |
fCurrentPSVI.fGrammars = null; |
|
1693 |
fCurrentPSVI.fSchemaInformation = null; |
|
1694 |
} |
|
1695 |
} // handleStartDocument(XMLLocator,String) |
|
1696 |
||
1697 |
void handleEndDocument() { |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1698 |
if (fIDCChecking) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1699 |
fValueStoreCache.endDocument(); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
1700 |
} |
12005 | 1701 |
} // handleEndDocument() |
1702 |
||
1703 |
// handle character contents |
|
1704 |
// returns the normalized string if possible, otherwise the original string |
|
1705 |
XMLString handleCharacters(XMLString text) { |
|
1706 |
||
1707 |
if (fSkipValidationDepth >= 0) |
|
1708 |
return text; |
|
1709 |
||
1710 |
fSawText = fSawText || text.length > 0; |
|
1711 |
||
1712 |
// Note: data in EntityRef and CDATA is normalized as well |
|
1713 |
// if whitespace == -1 skip normalization, because it is a complexType |
|
1714 |
// or a union type. |
|
1715 |
if (fNormalizeData && fWhiteSpace != -1 && fWhiteSpace != XSSimpleType.WS_PRESERVE) { |
|
1716 |
// normalize data |
|
1717 |
normalizeWhitespace(text, fWhiteSpace == XSSimpleType.WS_COLLAPSE); |
|
1718 |
text = fNormalizedStr; |
|
1719 |
} |
|
1720 |
if (fAppendBuffer) |
|
1721 |
fBuffer.append(text.ch, text.offset, text.length); |
|
1722 |
||
1723 |
// When it's a complex type with element-only content, we need to |
|
1724 |
// find out whether the content contains any non-whitespace character. |
|
1725 |
fSawOnlyWhitespaceInElementContent = false; |
|
1726 |
if (fCurrentType != null |
|
1727 |
&& fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { |
|
1728 |
XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType; |
|
1729 |
if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT) { |
|
1730 |
// data outside of element content |
|
1731 |
for (int i = text.offset; i < text.offset + text.length; i++) { |
|
1732 |
if (!XMLChar.isSpace(text.ch[i])) { |
|
1733 |
fSawCharacters = true; |
|
1734 |
break; |
|
1735 |
} |
|
1736 |
fSawOnlyWhitespaceInElementContent = !fSawCharacters; |
|
1737 |
} |
|
1738 |
} |
|
1739 |
} |
|
1740 |
||
1741 |
return text; |
|
1742 |
} // handleCharacters(XMLString) |
|
1743 |
||
1744 |
/** |
|
1745 |
* Normalize whitespace in an XMLString according to the rules defined |
|
1746 |
* in XML Schema specifications. |
|
1747 |
* @param value The string to normalize. |
|
1748 |
* @param collapse replace or collapse |
|
1749 |
*/ |
|
1750 |
private void normalizeWhitespace(XMLString value, boolean collapse) { |
|
1751 |
boolean skipSpace = collapse; |
|
1752 |
boolean sawNonWS = false; |
|
1753 |
boolean leading = false; |
|
1754 |
boolean trailing = false; |
|
1755 |
char c; |
|
1756 |
int size = value.offset + value.length; |
|
1757 |
||
1758 |
// ensure the ch array is big enough |
|
1759 |
if (fNormalizedStr.ch == null || fNormalizedStr.ch.length < value.length + 1) { |
|
1760 |
fNormalizedStr.ch = new char[value.length + 1]; |
|
1761 |
} |
|
1762 |
// don't include the leading ' ' for now. might include it later. |
|
1763 |
fNormalizedStr.offset = 1; |
|
1764 |
fNormalizedStr.length = 1; |
|
1765 |
||
1766 |
for (int i = value.offset; i < size; i++) { |
|
1767 |
c = value.ch[i]; |
|
1768 |
if (XMLChar.isSpace(c)) { |
|
1769 |
if (!skipSpace) { |
|
1770 |
// take the first whitespace as a space and skip the others |
|
1771 |
fNormalizedStr.ch[fNormalizedStr.length++] = ' '; |
|
1772 |
skipSpace = collapse; |
|
1773 |
} |
|
1774 |
if (!sawNonWS) { |
|
1775 |
// this is a leading whitespace, record it |
|
1776 |
leading = true; |
|
1777 |
} |
|
1778 |
} else { |
|
1779 |
fNormalizedStr.ch[fNormalizedStr.length++] = c; |
|
1780 |
skipSpace = false; |
|
1781 |
sawNonWS = true; |
|
1782 |
} |
|
1783 |
} |
|
1784 |
if (skipSpace) { |
|
1785 |
if (fNormalizedStr.length > 1) { |
|
1786 |
// if we finished on a space trim it but also record it |
|
1787 |
fNormalizedStr.length--; |
|
1788 |
trailing = true; |
|
1789 |
} else if (leading && !fFirstChunk) { |
|
1790 |
// if all we had was whitespace we skipped record it as |
|
1791 |
// trailing whitespace as well |
|
1792 |
trailing = true; |
|
1793 |
} |
|
1794 |
} |
|
1795 |
||
1796 |
if (fNormalizedStr.length > 1) { |
|
1797 |
if (!fFirstChunk && (fWhiteSpace == XSSimpleType.WS_COLLAPSE)) { |
|
1798 |
if (fTrailing) { |
|
1799 |
// previous chunk ended on whitespace |
|
1800 |
// insert whitespace |
|
1801 |
fNormalizedStr.offset = 0; |
|
1802 |
fNormalizedStr.ch[0] = ' '; |
|
1803 |
} else if (leading) { |
|
1804 |
// previous chunk ended on character, |
|
1805 |
// this chunk starts with whitespace |
|
1806 |
fNormalizedStr.offset = 0; |
|
1807 |
fNormalizedStr.ch[0] = ' '; |
|
1808 |
} |
|
1809 |
} |
|
1810 |
} |
|
1811 |
||
1812 |
// The length includes the leading ' '. Now removing it. |
|
1813 |
fNormalizedStr.length -= fNormalizedStr.offset; |
|
1814 |
||
1815 |
fTrailing = trailing; |
|
1816 |
||
1817 |
if (trailing || sawNonWS) |
|
1818 |
fFirstChunk = false; |
|
1819 |
} |
|
1820 |
||
1821 |
private void normalizeWhitespace(String value, boolean collapse) { |
|
1822 |
boolean skipSpace = collapse; |
|
1823 |
char c; |
|
1824 |
int size = value.length(); |
|
1825 |
||
1826 |
// ensure the ch array is big enough |
|
1827 |
if (fNormalizedStr.ch == null || fNormalizedStr.ch.length < size) { |
|
1828 |
fNormalizedStr.ch = new char[size]; |
|
1829 |
} |
|
1830 |
fNormalizedStr.offset = 0; |
|
1831 |
fNormalizedStr.length = 0; |
|
1832 |
||
1833 |
for (int i = 0; i < size; i++) { |
|
1834 |
c = value.charAt(i); |
|
1835 |
if (XMLChar.isSpace(c)) { |
|
1836 |
if (!skipSpace) { |
|
1837 |
// take the first whitespace as a space and skip the others |
|
1838 |
fNormalizedStr.ch[fNormalizedStr.length++] = ' '; |
|
1839 |
skipSpace = collapse; |
|
1840 |
} |
|
1841 |
} else { |
|
1842 |
fNormalizedStr.ch[fNormalizedStr.length++] = c; |
|
1843 |
skipSpace = false; |
|
1844 |
} |
|
1845 |
} |
|
1846 |
if (skipSpace) { |
|
1847 |
if (fNormalizedStr.length != 0) |
|
1848 |
// if we finished on a space trim it but also record it |
|
1849 |
fNormalizedStr.length--; |
|
1850 |
} |
|
1851 |
} |
|
1852 |
||
1853 |
// handle ignorable whitespace |
|
1854 |
void handleIgnorableWhitespace(XMLString text) { |
|
1855 |
||
1856 |
if (fSkipValidationDepth >= 0) |
|
1857 |
return; |
|
1858 |
||
1859 |
// REVISIT: the same process needs to be performed as handleCharacters. |
|
1860 |
// only it's simpler here: we know all characters are whitespaces. |
|
1861 |
||
1862 |
} // handleIgnorableWhitespace(XMLString) |
|
1863 |
||
1864 |
/** Handle element. */ |
|
1865 |
Augmentations handleStartElement(QName element, XMLAttributes attributes, Augmentations augs) { |
|
1866 |
||
1867 |
if (DEBUG) { |
|
1868 |
System.out.println("==>handleStartElement: " + element); |
|
1869 |
} |
|
1870 |
||
1871 |
// root element |
|
1872 |
if (fElementDepth == -1 && fValidationManager.isGrammarFound()) { |
|
1873 |
if (fSchemaType == null) { |
|
1874 |
// schemaType is not specified |
|
1875 |
// if a DTD grammar is found, we do the same thing as Dynamic: |
|
1876 |
// if a schema grammar is found, validation is performed; |
|
1877 |
// otherwise, skip the whole document. |
|
1878 |
fSchemaDynamicValidation = true; |
|
1879 |
} else { |
|
1880 |
// [1] Either schemaType is DTD, and in this case validate/schema is turned off |
|
1881 |
// [2] Validating against XML Schemas only |
|
1882 |
// [a] dynamic validation is false: report error if SchemaGrammar is not found |
|
1883 |
// [b] dynamic validation is true: if grammar is not found ignore. |
|
1884 |
} |
|
1885 |
||
1886 |
} |
|
1887 |
||
1888 |
// get xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes, |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1889 |
// parse them to get the grammars. But only do this if the grammar can grow. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1890 |
if (!fUseGrammarPoolOnly) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1891 |
String sLocation = |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1892 |
attributes.getValue(SchemaSymbols.URI_XSI, SchemaSymbols.XSI_SCHEMALOCATION); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1893 |
String nsLocation = |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1894 |
attributes.getValue(SchemaSymbols.URI_XSI, SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1895 |
//store the location hints.. we need to do it so that we can defer the loading of grammar until |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1896 |
//there is a reference to a component from that namespace. To provide location hints to the |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1897 |
//application for a namespace |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1898 |
storeLocations(sLocation, nsLocation); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1899 |
} |
12005 | 1900 |
|
1901 |
// if we are in the content of "skip", then just skip this element |
|
1902 |
// REVISIT: is this the correct behaviour for ID constraints? -NG |
|
1903 |
if (fSkipValidationDepth >= 0) { |
|
1904 |
fElementDepth++; |
|
1905 |
if (fAugPSVI) |
|
1906 |
augs = getEmptyAugs(augs); |
|
1907 |
return augs; |
|
1908 |
} |
|
1909 |
||
1910 |
// if we are not skipping this element, and there is a content model, |
|
1911 |
// we try to find the corresponding decl object for this element. |
|
1912 |
// the reason we move this part of code here is to make sure the |
|
1913 |
// error reported here (if any) is stored within the parent element's |
|
1914 |
// context, instead of that of the current element. |
|
1915 |
Object decl = null; |
|
1916 |
if (fCurrentCM != null) { |
|
1917 |
decl = fCurrentCM.oneTransition(element, fCurrCMState, fSubGroupHandler); |
|
1918 |
// it could be an element decl or a wildcard decl |
|
1919 |
if (fCurrCMState[0] == XSCMValidator.FIRST_ERROR) { |
|
1920 |
XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType; |
|
1921 |
//REVISIT: is it the only case we will have particle = null? |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1922 |
ArrayList next; |
12005 | 1923 |
if (ctype.fParticle != null |
1924 |
&& (next = fCurrentCM.whatCanGoHere(fCurrCMState)).size() > 0) { |
|
1925 |
String expected = expectedStr(next); |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1926 |
final int[] occurenceInfo = fCurrentCM.occurenceInfo(fCurrCMState); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1927 |
String elemExpandedQname = (element.uri != null) ? "{"+'"'+element.uri+'"'+":"+element.localpart+"}" : element.localpart; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1928 |
if (occurenceInfo != null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1929 |
final int minOccurs = occurenceInfo[0]; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1930 |
final int maxOccurs = occurenceInfo[1]; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1931 |
final int count = occurenceInfo[2]; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1932 |
// Check if this is a violation of minOccurs |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1933 |
if (count < minOccurs) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1934 |
final int required = minOccurs - count; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1935 |
if (required > 1) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1936 |
reportSchemaError("cvc-complex-type.2.4.h", new Object[] { element.rawname, |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1937 |
fCurrentCM.getTermName(occurenceInfo[3]), Integer.toString(minOccurs), Integer.toString(required) }); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1938 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1939 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1940 |
reportSchemaError("cvc-complex-type.2.4.g", new Object[] { element.rawname, |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1941 |
fCurrentCM.getTermName(occurenceInfo[3]), Integer.toString(minOccurs) }); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1942 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1943 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1944 |
// Check if this is a violation of maxOccurs |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1945 |
else if (count >= maxOccurs && maxOccurs != SchemaSymbols.OCCURRENCE_UNBOUNDED) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1946 |
reportSchemaError("cvc-complex-type.2.4.e", new Object[] { element.rawname, |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1947 |
expected, Integer.toString(maxOccurs) }); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1948 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1949 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1950 |
reportSchemaError("cvc-complex-type.2.4.a", new Object[] { elemExpandedQname, expected }); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1951 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1952 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1953 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1954 |
reportSchemaError("cvc-complex-type.2.4.a", new Object[] { elemExpandedQname, expected }); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1955 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1956 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1957 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1958 |
final int[] occurenceInfo = fCurrentCM.occurenceInfo(fCurrCMState); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1959 |
if (occurenceInfo != null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1960 |
final int maxOccurs = occurenceInfo[1]; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1961 |
final int count = occurenceInfo[2]; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1962 |
// Check if this is a violation of maxOccurs |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1963 |
if (count >= maxOccurs && maxOccurs != SchemaSymbols.OCCURRENCE_UNBOUNDED) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1964 |
reportSchemaError("cvc-complex-type.2.4.f", new Object[] { fCurrentCM.getTermName(occurenceInfo[3]), Integer.toString(maxOccurs) }); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1965 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1966 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1967 |
reportSchemaError("cvc-complex-type.2.4.d", new Object[] { element.rawname }); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1968 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1969 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1970 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1971 |
reportSchemaError("cvc-complex-type.2.4.d", new Object[] { element.rawname }); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
1972 |
} |
12005 | 1973 |
} |
1974 |
} |
|
1975 |
} |
|
1976 |
||
1977 |
// if it's not the root element, we push the current states in the stacks |
|
1978 |
if (fElementDepth != -1) { |
|
1979 |
ensureStackCapacity(); |
|
1980 |
fSubElementStack[fElementDepth] = true; |
|
1981 |
fSubElement = false; |
|
1982 |
fElemDeclStack[fElementDepth] = fCurrentElemDecl; |
|
1983 |
fNilStack[fElementDepth] = fNil; |
|
1984 |
fNotationStack[fElementDepth] = fNotation; |
|
1985 |
fTypeStack[fElementDepth] = fCurrentType; |
|
1986 |
fStrictAssessStack[fElementDepth] = fStrictAssess; |
|
1987 |
fCMStack[fElementDepth] = fCurrentCM; |
|
1988 |
fCMStateStack[fElementDepth] = fCurrCMState; |
|
1989 |
fSawTextStack[fElementDepth] = fSawText; |
|
1990 |
fStringContent[fElementDepth] = fSawCharacters; |
|
1991 |
} |
|
1992 |
||
1993 |
// increase the element depth after we've saved |
|
1994 |
// all states for the parent element |
|
1995 |
fElementDepth++; |
|
1996 |
fCurrentElemDecl = null; |
|
1997 |
XSWildcardDecl wildcard = null; |
|
1998 |
fCurrentType = null; |
|
1999 |
fStrictAssess = true; |
|
2000 |
fNil = false; |
|
2001 |
fNotation = null; |
|
2002 |
||
2003 |
// and the buffer to hold the value of the element |
|
2004 |
fBuffer.setLength(0); |
|
2005 |
fSawText = false; |
|
2006 |
fSawCharacters = false; |
|
2007 |
||
2008 |
// check what kind of declaration the "decl" from |
|
2009 |
// oneTransition() maps to |
|
2010 |
if (decl != null) { |
|
2011 |
if (decl instanceof XSElementDecl) { |
|
2012 |
fCurrentElemDecl = (XSElementDecl) decl; |
|
2013 |
} else { |
|
2014 |
wildcard = (XSWildcardDecl) decl; |
|
2015 |
} |
|
2016 |
} |
|
2017 |
||
2018 |
// if the wildcard is skip, then return |
|
2019 |
if (wildcard != null && wildcard.fProcessContents == XSWildcardDecl.PC_SKIP) { |
|
2020 |
fSkipValidationDepth = fElementDepth; |
|
2021 |
if (fAugPSVI) |
|
2022 |
augs = getEmptyAugs(augs); |
|
2023 |
return augs; |
|
2024 |
} |
|
2025 |
||
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2026 |
if (fElementDepth == 0) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2027 |
// 1.1.1.1 An element declaration was stipulated by the processor |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2028 |
if (fRootElementDeclaration != null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2029 |
fCurrentElemDecl = fRootElementDeclaration; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2030 |
checkElementMatchesRootElementDecl(fCurrentElemDecl, element); |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2031 |
} |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2032 |
else if (fRootElementDeclQName != null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2033 |
processRootElementDeclQName(fRootElementDeclQName, element); |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2034 |
} |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2035 |
// 1.2.1.1 A type definition was stipulated by the processor |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2036 |
else if (fRootTypeDefinition != null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2037 |
fCurrentType = fRootTypeDefinition; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2038 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2039 |
else if (fRootTypeQName != null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2040 |
processRootTypeQName(fRootTypeQName); |
12005 | 2041 |
} |
2042 |
} |
|
2043 |
||
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2044 |
// if there was no processor stipulated type |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2045 |
if (fCurrentType == null) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2046 |
// try again to get the element decl: |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2047 |
// case 1: find declaration for root element |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2048 |
// case 2: find declaration for element from another namespace |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2049 |
if (fCurrentElemDecl == null) { |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2050 |
// try to find schema grammar by different means.. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2051 |
SchemaGrammar sGrammar = |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2052 |
findSchemaGrammar( |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2053 |
XSDDescription.CONTEXT_ELEMENT, |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2054 |
element.uri, |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2055 |
null, |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2056 |
element, |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2057 |
attributes); |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2058 |
if (sGrammar != null) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2059 |
fCurrentElemDecl = sGrammar.getGlobalElementDecl(element.localpart); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2060 |
} |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2061 |
} |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2062 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2063 |
if (fCurrentElemDecl != null) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2064 |
// then get the type |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2065 |
fCurrentType = fCurrentElemDecl.fType; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2066 |
} |
12005 | 2067 |
} |
2068 |
||
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2069 |
// check if we should be ignoring xsi:type on this element |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2070 |
if (fElementDepth == fIgnoreXSITypeDepth && fCurrentElemDecl == null) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2071 |
fIgnoreXSITypeDepth++; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2072 |
} |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2073 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2074 |
// process xsi:type attribute information |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2075 |
String xsiType = null; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2076 |
if (fElementDepth >= fIgnoreXSITypeDepth) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2077 |
xsiType = attributes.getValue(SchemaSymbols.URI_XSI, SchemaSymbols.XSI_TYPE); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2078 |
} |
12005 | 2079 |
|
2080 |
// if no decl/type found for the current element |
|
2081 |
if (fCurrentType == null && xsiType == null) { |
|
2082 |
// if this is the validation root, report an error, because |
|
2083 |
// we can't find eith decl or type for this element |
|
2084 |
// REVISIT: should we report error, or warning? |
|
2085 |
if (fElementDepth == 0) { |
|
2086 |
// for dynamic validation, skip the whole content, |
|
2087 |
// because no grammar was found. |
|
2088 |
if (fDynamicValidation || fSchemaDynamicValidation) { |
|
2089 |
// no schema grammar was found, but it's either dynamic |
|
2090 |
// validation, or another kind of grammar was found (DTD, |
|
2091 |
// for example). The intended behavior here is to skip |
|
2092 |
// the whole document. To improve performance, we try to |
|
2093 |
// remove the validator from the pipeline, since it's not |
|
2094 |
// supposed to do anything. |
|
2095 |
if (fDocumentSource != null) { |
|
2096 |
fDocumentSource.setDocumentHandler(fDocumentHandler); |
|
2097 |
if (fDocumentHandler != null) |
|
2098 |
fDocumentHandler.setDocumentSource(fDocumentSource); |
|
2099 |
// indicate that the validator was removed. |
|
2100 |
fElementDepth = -2; |
|
2101 |
return augs; |
|
2102 |
} |
|
2103 |
||
2104 |
fSkipValidationDepth = fElementDepth; |
|
2105 |
if (fAugPSVI) |
|
2106 |
augs = getEmptyAugs(augs); |
|
2107 |
return augs; |
|
2108 |
} |
|
2109 |
// We don't call reportSchemaError here, because the spec |
|
2110 |
// doesn't think it's invalid not to be able to find a |
|
2111 |
// declaration or type definition for an element. Xerces is |
|
2112 |
// reporting it as an error for historical reasons, but in |
|
2113 |
// PSVI, we shouldn't mark this element as invalid because |
|
2114 |
// of this. - SG |
|
2115 |
fXSIErrorReporter.fErrorReporter.reportError( |
|
2116 |
XSMessageFormatter.SCHEMA_DOMAIN, |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2117 |
"cvc-elt.1.a", |
12005 | 2118 |
new Object[] { element.rawname }, |
2119 |
XMLErrorReporter.SEVERITY_ERROR); |
|
2120 |
} |
|
2121 |
// if wildcard = strict, report error. |
|
2122 |
// needs to be called before fXSIErrorReporter.pushContext() |
|
2123 |
// so that the error belongs to the parent element. |
|
2124 |
else if (wildcard != null && wildcard.fProcessContents == XSWildcardDecl.PC_STRICT) { |
|
2125 |
// report error, because wilcard = strict |
|
2126 |
reportSchemaError("cvc-complex-type.2.4.c", new Object[] { element.rawname }); |
|
2127 |
} |
|
2128 |
// no element decl or type found for this element. |
|
2129 |
// Allowed by the spec, we can choose to either laxly assess this |
|
2130 |
// element, or to skip it. Now we choose lax assessment. |
|
2131 |
fCurrentType = SchemaGrammar.fAnyType; |
|
2132 |
fStrictAssess = false; |
|
2133 |
fNFullValidationDepth = fElementDepth; |
|
2134 |
// any type has mixed content, so we don't need to append buffer |
|
2135 |
fAppendBuffer = false; |
|
2136 |
||
2137 |
// push error reporter context: record the current position |
|
2138 |
// This has to happen after we process skip contents, |
|
2139 |
// otherwise push and pop won't be correctly paired. |
|
2140 |
fXSIErrorReporter.pushContext(); |
|
2141 |
} else { |
|
2142 |
// push error reporter context: record the current position |
|
2143 |
// This has to happen after we process skip contents, |
|
2144 |
// otherwise push and pop won't be correctly paired. |
|
2145 |
fXSIErrorReporter.pushContext(); |
|
2146 |
||
2147 |
// get xsi:type |
|
2148 |
if (xsiType != null) { |
|
2149 |
XSTypeDefinition oldType = fCurrentType; |
|
2150 |
fCurrentType = getAndCheckXsiType(element, xsiType, attributes); |
|
2151 |
// If it fails, use the old type. Use anyType if ther is no old type. |
|
2152 |
if (fCurrentType == null) { |
|
2153 |
if (oldType == null) |
|
2154 |
fCurrentType = SchemaGrammar.fAnyType; |
|
2155 |
else |
|
2156 |
fCurrentType = oldType; |
|
2157 |
} |
|
2158 |
} |
|
2159 |
||
2160 |
fNNoneValidationDepth = fElementDepth; |
|
2161 |
// if the element has a fixed value constraint, we need to append |
|
2162 |
if (fCurrentElemDecl != null |
|
2163 |
&& fCurrentElemDecl.getConstraintType() == XSConstants.VC_FIXED) { |
|
2164 |
fAppendBuffer = true; |
|
2165 |
} |
|
2166 |
// if the type is simple, we need to append |
|
2167 |
else if (fCurrentType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { |
|
2168 |
fAppendBuffer = true; |
|
2169 |
} else { |
|
2170 |
// if the type is simple content complex type, we need to append |
|
2171 |
XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType; |
|
2172 |
fAppendBuffer = (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_SIMPLE); |
|
2173 |
} |
|
2174 |
} |
|
2175 |
||
2176 |
// Element Locally Valid (Element) |
|
2177 |
// 2 Its {abstract} must be false. |
|
2178 |
if (fCurrentElemDecl != null && fCurrentElemDecl.getAbstract()) |
|
2179 |
reportSchemaError("cvc-elt.2", new Object[] { element.rawname }); |
|
2180 |
||
2181 |
// make the current element validation root |
|
2182 |
if (fElementDepth == 0) { |
|
2183 |
fValidationRoot = element.rawname; |
|
2184 |
} |
|
2185 |
||
2186 |
// update normalization flags |
|
2187 |
if (fNormalizeData) { |
|
2188 |
// reset values |
|
2189 |
fFirstChunk = true; |
|
2190 |
fTrailing = false; |
|
2191 |
fUnionType = false; |
|
2192 |
fWhiteSpace = -1; |
|
2193 |
} |
|
2194 |
||
2195 |
// Element Locally Valid (Type) |
|
2196 |
// 2 Its {abstract} must be false. |
|
2197 |
if (fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { |
|
2198 |
XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType; |
|
2199 |
if (ctype.getAbstract()) { |
|
2200 |
reportSchemaError("cvc-type.2", new Object[] { element.rawname }); |
|
2201 |
} |
|
2202 |
if (fNormalizeData) { |
|
2203 |
// find out if the content type is simple and if variety is union |
|
2204 |
// to be able to do character normalization |
|
2205 |
if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_SIMPLE) { |
|
2206 |
if (ctype.fXSSimpleType.getVariety() == XSSimpleType.VARIETY_UNION) { |
|
2207 |
fUnionType = true; |
|
2208 |
} else { |
|
2209 |
try { |
|
2210 |
fWhiteSpace = ctype.fXSSimpleType.getWhitespace(); |
|
2211 |
} catch (DatatypeException e) { |
|
2212 |
// do nothing |
|
2213 |
} |
|
2214 |
} |
|
2215 |
} |
|
2216 |
} |
|
2217 |
} |
|
2218 |
// normalization: simple type |
|
2219 |
else if (fNormalizeData) { |
|
2220 |
// if !union type |
|
2221 |
XSSimpleType dv = (XSSimpleType) fCurrentType; |
|
2222 |
if (dv.getVariety() == XSSimpleType.VARIETY_UNION) { |
|
2223 |
fUnionType = true; |
|
2224 |
} else { |
|
2225 |
try { |
|
2226 |
fWhiteSpace = dv.getWhitespace(); |
|
2227 |
} catch (DatatypeException e) { |
|
2228 |
// do nothing |
|
2229 |
} |
|
2230 |
} |
|
2231 |
} |
|
2232 |
||
2233 |
// then try to get the content model |
|
2234 |
fCurrentCM = null; |
|
2235 |
if (fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { |
|
2236 |
fCurrentCM = ((XSComplexTypeDecl) fCurrentType).getContentModel(fCMBuilder); |
|
2237 |
} |
|
2238 |
||
2239 |
// and get the initial content model state |
|
2240 |
fCurrCMState = null; |
|
2241 |
if (fCurrentCM != null) |
|
2242 |
fCurrCMState = fCurrentCM.startContentModel(); |
|
2243 |
||
2244 |
// get information about xsi:nil |
|
2245 |
String xsiNil = attributes.getValue(SchemaSymbols.URI_XSI, SchemaSymbols.XSI_NIL); |
|
2246 |
// only deal with xsi:nil when there is an element declaration |
|
2247 |
if (xsiNil != null && fCurrentElemDecl != null) |
|
2248 |
fNil = getXsiNil(element, xsiNil); |
|
2249 |
||
2250 |
// now validate everything related with the attributes |
|
2251 |
// first, get the attribute group |
|
2252 |
XSAttributeGroupDecl attrGrp = null; |
|
2253 |
if (fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { |
|
2254 |
XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType; |
|
2255 |
attrGrp = ctype.getAttrGrp(); |
|
2256 |
} |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2257 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2258 |
if (fIDCChecking) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2259 |
// activate identity constraints |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2260 |
fValueStoreCache.startElement(); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2261 |
fMatcherStack.pushContext(); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2262 |
//if (fCurrentElemDecl != null && fCurrentElemDecl.fIDCPos > 0 && !fIgnoreIDC) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2263 |
if (fCurrentElemDecl != null && fCurrentElemDecl.fIDCPos > 0) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2264 |
fIdConstraint = true; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2265 |
// initialize when identity constrains are defined for the elem |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2266 |
fValueStoreCache.initValueStoresFor(fCurrentElemDecl, this); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2267 |
} |
12005 | 2268 |
} |
2269 |
processAttributes(element, attributes, attrGrp); |
|
2270 |
||
2271 |
// add default attributes |
|
2272 |
if (attrGrp != null) { |
|
2273 |
addDefaultAttributes(element, attributes, attrGrp); |
|
2274 |
} |
|
2275 |
||
2276 |
// call all active identity constraints |
|
2277 |
int count = fMatcherStack.getMatcherCount(); |
|
2278 |
for (int i = 0; i < count; i++) { |
|
2279 |
XPathMatcher matcher = fMatcherStack.getMatcherAt(i); |
|
2280 |
matcher.startElement( element, attributes); |
|
2281 |
} |
|
2282 |
||
2283 |
if (fAugPSVI) { |
|
2284 |
augs = getEmptyAugs(augs); |
|
2285 |
||
2286 |
// PSVI: add validation context |
|
2287 |
fCurrentPSVI.fValidationContext = fValidationRoot; |
|
2288 |
// PSVI: add element declaration |
|
2289 |
fCurrentPSVI.fDeclaration = fCurrentElemDecl; |
|
2290 |
// PSVI: add element type |
|
2291 |
fCurrentPSVI.fTypeDecl = fCurrentType; |
|
2292 |
// PSVI: add notation attribute |
|
2293 |
fCurrentPSVI.fNotation = fNotation; |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2294 |
// PSVI: add nil |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2295 |
fCurrentPSVI.fNil = fNil; |
12005 | 2296 |
} |
2297 |
||
2298 |
return augs; |
|
2299 |
||
2300 |
} // handleStartElement(QName,XMLAttributes,boolean) |
|
2301 |
||
2302 |
/** |
|
2303 |
* Handle end element. If there is not text content, and there is a |
|
2304 |
* {value constraint} on the corresponding element decl, then |
|
2305 |
* set the fDefaultValue XMLString representing the default value. |
|
2306 |
*/ |
|
2307 |
Augmentations handleEndElement(QName element, Augmentations augs) { |
|
2308 |
||
2309 |
if (DEBUG) { |
|
2310 |
System.out.println("==>handleEndElement:" + element); |
|
2311 |
} |
|
2312 |
// if we are skipping, return |
|
2313 |
if (fSkipValidationDepth >= 0) { |
|
2314 |
// but if this is the top element that we are skipping, |
|
2315 |
// restore the states. |
|
2316 |
if (fSkipValidationDepth == fElementDepth && fSkipValidationDepth > 0) { |
|
2317 |
// set the partial validation depth to the depth of parent |
|
2318 |
fNFullValidationDepth = fSkipValidationDepth - 1; |
|
2319 |
fSkipValidationDepth = -1; |
|
2320 |
fElementDepth--; |
|
2321 |
fSubElement = fSubElementStack[fElementDepth]; |
|
2322 |
fCurrentElemDecl = fElemDeclStack[fElementDepth]; |
|
2323 |
fNil = fNilStack[fElementDepth]; |
|
2324 |
fNotation = fNotationStack[fElementDepth]; |
|
2325 |
fCurrentType = fTypeStack[fElementDepth]; |
|
2326 |
fCurrentCM = fCMStack[fElementDepth]; |
|
2327 |
fStrictAssess = fStrictAssessStack[fElementDepth]; |
|
2328 |
fCurrCMState = fCMStateStack[fElementDepth]; |
|
2329 |
fSawText = fSawTextStack[fElementDepth]; |
|
2330 |
fSawCharacters = fStringContent[fElementDepth]; |
|
2331 |
} |
|
2332 |
else { |
|
2333 |
fElementDepth--; |
|
2334 |
} |
|
2335 |
||
2336 |
// PSVI: validation attempted: |
|
2337 |
// use default values in psvi item for |
|
2338 |
// validation attempted, validity, and error codes |
|
2339 |
||
2340 |
// check extra schema constraints on root element |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2341 |
if (fElementDepth == -1 && fFullChecking && !fUseGrammarPoolOnly) { |
12005 | 2342 |
XSConstraints.fullSchemaChecking( |
2343 |
fGrammarBucket, |
|
2344 |
fSubGroupHandler, |
|
2345 |
fCMBuilder, |
|
2346 |
fXSIErrorReporter.fErrorReporter); |
|
2347 |
} |
|
2348 |
||
2349 |
if (fAugPSVI) |
|
2350 |
augs = getEmptyAugs(augs); |
|
2351 |
return augs; |
|
2352 |
} |
|
2353 |
||
2354 |
// now validate the content of the element |
|
2355 |
processElementContent(element); |
|
2356 |
||
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2357 |
if (fIDCChecking) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2358 |
// Element Locally Valid (Element) |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2359 |
// 6 The element information item must be valid with respect to each of the {identity-constraint definitions} as per Identity-constraint Satisfied (3.11.4). |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2360 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2361 |
// call matchers and de-activate context |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2362 |
int oldCount = fMatcherStack.getMatcherCount(); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2363 |
for (int i = oldCount - 1; i >= 0; i--) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2364 |
XPathMatcher matcher = fMatcherStack.getMatcherAt(i); |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2365 |
if (fCurrentElemDecl == null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2366 |
matcher.endElement(element, fCurrentType, false, fValidatedInfo.actualValue, fValidatedInfo.actualValueType, fValidatedInfo.itemValueTypes); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2367 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2368 |
else { |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2369 |
matcher.endElement( |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2370 |
element, |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2371 |
fCurrentType, |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2372 |
fCurrentElemDecl.getNillable(), |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2373 |
fDefaultValue == null |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2374 |
? fValidatedInfo.actualValue |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2375 |
: fCurrentElemDecl.fDefault.actualValue, |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2376 |
fDefaultValue == null |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2377 |
? fValidatedInfo.actualValueType |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2378 |
: fCurrentElemDecl.fDefault.actualValueType, |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2379 |
fDefaultValue == null |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2380 |
? fValidatedInfo.itemValueTypes |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2381 |
: fCurrentElemDecl.fDefault.itemValueTypes); |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2382 |
} |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2383 |
} |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2384 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2385 |
if (fMatcherStack.size() > 0) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2386 |
fMatcherStack.popContext(); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2387 |
} |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2388 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2389 |
int newCount = fMatcherStack.getMatcherCount(); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2390 |
// handle everything *but* keyref's. |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2391 |
for (int i = oldCount - 1; i >= newCount; i--) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2392 |
XPathMatcher matcher = fMatcherStack.getMatcherAt(i); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2393 |
if (matcher instanceof Selector.Matcher) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2394 |
Selector.Matcher selMatcher = (Selector.Matcher) matcher; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2395 |
IdentityConstraint id; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2396 |
if ((id = selMatcher.getIdentityConstraint()) != null |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2397 |
&& id.getCategory() != IdentityConstraint.IC_KEYREF) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2398 |
fValueStoreCache.transplant(id, selMatcher.getInitialDepth()); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2399 |
} |
12005 | 2400 |
} |
2401 |
} |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2402 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2403 |
// now handle keyref's/... |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2404 |
for (int i = oldCount - 1; i >= newCount; i--) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2405 |
XPathMatcher matcher = fMatcherStack.getMatcherAt(i); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2406 |
if (matcher instanceof Selector.Matcher) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2407 |
Selector.Matcher selMatcher = (Selector.Matcher) matcher; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2408 |
IdentityConstraint id; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2409 |
if ((id = selMatcher.getIdentityConstraint()) != null |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2410 |
&& id.getCategory() == IdentityConstraint.IC_KEYREF) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2411 |
ValueStoreBase values = |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2412 |
fValueStoreCache.getValueStoreFor(id, selMatcher.getInitialDepth()); |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2413 |
// nothing to do if nothing matched, or if not all |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2414 |
// fields are present. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2415 |
if (values != null && values.fValuesCount == values.fFieldCount) |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2416 |
values.endDocumentFragment(); |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2417 |
} |
12005 | 2418 |
} |
2419 |
} |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2420 |
fValueStoreCache.endElement(); |
12005 | 2421 |
} |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2422 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2423 |
// Check if we should modify the xsi:type ignore depth |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2424 |
// This check is independent of whether this is the validation root, |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2425 |
// and should be done before the element depth is decremented. |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2426 |
if (fElementDepth < fIgnoreXSITypeDepth) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2427 |
fIgnoreXSITypeDepth--; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2428 |
} |
12005 | 2429 |
|
2430 |
SchemaGrammar[] grammars = null; |
|
2431 |
// have we reached the end tag of the validation root? |
|
2432 |
if (fElementDepth == 0) { |
|
2433 |
// 7 If the element information item is the validation root, it must be valid per Validation Root Valid (ID/IDREF) (3.3.4). |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2434 |
Iterator invIdRefs = fValidationState.checkIDRefID(); |
12005 | 2435 |
fValidationState.resetIDTables(); |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2436 |
if (invIdRefs != null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2437 |
while (invIdRefs.hasNext()) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2438 |
reportSchemaError("cvc-id.1", new Object[] { invIdRefs.next() }); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2439 |
} |
12005 | 2440 |
} |
2441 |
// check extra schema constraints |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2442 |
if (fFullChecking && !fUseGrammarPoolOnly) { |
12005 | 2443 |
XSConstraints.fullSchemaChecking( |
2444 |
fGrammarBucket, |
|
2445 |
fSubGroupHandler, |
|
2446 |
fCMBuilder, |
|
2447 |
fXSIErrorReporter.fErrorReporter); |
|
2448 |
} |
|
2449 |
||
2450 |
grammars = fGrammarBucket.getGrammars(); |
|
2451 |
// return the final set of grammars validator ended up with |
|
2452 |
if (fGrammarPool != null) { |
|
2453 |
// Set grammars as immutable |
|
2454 |
for (int k=0; k < grammars.length; k++) { |
|
2455 |
grammars[k].setImmutable(true); |
|
2456 |
} |
|
2457 |
fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_SCHEMA, grammars); |
|
2458 |
} |
|
2459 |
augs = endElementPSVI(true, grammars, augs); |
|
2460 |
} else { |
|
2461 |
augs = endElementPSVI(false, grammars, augs); |
|
2462 |
||
2463 |
// decrease element depth and restore states |
|
2464 |
fElementDepth--; |
|
2465 |
||
2466 |
// get the states for the parent element. |
|
2467 |
fSubElement = fSubElementStack[fElementDepth]; |
|
2468 |
fCurrentElemDecl = fElemDeclStack[fElementDepth]; |
|
2469 |
fNil = fNilStack[fElementDepth]; |
|
2470 |
fNotation = fNotationStack[fElementDepth]; |
|
2471 |
fCurrentType = fTypeStack[fElementDepth]; |
|
2472 |
fCurrentCM = fCMStack[fElementDepth]; |
|
2473 |
fStrictAssess = fStrictAssessStack[fElementDepth]; |
|
2474 |
fCurrCMState = fCMStateStack[fElementDepth]; |
|
2475 |
fSawText = fSawTextStack[fElementDepth]; |
|
2476 |
fSawCharacters = fStringContent[fElementDepth]; |
|
2477 |
||
2478 |
// We should have a stack for whitespace value, and pop it up here. |
|
2479 |
// But when fWhiteSpace != -1, and we see a sub-element, it must be |
|
2480 |
// an error (at least for Schema 1.0). So for valid documents, the |
|
2481 |
// only value we are going to push/pop in the stack is -1. |
|
2482 |
// Here we just mimic the effect of popping -1. -SG |
|
2483 |
fWhiteSpace = -1; |
|
2484 |
// Same for append buffer. Simple types and elements with fixed |
|
2485 |
// value constraint don't allow sub-elements. -SG |
|
2486 |
fAppendBuffer = false; |
|
2487 |
// same here. |
|
2488 |
fUnionType = false; |
|
2489 |
} |
|
2490 |
||
2491 |
return augs; |
|
2492 |
} // handleEndElement(QName,boolean)*/ |
|
2493 |
||
2494 |
final Augmentations endElementPSVI( |
|
2495 |
boolean root, |
|
2496 |
SchemaGrammar[] grammars, |
|
2497 |
Augmentations augs) { |
|
2498 |
||
2499 |
if (fAugPSVI) { |
|
2500 |
augs = getEmptyAugs(augs); |
|
2501 |
||
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2502 |
// the 5 properties sent on startElement calls |
12005 | 2503 |
fCurrentPSVI.fDeclaration = this.fCurrentElemDecl; |
2504 |
fCurrentPSVI.fTypeDecl = this.fCurrentType; |
|
2505 |
fCurrentPSVI.fNotation = this.fNotation; |
|
2506 |
fCurrentPSVI.fValidationContext = this.fValidationRoot; |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2507 |
fCurrentPSVI.fNil = this.fNil; |
12005 | 2508 |
// PSVI: validation attempted |
2509 |
// nothing below or at the same level has none or partial |
|
2510 |
// (which means this level is strictly assessed, and all chidren |
|
2511 |
// are full), so this one has full |
|
2512 |
if (fElementDepth > fNFullValidationDepth) { |
|
2513 |
fCurrentPSVI.fValidationAttempted = ElementPSVI.VALIDATION_FULL; |
|
2514 |
} |
|
2515 |
// nothing below or at the same level has full or partial |
|
2516 |
// (which means this level is not strictly assessed, and all chidren |
|
2517 |
// are none), so this one has none |
|
2518 |
else if (fElementDepth > fNNoneValidationDepth) { |
|
2519 |
fCurrentPSVI.fValidationAttempted = ElementPSVI.VALIDATION_NONE; |
|
2520 |
} |
|
2521 |
// otherwise partial, and anything above this level will be partial |
|
2522 |
else { |
|
2523 |
fCurrentPSVI.fValidationAttempted = ElementPSVI.VALIDATION_PARTIAL; |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2524 |
} |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2525 |
|
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2526 |
// this guarantees that depth settings do not cross-over between sibling nodes |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2527 |
if (fNFullValidationDepth == fElementDepth) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2528 |
fNFullValidationDepth = fElementDepth - 1; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2529 |
} |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2530 |
if (fNNoneValidationDepth == fElementDepth) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2531 |
fNNoneValidationDepth = fElementDepth - 1; |
12005 | 2532 |
} |
2533 |
||
2534 |
if (fDefaultValue != null) |
|
2535 |
fCurrentPSVI.fSpecified = true; |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2536 |
fCurrentPSVI.fValue.copyFrom(fValidatedInfo); |
12005 | 2537 |
|
2538 |
if (fStrictAssess) { |
|
2539 |
// get all errors for the current element, its attribute, |
|
2540 |
// and subelements (if they were strictly assessed). |
|
2541 |
// any error would make this element invalid. |
|
2542 |
// and we merge these errors to the parent element. |
|
2543 |
String[] errors = fXSIErrorReporter.mergeContext(); |
|
2544 |
||
2545 |
// PSVI: error codes |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2546 |
fCurrentPSVI.fErrors = errors; |
12005 | 2547 |
// PSVI: validity |
2548 |
fCurrentPSVI.fValidity = |
|
2549 |
(errors == null) ? ElementPSVI.VALIDITY_VALID : ElementPSVI.VALIDITY_INVALID; |
|
2550 |
} else { |
|
2551 |
// PSVI: validity |
|
2552 |
fCurrentPSVI.fValidity = ElementPSVI.VALIDITY_NOTKNOWN; |
|
2553 |
// Discard the current context: ignore any error happened within |
|
2554 |
// the sub-elements/attributes of this element, because those |
|
2555 |
// errors won't affect the validity of the parent elements. |
|
2556 |
fXSIErrorReporter.popContext(); |
|
2557 |
} |
|
2558 |
||
2559 |
if (root) { |
|
2560 |
// store [schema information] in the PSVI |
|
2561 |
fCurrentPSVI.fGrammars = grammars; |
|
2562 |
fCurrentPSVI.fSchemaInformation = null; |
|
2563 |
} |
|
2564 |
} |
|
2565 |
||
2566 |
return augs; |
|
2567 |
||
2568 |
} |
|
2569 |
||
2570 |
Augmentations getEmptyAugs(Augmentations augs) { |
|
2571 |
if (augs == null) { |
|
2572 |
augs = fAugmentations; |
|
2573 |
augs.removeAllItems(); |
|
2574 |
} |
|
2575 |
augs.putItem(Constants.ELEMENT_PSVI, fCurrentPSVI); |
|
2576 |
fCurrentPSVI.reset(); |
|
2577 |
||
2578 |
return augs; |
|
2579 |
} |
|
2580 |
||
2581 |
void storeLocations(String sLocation, String nsLocation) { |
|
2582 |
if (sLocation != null) { |
|
33349 | 2583 |
if (!XMLSchemaLoader.tokenizeSchemaLocationStr(sLocation, |
2584 |
fLocationPairs, fLocator == null ? null : fLocator.getExpandedSystemId())) { |
|
12005 | 2585 |
// error! |
2586 |
fXSIErrorReporter.reportError( |
|
2587 |
XSMessageFormatter.SCHEMA_DOMAIN, |
|
2588 |
"SchemaLocation", |
|
2589 |
new Object[] { sLocation }, |
|
2590 |
XMLErrorReporter.SEVERITY_WARNING); |
|
2591 |
} |
|
2592 |
} |
|
2593 |
if (nsLocation != null) { |
|
33349 | 2594 |
XMLSchemaLoader.LocationArray la = fLocationPairs.get(XMLSymbols.EMPTY_STRING); |
12005 | 2595 |
if (la == null) { |
2596 |
la = new XMLSchemaLoader.LocationArray(); |
|
2597 |
fLocationPairs.put(XMLSymbols.EMPTY_STRING, la); |
|
2598 |
} |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2599 |
if (fLocator != null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2600 |
try { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2601 |
nsLocation = XMLEntityManager.expandSystemId(nsLocation, fLocator.getExpandedSystemId(), false); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2602 |
} catch (MalformedURIException e) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2603 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2604 |
} |
12005 | 2605 |
la.addLocation(nsLocation); |
2606 |
} |
|
2607 |
||
2608 |
} //storeLocations |
|
2609 |
||
2610 |
//this is the function where logic of retrieving grammar is written , parser first tries to get the grammar from |
|
2611 |
//the local pool, if not in local pool, it gives chance to application to be able to retrieve the grammar, then it |
|
2612 |
//tries to parse the grammar using location hints from the give namespace. |
|
2613 |
SchemaGrammar findSchemaGrammar( |
|
2614 |
short contextType, |
|
2615 |
String namespace, |
|
2616 |
QName enclosingElement, |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2617 |
QName triggeringComponent, |
12005 | 2618 |
XMLAttributes attributes) { |
2619 |
SchemaGrammar grammar = null; |
|
2620 |
//get the grammar from local pool... |
|
2621 |
grammar = fGrammarBucket.getGrammar(namespace); |
|
2622 |
||
2623 |
if (grammar == null) { |
|
2624 |
fXSDDescription.setNamespace(namespace); |
|
2625 |
// give a chance to application to be able to retreive the grammar. |
|
2626 |
if (fGrammarPool != null) { |
|
2627 |
grammar = (SchemaGrammar) fGrammarPool.retrieveGrammar(fXSDDescription); |
|
2628 |
if (grammar != null) { |
|
2629 |
// put this grammar into the bucket, along with grammars |
|
2630 |
// imported by it (directly or indirectly) |
|
2631 |
if (!fGrammarBucket.putGrammar(grammar, true, fNamespaceGrowth)) { |
|
2632 |
// REVISIT: a conflict between new grammar(s) and grammars |
|
2633 |
// in the bucket. What to do? A warning? An exception? |
|
2634 |
fXSIErrorReporter.fErrorReporter.reportError( |
|
2635 |
XSMessageFormatter.SCHEMA_DOMAIN, |
|
2636 |
"GrammarConflict", |
|
2637 |
null, |
|
2638 |
XMLErrorReporter.SEVERITY_WARNING); |
|
2639 |
grammar = null; |
|
2640 |
} |
|
2641 |
} |
|
2642 |
} |
|
2643 |
} |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2644 |
|
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2645 |
if (!fUseGrammarPoolOnly && (grammar == null || |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2646 |
(fNamespaceGrowth && !hasSchemaComponent(grammar, contextType, triggeringComponent)))) { |
12005 | 2647 |
fXSDDescription.reset(); |
2648 |
fXSDDescription.fContextType = contextType; |
|
2649 |
fXSDDescription.setNamespace(namespace); |
|
2650 |
fXSDDescription.fEnclosedElementName = enclosingElement; |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2651 |
fXSDDescription.fTriggeringComponent = triggeringComponent; |
12005 | 2652 |
fXSDDescription.fAttributes = attributes; |
2653 |
if (fLocator != null) { |
|
2654 |
fXSDDescription.setBaseSystemId(fLocator.getExpandedSystemId()); |
|
2655 |
} |
|
2656 |
||
33349 | 2657 |
Map<String, XMLSchemaLoader.LocationArray> locationPairs = fLocationPairs; |
2658 |
XMLSchemaLoader.LocationArray locationArray = |
|
12005 | 2659 |
locationPairs.get(namespace == null ? XMLSymbols.EMPTY_STRING : namespace); |
2660 |
if (locationArray != null) { |
|
33349 | 2661 |
String[] temp = locationArray.getLocationArray(); |
12005 | 2662 |
if (temp.length != 0) { |
2663 |
setLocationHints(fXSDDescription, temp, grammar); |
|
2664 |
} |
|
2665 |
} |
|
2666 |
||
2667 |
if (grammar == null || fXSDDescription.fLocationHints != null) { |
|
2668 |
boolean toParseSchema = true; |
|
2669 |
if (grammar != null) { |
|
2670 |
// use location hints instead |
|
33349 | 2671 |
locationPairs = Collections.emptyMap(); |
12005 | 2672 |
} |
2673 |
||
2674 |
// try to parse the grammar using location hints from that namespace.. |
|
2675 |
try { |
|
2676 |
XMLInputSource xis = |
|
2677 |
XMLSchemaLoader.resolveDocument( |
|
2678 |
fXSDDescription, |
|
2679 |
locationPairs, |
|
2680 |
fEntityResolver); |
|
2681 |
if (grammar != null && fNamespaceGrowth) { |
|
2682 |
try { |
|
2683 |
// if we are dealing with a different schema location, then include the new schema |
|
2684 |
// into the existing grammar |
|
2685 |
if (grammar.getDocumentLocations().contains(XMLEntityManager.expandSystemId(xis.getSystemId(), xis.getBaseSystemId(), false))) { |
|
2686 |
toParseSchema = false; |
|
2687 |
} |
|
2688 |
} |
|
2689 |
catch (MalformedURIException e) { |
|
2690 |
} |
|
2691 |
} |
|
2692 |
if (toParseSchema) { |
|
2693 |
grammar = fSchemaLoader.loadSchema(fXSDDescription, xis, fLocationPairs); |
|
2694 |
} |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2695 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2696 |
catch (IOException ex) { |
12005 | 2697 |
final String [] locationHints = fXSDDescription.getLocationHints(); |
2698 |
fXSIErrorReporter.fErrorReporter.reportError( |
|
2699 |
XSMessageFormatter.SCHEMA_DOMAIN, |
|
2700 |
"schema_reference.4", |
|
2701 |
new Object[] { locationHints != null ? locationHints[0] : XMLSymbols.EMPTY_STRING }, |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2702 |
XMLErrorReporter.SEVERITY_WARNING, ex); |
12005 | 2703 |
} |
2704 |
} |
|
2705 |
} |
|
2706 |
||
2707 |
return grammar; |
|
2708 |
||
2709 |
} //findSchemaGrammar |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2710 |
|
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2711 |
private boolean hasSchemaComponent(SchemaGrammar grammar, short contextType, QName triggeringComponent) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2712 |
if (grammar != null && triggeringComponent != null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2713 |
String localName = triggeringComponent.localpart; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2714 |
if (localName != null && localName.length() > 0) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2715 |
switch (contextType) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2716 |
case XSDDescription.CONTEXT_ELEMENT: |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2717 |
return grammar.getElementDeclaration(localName) != null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2718 |
case XSDDescription.CONTEXT_ATTRIBUTE: |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2719 |
return grammar.getAttributeDeclaration(localName) != null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2720 |
case XSDDescription.CONTEXT_XSITYPE: |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2721 |
return grammar.getTypeDefinition(localName) != null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2722 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2723 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2724 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2725 |
return false; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2726 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2727 |
|
12005 | 2728 |
private void setLocationHints(XSDDescription desc, String[] locations, SchemaGrammar grammar) { |
2729 |
int length = locations.length; |
|
2730 |
if (grammar == null) { |
|
2731 |
fXSDDescription.fLocationHints = new String[length]; |
|
2732 |
System.arraycopy(locations, 0, fXSDDescription.fLocationHints, 0, length); |
|
2733 |
} |
|
2734 |
else { |
|
2735 |
setLocationHints(desc, locations, grammar.getDocumentLocations()); |
|
2736 |
} |
|
2737 |
} |
|
2738 |
||
2739 |
private void setLocationHints(XSDDescription desc, String[] locations, StringList docLocations) { |
|
2740 |
int length = locations.length; |
|
2741 |
String[] hints = new String[length]; |
|
2742 |
int counter = 0; |
|
2743 |
||
2744 |
for (int i=0; i<length; i++) { |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2745 |
if (!docLocations.contains(locations[i])) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2746 |
hints[counter++] = locations[i]; |
12005 | 2747 |
} |
2748 |
} |
|
2749 |
||
2750 |
if (counter > 0) { |
|
2751 |
if (counter == length) { |
|
2752 |
fXSDDescription.fLocationHints = hints; |
|
2753 |
} |
|
2754 |
else { |
|
2755 |
fXSDDescription.fLocationHints = new String[counter]; |
|
2756 |
System.arraycopy(hints, 0, fXSDDescription.fLocationHints, 0, counter); |
|
2757 |
} |
|
2758 |
} |
|
2759 |
} |
|
2760 |
||
2761 |
XSTypeDefinition getAndCheckXsiType(QName element, String xsiType, XMLAttributes attributes) { |
|
2762 |
// This method also deals with clause 1.2.1.2 of the constraint |
|
2763 |
// Validation Rule: Schema-Validity Assessment (Element) |
|
2764 |
||
2765 |
// Element Locally Valid (Element) |
|
2766 |
// 4 If there is an attribute information item among the element information item's [attributes] whose [namespace name] is identical to http://www.w3.org/2001/XMLSchema-instance and whose [local name] is type, then all of the following must be true: |
|
2767 |
// 4.1 The normalized value of that attribute information item must be valid with respect to the built-in QName simple type, as defined by String Valid (3.14.4); |
|
2768 |
QName typeName = null; |
|
2769 |
try { |
|
2770 |
typeName = (QName) fQNameDV.validate(xsiType, fValidationState, null); |
|
2771 |
} catch (InvalidDatatypeValueException e) { |
|
2772 |
reportSchemaError(e.getKey(), e.getArgs()); |
|
2773 |
reportSchemaError( |
|
2774 |
"cvc-elt.4.1", |
|
2775 |
new Object[] { |
|
2776 |
element.rawname, |
|
2777 |
SchemaSymbols.URI_XSI + "," + SchemaSymbols.XSI_TYPE, |
|
2778 |
xsiType }); |
|
2779 |
return null; |
|
2780 |
} |
|
2781 |
||
2782 |
// 4.2 The local name and namespace name (as defined in QName Interpretation (3.15.3)), of the actual value of that attribute information item must resolve to a type definition, as defined in QName resolution (Instance) (3.15.4) |
|
2783 |
XSTypeDefinition type = null; |
|
2784 |
// if the namespace is schema namespace, first try built-in types |
|
2785 |
if (typeName.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA) { |
|
2786 |
type = SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(typeName.localpart); |
|
2787 |
} |
|
2788 |
// if it's not schema built-in types, then try to get a grammar |
|
2789 |
if (type == null) { |
|
2790 |
//try to find schema grammar by different means.... |
|
2791 |
SchemaGrammar grammar = |
|
2792 |
findSchemaGrammar( |
|
2793 |
XSDDescription.CONTEXT_XSITYPE, |
|
2794 |
typeName.uri, |
|
2795 |
element, |
|
2796 |
typeName, |
|
2797 |
attributes); |
|
2798 |
||
2799 |
if (grammar != null) |
|
2800 |
type = grammar.getGlobalTypeDecl(typeName.localpart); |
|
2801 |
} |
|
2802 |
// still couldn't find the type, report an error |
|
2803 |
if (type == null) { |
|
2804 |
reportSchemaError("cvc-elt.4.2", new Object[] { element.rawname, xsiType }); |
|
2805 |
return null; |
|
2806 |
} |
|
2807 |
||
2808 |
// if there is no current type, set this one as current. |
|
2809 |
// and we don't need to do extra checking |
|
2810 |
if (fCurrentType != null) { |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2811 |
short block = XSConstants.DERIVATION_NONE; |
12005 | 2812 |
// 4.3 The local type definition must be validly derived from the {type definition} given the union of the {disallowed substitutions} and the {type definition}'s {prohibited substitutions}, as defined in Type Derivation OK (Complex) (3.4.6) (if it is a complex type definition), or given {disallowed substitutions} as defined in Type Derivation OK (Simple) (3.14.6) (if it is a simple type definition). |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2813 |
// Note: It's possible to have fCurrentType be non-null and fCurrentElemDecl |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2814 |
// be null, if the current type is set using the property "root-type-definition". |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2815 |
// In that case, we don't disallow any substitutions. -PM |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2816 |
if (fCurrentElemDecl != null) { |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2817 |
block = fCurrentElemDecl.fBlock; |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2818 |
} |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2819 |
if (fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { |
12005 | 2820 |
block |= ((XSComplexTypeDecl) fCurrentType).fBlock; |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2821 |
} |
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2822 |
if (!XSConstraints.checkTypeDerivationOk(type, fCurrentType, block)) { |
12005 | 2823 |
reportSchemaError( |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2824 |
"cvc-elt.4.3", |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2825 |
new Object[] { element.rawname, xsiType, XS10TypeHelper.getSchemaTypeName(fCurrentType)}); |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
2826 |
} |
12005 | 2827 |
} |
2828 |
||
2829 |
return type; |
|
2830 |
} //getAndCheckXsiType |
|
2831 |
||
2832 |
boolean getXsiNil(QName element, String xsiNil) { |
|
2833 |
// Element Locally Valid (Element) |
|
2834 |
// 3 The appropriate case among the following must be true: |
|
2835 |
// 3.1 If {nillable} is false, then there must be no attribute information item among the element information item's [attributes] whose [namespace name] is identical to http://www.w3.org/2001/XMLSchema-instance and whose [local name] is nil. |
|
2836 |
if (fCurrentElemDecl != null && !fCurrentElemDecl.getNillable()) { |
|
2837 |
reportSchemaError( |
|
2838 |
"cvc-elt.3.1", |
|
2839 |
new Object[] { |
|
2840 |
element.rawname, |
|
2841 |
SchemaSymbols.URI_XSI + "," + SchemaSymbols.XSI_NIL }); |
|
2842 |
} |
|
2843 |
// 3.2 If {nillable} is true and there is such an attribute information item and its actual value is true , then all of the following must be true: |
|
2844 |
// 3.2.2 There must be no fixed {value constraint}. |
|
2845 |
else { |
|
2846 |
String value = XMLChar.trim(xsiNil); |
|
2847 |
if (value.equals(SchemaSymbols.ATTVAL_TRUE) |
|
2848 |
|| value.equals(SchemaSymbols.ATTVAL_TRUE_1)) { |
|
2849 |
if (fCurrentElemDecl != null |
|
2850 |
&& fCurrentElemDecl.getConstraintType() == XSConstants.VC_FIXED) { |
|
2851 |
reportSchemaError( |
|
2852 |
"cvc-elt.3.2.2", |
|
2853 |
new Object[] { |
|
2854 |
element.rawname, |
|
2855 |
SchemaSymbols.URI_XSI + "," + SchemaSymbols.XSI_NIL }); |
|
2856 |
} |
|
2857 |
return true; |
|
2858 |
} |
|
2859 |
} |
|
2860 |
return false; |
|
2861 |
} |
|
2862 |
||
2863 |
void processAttributes(QName element, XMLAttributes attributes, XSAttributeGroupDecl attrGrp) { |
|
2864 |
||
2865 |
if (DEBUG) { |
|
2866 |
System.out.println("==>processAttributes: " + attributes.getLength()); |
|
2867 |
} |
|
2868 |
||
2869 |
// whether we have seen a Wildcard ID. |
|
2870 |
String wildcardIDName = null; |
|
2871 |
||
2872 |
// for each present attribute |
|
2873 |
int attCount = attributes.getLength(); |
|
2874 |
||
2875 |
Augmentations augs = null; |
|
2876 |
AttributePSVImpl attrPSVI = null; |
|
2877 |
||
2878 |
boolean isSimple = |
|
2879 |
fCurrentType == null || fCurrentType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE; |
|
2880 |
||
2881 |
XSObjectList attrUses = null; |
|
2882 |
int useCount = 0; |
|
2883 |
XSWildcardDecl attrWildcard = null; |
|
2884 |
if (!isSimple) { |
|
2885 |
attrUses = attrGrp.getAttributeUses(); |
|
2886 |
useCount = attrUses.getLength(); |
|
2887 |
attrWildcard = attrGrp.fAttributeWC; |
|
2888 |
} |
|
2889 |
||
2890 |
// Element Locally Valid (Complex Type) |
|
2891 |
// 3 For each attribute information item in the element information item's [attributes] excepting those whose [namespace name] is identical to http://www.w3.org/2001/XMLSchema-instance and whose [local name] is one of type, nil, schemaLocation or noNamespaceSchemaLocation, the appropriate case among the following must be true: |
|
2892 |
// get the corresponding attribute decl |
|
2893 |
for (int index = 0; index < attCount; index++) { |
|
2894 |
||
2895 |
attributes.getName(index, fTempQName); |
|
2896 |
||
2897 |
if (DEBUG) { |
|
2898 |
System.out.println("==>process attribute: " + fTempQName); |
|
2899 |
} |
|
2900 |
||
2901 |
if (fAugPSVI || fIdConstraint) { |
|
2902 |
augs = attributes.getAugmentations(index); |
|
2903 |
attrPSVI = (AttributePSVImpl) augs.getItem(Constants.ATTRIBUTE_PSVI); |
|
2904 |
if (attrPSVI != null) { |
|
2905 |
attrPSVI.reset(); |
|
2906 |
} else { |
|
2907 |
attrPSVI = new AttributePSVImpl(); |
|
2908 |
augs.putItem(Constants.ATTRIBUTE_PSVI, attrPSVI); |
|
2909 |
} |
|
2910 |
// PSVI attribute: validation context |
|
2911 |
attrPSVI.fValidationContext = fValidationRoot; |
|
2912 |
} |
|
2913 |
||
2914 |
// Element Locally Valid (Type) |
|
2915 |
// 3.1.1 The element information item's [attributes] must be empty, excepting those |
|
2916 |
// whose [namespace name] is identical to http://www.w3.org/2001/XMLSchema-instance and |
|
2917 |
// whose [local name] is one of type, nil, schemaLocation or noNamespaceSchemaLocation. |
|
2918 |
||
2919 |
// for the 4 xsi attributes, get appropriate decl, and validate |
|
2920 |
if (fTempQName.uri == SchemaSymbols.URI_XSI) { |
|
2921 |
XSAttributeDecl attrDecl = null; |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2922 |
if (fTempQName.localpart == SchemaSymbols.XSI_TYPE) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2923 |
attrDecl = XSI_TYPE; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2924 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2925 |
else if (fTempQName.localpart == SchemaSymbols.XSI_NIL) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2926 |
attrDecl = XSI_NIL; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2927 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2928 |
else if (fTempQName.localpart == SchemaSymbols.XSI_SCHEMALOCATION) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2929 |
attrDecl = XSI_SCHEMALOCATION; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2930 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2931 |
else if (fTempQName.localpart == SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2932 |
attrDecl = XSI_NONAMESPACESCHEMALOCATION; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2933 |
} |
12005 | 2934 |
if (attrDecl != null) { |
2935 |
processOneAttribute(element, attributes, index, attrDecl, null, attrPSVI); |
|
2936 |
continue; |
|
2937 |
} |
|
2938 |
} |
|
2939 |
||
2940 |
// for namespace attributes, no_validation/unknow_validity |
|
2941 |
if (fTempQName.rawname == XMLSymbols.PREFIX_XMLNS |
|
2942 |
|| fTempQName.rawname.startsWith("xmlns:")) { |
|
2943 |
continue; |
|
2944 |
} |
|
2945 |
||
2946 |
// simple type doesn't allow any other attributes |
|
2947 |
if (isSimple) { |
|
2948 |
reportSchemaError( |
|
2949 |
"cvc-type.3.1.1", |
|
2950 |
new Object[] { element.rawname, fTempQName.rawname }); |
|
2951 |
continue; |
|
2952 |
} |
|
2953 |
||
2954 |
// it's not xmlns, and not xsi, then we need to find a decl for it |
|
2955 |
XSAttributeUseImpl currUse = null, oneUse; |
|
2956 |
for (int i = 0; i < useCount; i++) { |
|
2957 |
oneUse = (XSAttributeUseImpl) attrUses.item(i); |
|
2958 |
if (oneUse.fAttrDecl.fName == fTempQName.localpart |
|
2959 |
&& oneUse.fAttrDecl.fTargetNamespace == fTempQName.uri) { |
|
2960 |
currUse = oneUse; |
|
2961 |
break; |
|
2962 |
} |
|
2963 |
} |
|
2964 |
||
2965 |
// 3.2 otherwise all of the following must be true: |
|
2966 |
// 3.2.1 There must be an {attribute wildcard}. |
|
2967 |
// 3.2.2 The attribute information item must be valid with respect to it as defined in Item Valid (Wildcard) (3.10.4). |
|
2968 |
||
2969 |
// if failed, get it from wildcard |
|
2970 |
if (currUse == null) { |
|
2971 |
//if (attrWildcard == null) |
|
2972 |
// reportSchemaError("cvc-complex-type.3.2.1", new Object[]{element.rawname, fTempQName.rawname}); |
|
2973 |
if (attrWildcard == null || !attrWildcard.allowNamespace(fTempQName.uri)) { |
|
2974 |
// so this attribute is not allowed |
|
2975 |
reportSchemaError( |
|
2976 |
"cvc-complex-type.3.2.2", |
|
2977 |
new Object[] { element.rawname, fTempQName.rawname }); |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2978 |
|
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2979 |
// We have seen an attribute that was not declared |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2980 |
fNFullValidationDepth = fElementDepth; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
2981 |
|
12005 | 2982 |
continue; |
2983 |
} |
|
2984 |
} |
|
2985 |
||
2986 |
XSAttributeDecl currDecl = null; |
|
2987 |
if (currUse != null) { |
|
2988 |
currDecl = currUse.fAttrDecl; |
|
2989 |
} else { |
|
2990 |
// which means it matches a wildcard |
|
2991 |
// skip it if processContents is skip |
|
2992 |
if (attrWildcard.fProcessContents == XSWildcardDecl.PC_SKIP) |
|
2993 |
continue; |
|
2994 |
||
2995 |
//try to find grammar by different means... |
|
2996 |
SchemaGrammar grammar = |
|
2997 |
findSchemaGrammar( |
|
2998 |
XSDDescription.CONTEXT_ATTRIBUTE, |
|
2999 |
fTempQName.uri, |
|
3000 |
element, |
|
3001 |
fTempQName, |
|
3002 |
attributes); |
|
3003 |
||
3004 |
if (grammar != null) { |
|
3005 |
currDecl = grammar.getGlobalAttributeDecl(fTempQName.localpart); |
|
3006 |
} |
|
3007 |
||
3008 |
// if can't find |
|
3009 |
if (currDecl == null) { |
|
3010 |
// if strict, report error |
|
3011 |
if (attrWildcard.fProcessContents == XSWildcardDecl.PC_STRICT) { |
|
3012 |
reportSchemaError( |
|
3013 |
"cvc-complex-type.3.2.2", |
|
3014 |
new Object[] { element.rawname, fTempQName.rawname }); |
|
3015 |
} |
|
3016 |
||
3017 |
// then continue to the next attribute |
|
3018 |
continue; |
|
3019 |
} else { |
|
3020 |
// 5 Let [Definition:] the wild IDs be the set of all attribute information item to which clause 3.2 applied and whose validation resulted in a context-determined declaration of mustFind or no context-determined declaration at all, and whose [local name] and [namespace name] resolve (as defined by QName resolution (Instance) (3.15.4)) to an attribute declaration whose {type definition} is or is derived from ID. Then all of the following must be true: |
|
3021 |
// 5.1 There must be no more than one item in wild IDs. |
|
3022 |
if (currDecl.fType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE |
|
3023 |
&& ((XSSimpleType) currDecl.fType).isIDType()) { |
|
3024 |
if (wildcardIDName != null) { |
|
3025 |
reportSchemaError( |
|
3026 |
"cvc-complex-type.5.1", |
|
3027 |
new Object[] { element.rawname, currDecl.fName, wildcardIDName }); |
|
3028 |
} else |
|
3029 |
wildcardIDName = currDecl.fName; |
|
3030 |
} |
|
3031 |
} |
|
3032 |
} |
|
3033 |
||
3034 |
processOneAttribute(element, attributes, index, currDecl, currUse, attrPSVI); |
|
3035 |
} // end of for (all attributes) |
|
3036 |
||
3037 |
// 5.2 If wild IDs is non-empty, there must not be any attribute uses among the {attribute uses} whose {attribute declaration}'s {type definition} is or is derived from ID. |
|
3038 |
if (!isSimple && attrGrp.fIDAttrName != null && wildcardIDName != null) { |
|
3039 |
reportSchemaError( |
|
3040 |
"cvc-complex-type.5.2", |
|
3041 |
new Object[] { element.rawname, wildcardIDName, attrGrp.fIDAttrName }); |
|
3042 |
} |
|
3043 |
||
3044 |
} //processAttributes |
|
3045 |
||
3046 |
void processOneAttribute( |
|
3047 |
QName element, |
|
3048 |
XMLAttributes attributes, |
|
3049 |
int index, |
|
3050 |
XSAttributeDecl currDecl, |
|
3051 |
XSAttributeUseImpl currUse, |
|
3052 |
AttributePSVImpl attrPSVI) { |
|
3053 |
||
3054 |
String attrValue = attributes.getValue(index); |
|
3055 |
fXSIErrorReporter.pushContext(); |
|
3056 |
||
3057 |
// Attribute Locally Valid |
|
3058 |
// For an attribute information item to be locally valid with respect to an attribute declaration all of the following must be true: |
|
3059 |
// 1 The declaration must not be absent (see Missing Sub-components (5.3) for how this can fail to be the case). |
|
3060 |
// 2 Its {type definition} must not be absent. |
|
3061 |
// 3 The item's normalized value must be locally valid with respect to that {type definition} as per String Valid (3.14.4). |
|
3062 |
// get simple type |
|
3063 |
XSSimpleType attDV = currDecl.fType; |
|
3064 |
||
3065 |
Object actualValue = null; |
|
3066 |
try { |
|
3067 |
actualValue = attDV.validate(attrValue, fValidationState, fValidatedInfo); |
|
3068 |
// store the normalized value |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3069 |
if (fNormalizeData) { |
12005 | 3070 |
attributes.setValue(index, fValidatedInfo.normalizedValue); |
3071 |
} |
|
3072 |
// PSVI: element notation |
|
3073 |
if (attDV.getVariety() == XSSimpleType.VARIETY_ATOMIC |
|
3074 |
&& attDV.getPrimitiveKind() == XSSimpleType.PRIMITIVE_NOTATION) { |
|
3075 |
QName qName = (QName) actualValue; |
|
3076 |
SchemaGrammar grammar = fGrammarBucket.getGrammar(qName.uri); |
|
3077 |
||
3078 |
//REVISIT: is it possible for the notation to be in different namespace than the attribute |
|
3079 |
//with which it is associated, CHECK !! <fof n1:att1 = "n2:notation1" ..> |
|
3080 |
// should we give chance to the application to be able to retrieve a grammar - nb |
|
3081 |
//REVISIT: what would be the triggering component here.. if it is attribute value that |
|
3082 |
// triggered the loading of grammar ?? -nb |
|
3083 |
||
3084 |
if (grammar != null) { |
|
3085 |
fNotation = grammar.getGlobalNotationDecl(qName.localpart); |
|
3086 |
} |
|
3087 |
} |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3088 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3089 |
catch (InvalidDatatypeValueException idve) { |
12005 | 3090 |
reportSchemaError(idve.getKey(), idve.getArgs()); |
3091 |
reportSchemaError( |
|
3092 |
"cvc-attribute.3", |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3093 |
new Object[] { element.rawname, fTempQName.rawname, attrValue, |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3094 |
(attDV instanceof XSSimpleTypeDecl) ? |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3095 |
((XSSimpleTypeDecl) attDV).getTypeName() : attDV.getName()}); |
12005 | 3096 |
} |
3097 |
||
3098 |
// get the value constraint from use or decl |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3099 |
// 4 The item's actual value must match the value of the {value constraint}, if it is present and fixed. // now check the value against the simpleType |
12005 | 3100 |
if (actualValue != null && currDecl.getConstraintType() == XSConstants.VC_FIXED) { |
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
3101 |
if (!ValidatedInfo.isComparable(fValidatedInfo, currDecl.fDefault) || !actualValue.equals(currDecl.fDefault.actualValue)) { |
12005 | 3102 |
reportSchemaError( |
3103 |
"cvc-attribute.4", |
|
3104 |
new Object[] { |
|
3105 |
element.rawname, |
|
3106 |
fTempQName.rawname, |
|
3107 |
attrValue, |
|
3108 |
currDecl.fDefault.stringValue()}); |
|
3109 |
} |
|
3110 |
} |
|
3111 |
||
3112 |
// 3.1 If there is among the {attribute uses} an attribute use with an {attribute declaration} whose {name} matches the attribute information item's [local name] and whose {target namespace} is identical to the attribute information item's [namespace name] (where an absent {target namespace} is taken to be identical to a [namespace name] with no value), then the attribute information must be valid with respect to that attribute use as per Attribute Locally Valid (Use) (3.5.4). In this case the {attribute declaration} of that attribute use is the context-determined declaration for the attribute information item with respect to Schema-Validity Assessment (Attribute) (3.2.4) and Assessment Outcome (Attribute) (3.2.5). |
|
3113 |
if (actualValue != null |
|
3114 |
&& currUse != null |
|
3115 |
&& currUse.fConstraintType == XSConstants.VC_FIXED) { |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
3116 |
if (!ValidatedInfo.isComparable(fValidatedInfo, currUse.fDefault) || !actualValue.equals(currUse.fDefault.actualValue)) { |
12005 | 3117 |
reportSchemaError( |
3118 |
"cvc-complex-type.3.1", |
|
3119 |
new Object[] { |
|
3120 |
element.rawname, |
|
3121 |
fTempQName.rawname, |
|
3122 |
attrValue, |
|
3123 |
currUse.fDefault.stringValue()}); |
|
3124 |
} |
|
3125 |
} |
|
3126 |
if (fIdConstraint) { |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3127 |
attrPSVI.fValue.copyFrom(fValidatedInfo); |
12005 | 3128 |
} |
3129 |
||
3130 |
if (fAugPSVI) { |
|
3131 |
// PSVI: attribute declaration |
|
3132 |
attrPSVI.fDeclaration = currDecl; |
|
3133 |
// PSVI: attribute type |
|
3134 |
attrPSVI.fTypeDecl = attDV; |
|
3135 |
||
3136 |
// PSVI: attribute normalized value |
|
3137 |
// NOTE: we always store the normalized value, even if it's invlid, |
|
3138 |
// because it might still be useful to the user. But when the it's |
|
3139 |
// not valid, the normalized value is not trustable. |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3140 |
attrPSVI.fValue.copyFrom(fValidatedInfo); |
12005 | 3141 |
|
3142 |
// PSVI: validation attempted: |
|
3143 |
attrPSVI.fValidationAttempted = AttributePSVI.VALIDATION_FULL; |
|
3144 |
||
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3145 |
// We have seen an attribute that was declared. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3146 |
if (!fUseGrammarPoolOnly && |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3147 |
!(fElementDepth < fIgnoreXSITypeDepth && fCurrentElemDecl == null)) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3148 |
//only when USE_GRAMMAR_POOL_ONLY and IGNORE_XSI_TYPE are not set |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3149 |
fNNoneValidationDepth = fElementDepth; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3150 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3151 |
|
12005 | 3152 |
String[] errors = fXSIErrorReporter.mergeContext(); |
3153 |
// PSVI: error codes |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3154 |
attrPSVI.fErrors = errors; |
12005 | 3155 |
// PSVI: validity |
3156 |
attrPSVI.fValidity = |
|
3157 |
(errors == null) ? AttributePSVI.VALIDITY_VALID : AttributePSVI.VALIDITY_INVALID; |
|
3158 |
} |
|
3159 |
} |
|
3160 |
||
3161 |
void addDefaultAttributes( |
|
3162 |
QName element, |
|
3163 |
XMLAttributes attributes, |
|
3164 |
XSAttributeGroupDecl attrGrp) { |
|
3165 |
// Check after all specified attrs are scanned |
|
3166 |
// (1) report error for REQUIRED attrs that are missing (V_TAGc) |
|
3167 |
// REVISIT: should we check prohibited attributes? |
|
3168 |
// (2) report error for PROHIBITED attrs that are present (V_TAGc) |
|
3169 |
// (3) add default attrs (FIXED and NOT_FIXED) |
|
3170 |
// |
|
3171 |
if (DEBUG) { |
|
3172 |
System.out.println("==>addDefaultAttributes: " + element); |
|
3173 |
} |
|
3174 |
XSObjectList attrUses = attrGrp.getAttributeUses(); |
|
3175 |
int useCount = attrUses.getLength(); |
|
3176 |
XSAttributeUseImpl currUse; |
|
3177 |
XSAttributeDecl currDecl; |
|
3178 |
short constType; |
|
3179 |
ValidatedInfo defaultValue; |
|
3180 |
boolean isSpecified; |
|
3181 |
QName attName; |
|
3182 |
// for each attribute use |
|
3183 |
for (int i = 0; i < useCount; i++) { |
|
3184 |
||
3185 |
currUse = (XSAttributeUseImpl) attrUses.item(i); |
|
3186 |
currDecl = currUse.fAttrDecl; |
|
3187 |
// get value constraint |
|
3188 |
constType = currUse.fConstraintType; |
|
3189 |
defaultValue = currUse.fDefault; |
|
3190 |
if (constType == XSConstants.VC_NONE) { |
|
3191 |
constType = currDecl.getConstraintType(); |
|
3192 |
defaultValue = currDecl.fDefault; |
|
3193 |
} |
|
3194 |
// whether this attribute is specified |
|
3195 |
isSpecified = attributes.getValue(currDecl.fTargetNamespace, currDecl.fName) != null; |
|
3196 |
||
3197 |
// Element Locally Valid (Complex Type) |
|
3198 |
// 4 The {attribute declaration} of each attribute use in the {attribute uses} whose |
|
3199 |
// {required} is true matches one of the attribute information items in the element |
|
3200 |
// information item's [attributes] as per clause 3.1 above. |
|
3201 |
if (currUse.fUse == SchemaSymbols.USE_REQUIRED) { |
|
3202 |
if (!isSpecified) |
|
3203 |
reportSchemaError( |
|
3204 |
"cvc-complex-type.4", |
|
3205 |
new Object[] { element.rawname, currDecl.fName }); |
|
3206 |
} |
|
3207 |
// if the attribute is not specified, then apply the value constraint |
|
3208 |
if (!isSpecified && constType != XSConstants.VC_NONE) { |
|
3209 |
attName = |
|
3210 |
new QName(null, currDecl.fName, currDecl.fName, currDecl.fTargetNamespace); |
|
3211 |
String normalized = (defaultValue != null) ? defaultValue.stringValue() : ""; |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3212 |
int attrIndex; |
12005 | 3213 |
if (attributes instanceof XMLAttributesImpl) { |
3214 |
XMLAttributesImpl attrs = (XMLAttributesImpl) attributes; |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3215 |
attrIndex = attrs.getLength(); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3216 |
attrs.addAttributeNS(attName, "CDATA", normalized); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3217 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3218 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3219 |
attrIndex = attributes.addAttribute(attName, "CDATA", normalized); |
12005 | 3220 |
} |
3221 |
||
3222 |
if (fAugPSVI) { |
|
3223 |
||
3224 |
// PSVI: attribute is "schema" specified |
|
3225 |
Augmentations augs = attributes.getAugmentations(attrIndex); |
|
3226 |
AttributePSVImpl attrPSVI = new AttributePSVImpl(); |
|
3227 |
augs.putItem(Constants.ATTRIBUTE_PSVI, attrPSVI); |
|
3228 |
||
3229 |
attrPSVI.fDeclaration = currDecl; |
|
3230 |
attrPSVI.fTypeDecl = currDecl.fType; |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3231 |
attrPSVI.fValue.copyFrom(defaultValue); |
12005 | 3232 |
attrPSVI.fValidationContext = fValidationRoot; |
3233 |
attrPSVI.fValidity = AttributePSVI.VALIDITY_VALID; |
|
3234 |
attrPSVI.fValidationAttempted = AttributePSVI.VALIDATION_FULL; |
|
3235 |
attrPSVI.fSpecified = true; |
|
3236 |
} |
|
3237 |
} |
|
3238 |
||
3239 |
} // for |
|
3240 |
} // addDefaultAttributes |
|
3241 |
||
3242 |
/** |
|
3243 |
* If there is not text content, and there is a |
|
3244 |
* {value constraint} on the corresponding element decl, then return |
|
3245 |
* an XMLString representing the default value. |
|
3246 |
*/ |
|
3247 |
void processElementContent(QName element) { |
|
3248 |
// 1 If the item is ?valid? with respect to an element declaration as per Element Locally Valid (Element) (?3.3.4) and the {value constraint} is present, but clause 3.2 of Element Locally Valid (Element) (?3.3.4) above is not satisfied and the item has no element or character information item [children], then schema. Furthermore, the post-schema-validation infoset has the canonical lexical representation of the {value constraint} value as the item's [schema normalized value] property. |
|
3249 |
if (fCurrentElemDecl != null |
|
3250 |
&& fCurrentElemDecl.fDefault != null |
|
3251 |
&& !fSawText |
|
3252 |
&& !fSubElement |
|
3253 |
&& !fNil) { |
|
3254 |
||
3255 |
String strv = fCurrentElemDecl.fDefault.stringValue(); |
|
3256 |
int bufLen = strv.length(); |
|
3257 |
if (fNormalizedStr.ch == null || fNormalizedStr.ch.length < bufLen) { |
|
3258 |
fNormalizedStr.ch = new char[bufLen]; |
|
3259 |
} |
|
3260 |
strv.getChars(0, bufLen, fNormalizedStr.ch, 0); |
|
3261 |
fNormalizedStr.offset = 0; |
|
3262 |
fNormalizedStr.length = bufLen; |
|
3263 |
fDefaultValue = fNormalizedStr; |
|
3264 |
} |
|
3265 |
// fixed values are handled later, after xsi:type determined. |
|
3266 |
||
3267 |
fValidatedInfo.normalizedValue = null; |
|
3268 |
||
3269 |
// Element Locally Valid (Element) |
|
3270 |
// 3.2.1 The element information item must have no character or element information item [children]. |
|
3271 |
if (fNil) { |
|
3272 |
if (fSubElement || fSawText) { |
|
3273 |
reportSchemaError( |
|
3274 |
"cvc-elt.3.2.1", |
|
3275 |
new Object[] { |
|
3276 |
element.rawname, |
|
3277 |
SchemaSymbols.URI_XSI + "," + SchemaSymbols.XSI_NIL }); |
|
3278 |
} |
|
3279 |
} |
|
3280 |
||
3281 |
this.fValidatedInfo.reset(); |
|
3282 |
||
3283 |
// 5 The appropriate case among the following must be true: |
|
3284 |
// 5.1 If the declaration has a {value constraint}, the item has neither element nor character [children] and clause 3.2 has not applied, then all of the following must be true: |
|
3285 |
if (fCurrentElemDecl != null |
|
3286 |
&& fCurrentElemDecl.getConstraintType() != XSConstants.VC_NONE |
|
3287 |
&& !fSubElement |
|
3288 |
&& !fSawText |
|
3289 |
&& !fNil) { |
|
3290 |
// 5.1.1 If the actual type definition is a local type definition then the canonical lexical representation of the {value constraint} value must be a valid default for the actual type definition as defined in Element Default Valid (Immediate) (3.3.6). |
|
3291 |
if (fCurrentType != fCurrentElemDecl.fType) { |
|
3292 |
//REVISIT:we should pass ValidatedInfo here. |
|
3293 |
if (XSConstraints |
|
3294 |
.ElementDefaultValidImmediate( |
|
3295 |
fCurrentType, |
|
3296 |
fCurrentElemDecl.fDefault.stringValue(), |
|
3297 |
fState4XsiType, |
|
3298 |
null) |
|
3299 |
== null) |
|
3300 |
reportSchemaError( |
|
3301 |
"cvc-elt.5.1.1", |
|
3302 |
new Object[] { |
|
3303 |
element.rawname, |
|
3304 |
fCurrentType.getName(), |
|
3305 |
fCurrentElemDecl.fDefault.stringValue()}); |
|
3306 |
} |
|
3307 |
// 5.1.2 The element information item with the canonical lexical representation of the {value constraint} value used as its normalized value must be valid with respect to the actual type definition as defined by Element Locally Valid (Type) (3.3.4). |
|
3308 |
// REVISIT: don't use toString, but validateActualValue instead |
|
3309 |
// use the fState4ApplyDefault |
|
3310 |
elementLocallyValidType(element, fCurrentElemDecl.fDefault.stringValue()); |
|
3311 |
} else { |
|
3312 |
// The following method call also deal with clause 1.2.2 of the constraint |
|
3313 |
// Validation Rule: Schema-Validity Assessment (Element) |
|
3314 |
||
3315 |
// 5.2 If the declaration has no {value constraint} or the item has either element or character [children] or clause 3.2 has applied, then all of the following must be true: |
|
3316 |
// 5.2.1 The element information item must be valid with respect to the actual type definition as defined by Element Locally Valid (Type) (3.3.4). |
|
3317 |
Object actualValue = elementLocallyValidType(element, fBuffer); |
|
3318 |
// 5.2.2 If there is a fixed {value constraint} and clause 3.2 has not applied, all of the following must be true: |
|
3319 |
if (fCurrentElemDecl != null |
|
3320 |
&& fCurrentElemDecl.getConstraintType() == XSConstants.VC_FIXED |
|
3321 |
&& !fNil) { |
|
3322 |
String content = fBuffer.toString(); |
|
3323 |
// 5.2.2.1 The element information item must have no element information item [children]. |
|
3324 |
if (fSubElement) |
|
3325 |
reportSchemaError("cvc-elt.5.2.2.1", new Object[] { element.rawname }); |
|
3326 |
// 5.2.2.2 The appropriate case among the following must be true: |
|
3327 |
if (fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { |
|
3328 |
XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType; |
|
3329 |
// 5.2.2.2.1 If the {content type} of the actual type definition is mixed, then the initial value of the item must match the canonical lexical representation of the {value constraint} value. |
|
3330 |
if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_MIXED) { |
|
3331 |
// REVISIT: how to get the initial value, does whiteSpace count? |
|
3332 |
if (!fCurrentElemDecl.fDefault.normalizedValue.equals(content)) |
|
3333 |
reportSchemaError( |
|
3334 |
"cvc-elt.5.2.2.2.1", |
|
3335 |
new Object[] { |
|
3336 |
element.rawname, |
|
3337 |
content, |
|
3338 |
fCurrentElemDecl.fDefault.normalizedValue }); |
|
3339 |
} |
|
3340 |
// 5.2.2.2.2 If the {content type} of the actual type definition is a simple type definition, then the actual value of the item must match the canonical lexical representation of the {value constraint} value. |
|
3341 |
else if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_SIMPLE) { |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
3342 |
if (actualValue != null && (!ValidatedInfo.isComparable(fValidatedInfo, fCurrentElemDecl.fDefault) |
12005 | 3343 |
|| !actualValue.equals(fCurrentElemDecl.fDefault.actualValue))) { |
3344 |
reportSchemaError( |
|
3345 |
"cvc-elt.5.2.2.2.2", |
|
3346 |
new Object[] { |
|
3347 |
element.rawname, |
|
3348 |
content, |
|
3349 |
fCurrentElemDecl.fDefault.stringValue()}); |
|
3350 |
} |
|
3351 |
} |
|
3352 |
} else if (fCurrentType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { |
|
26257
4ec17c54acb3
8037819: Xerces Update: jaxp/validation/XMLSchemaFactory
joehw
parents:
25868
diff
changeset
|
3353 |
if (actualValue != null && (!ValidatedInfo.isComparable(fValidatedInfo, fCurrentElemDecl.fDefault) |
12005 | 3354 |
|| !actualValue.equals(fCurrentElemDecl.fDefault.actualValue))) { |
3355 |
// REVISIT: the spec didn't mention this case: fixed |
|
3356 |
// value with simple type |
|
3357 |
reportSchemaError( |
|
3358 |
"cvc-elt.5.2.2.2.2", |
|
3359 |
new Object[] { |
|
3360 |
element.rawname, |
|
3361 |
content, |
|
3362 |
fCurrentElemDecl.fDefault.stringValue()}); |
|
3363 |
} |
|
3364 |
} |
|
3365 |
} |
|
3366 |
} |
|
3367 |
||
3368 |
if (fDefaultValue == null && fNormalizeData && fDocumentHandler != null && fUnionType) { |
|
3369 |
// for union types we need to send data because we delayed sending |
|
3370 |
// this data when we received it in the characters() call. |
|
3371 |
String content = fValidatedInfo.normalizedValue; |
|
3372 |
if (content == null) |
|
3373 |
content = fBuffer.toString(); |
|
3374 |
||
3375 |
int bufLen = content.length(); |
|
3376 |
if (fNormalizedStr.ch == null || fNormalizedStr.ch.length < bufLen) { |
|
3377 |
fNormalizedStr.ch = new char[bufLen]; |
|
3378 |
} |
|
3379 |
content.getChars(0, bufLen, fNormalizedStr.ch, 0); |
|
3380 |
fNormalizedStr.offset = 0; |
|
3381 |
fNormalizedStr.length = bufLen; |
|
3382 |
fDocumentHandler.characters(fNormalizedStr, null); |
|
3383 |
} |
|
3384 |
} // processElementContent |
|
3385 |
||
3386 |
Object elementLocallyValidType(QName element, Object textContent) { |
|
3387 |
if (fCurrentType == null) |
|
3388 |
return null; |
|
3389 |
||
3390 |
Object retValue = null; |
|
3391 |
// Element Locally Valid (Type) |
|
3392 |
// 3 The appropriate case among the following must be true: |
|
3393 |
// 3.1 If the type definition is a simple type definition, then all of the following must be true: |
|
3394 |
if (fCurrentType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { |
|
3395 |
// 3.1.2 The element information item must have no element information item [children]. |
|
3396 |
if (fSubElement) |
|
3397 |
reportSchemaError("cvc-type.3.1.2", new Object[] { element.rawname }); |
|
3398 |
// 3.1.3 If clause 3.2 of Element Locally Valid (Element) (3.3.4) did not apply, then the normalized value must be valid with respect to the type definition as defined by String Valid (3.14.4). |
|
3399 |
if (!fNil) { |
|
3400 |
XSSimpleType dv = (XSSimpleType) fCurrentType; |
|
3401 |
try { |
|
3402 |
if (!fNormalizeData || fUnionType) { |
|
3403 |
fValidationState.setNormalizationRequired(true); |
|
3404 |
} |
|
3405 |
retValue = dv.validate(textContent, fValidationState, fValidatedInfo); |
|
3406 |
} catch (InvalidDatatypeValueException e) { |
|
3407 |
reportSchemaError(e.getKey(), e.getArgs()); |
|
3408 |
reportSchemaError( |
|
3409 |
"cvc-type.3.1.3", |
|
3410 |
new Object[] { element.rawname, textContent }); |
|
3411 |
} |
|
3412 |
} |
|
3413 |
} else { |
|
3414 |
// 3.2 If the type definition is a complex type definition, then the element information item must be valid with respect to the type definition as per Element Locally Valid (Complex Type) (3.4.4); |
|
3415 |
retValue = elementLocallyValidComplexType(element, textContent); |
|
3416 |
} |
|
3417 |
||
3418 |
return retValue; |
|
3419 |
} // elementLocallyValidType |
|
3420 |
||
3421 |
Object elementLocallyValidComplexType(QName element, Object textContent) { |
|
3422 |
Object actualValue = null; |
|
3423 |
XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType; |
|
3424 |
||
3425 |
// Element Locally Valid (Complex Type) |
|
3426 |
// For an element information item to be locally valid with respect to a complex type definition all of the following must be true: |
|
3427 |
// 1 {abstract} is false. |
|
3428 |
// 2 If clause 3.2 of Element Locally Valid (Element) (3.3.4) did not apply, then the appropriate case among the following must be true: |
|
3429 |
if (!fNil) { |
|
3430 |
// 2.1 If the {content type} is empty, then the element information item has no character or element information item [children]. |
|
3431 |
if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_EMPTY |
|
3432 |
&& (fSubElement || fSawText)) { |
|
3433 |
reportSchemaError("cvc-complex-type.2.1", new Object[] { element.rawname }); |
|
3434 |
} |
|
3435 |
// 2.2 If the {content type} is a simple type definition, then the element information item has no element information item [children], and the normalized value of the element information item is valid with respect to that simple type definition as defined by String Valid (3.14.4). |
|
3436 |
else if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_SIMPLE) { |
|
3437 |
if (fSubElement) |
|
3438 |
reportSchemaError("cvc-complex-type.2.2", new Object[] { element.rawname }); |
|
3439 |
XSSimpleType dv = ctype.fXSSimpleType; |
|
3440 |
try { |
|
3441 |
if (!fNormalizeData || fUnionType) { |
|
3442 |
fValidationState.setNormalizationRequired(true); |
|
3443 |
} |
|
3444 |
actualValue = dv.validate(textContent, fValidationState, fValidatedInfo); |
|
3445 |
} catch (InvalidDatatypeValueException e) { |
|
3446 |
reportSchemaError(e.getKey(), e.getArgs()); |
|
3447 |
reportSchemaError("cvc-complex-type.2.2", new Object[] { element.rawname }); |
|
3448 |
} |
|
3449 |
// REVISIT: eventually, this method should return the same actualValue as elementLocallyValidType... |
|
3450 |
// obviously it'll return null when the content is complex. |
|
3451 |
} |
|
3452 |
// 2.3 If the {content type} is element-only, then the element information item has no character information item [children] other than those whose [character code] is defined as a white space in [XML 1.0 (Second Edition)]. |
|
3453 |
else if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT) { |
|
3454 |
if (fSawCharacters) { |
|
3455 |
reportSchemaError("cvc-complex-type.2.3", new Object[] { element.rawname }); |
|
3456 |
} |
|
3457 |
} |
|
3458 |
// 2.4 If the {content type} is element-only or mixed, then the sequence of the element information item's element information item [children], if any, taken in order, is valid with respect to the {content type}'s particle, as defined in Element Sequence Locally Valid (Particle) (3.9.4). |
|
3459 |
if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT |
|
3460 |
|| ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_MIXED) { |
|
3461 |
// if the current state is a valid state, check whether |
|
3462 |
// it's one of the final states. |
|
3463 |
if (DEBUG) { |
|
3464 |
System.out.println(fCurrCMState); |
|
3465 |
} |
|
3466 |
if (fCurrCMState[0] >= 0 && !fCurrentCM.endContentModel(fCurrCMState)) { |
|
3467 |
String expected = expectedStr(fCurrentCM.whatCanGoHere(fCurrCMState)); |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3468 |
final int[] occurenceInfo = fCurrentCM.occurenceInfo(fCurrCMState); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3469 |
if (occurenceInfo != null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3470 |
final int minOccurs = occurenceInfo[0]; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3471 |
final int count = occurenceInfo[2]; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3472 |
// Check if this is a violation of minOccurs |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3473 |
if (count < minOccurs) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3474 |
final int required = minOccurs - count; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3475 |
if (required > 1) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3476 |
reportSchemaError("cvc-complex-type.2.4.j", new Object[] { element.rawname, |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3477 |
fCurrentCM.getTermName(occurenceInfo[3]), Integer.toString(minOccurs), Integer.toString(required) }); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3478 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3479 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3480 |
reportSchemaError("cvc-complex-type.2.4.i", new Object[] { element.rawname, |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3481 |
fCurrentCM.getTermName(occurenceInfo[3]), Integer.toString(minOccurs) }); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3482 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3483 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3484 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3485 |
reportSchemaError("cvc-complex-type.2.4.b", new Object[] { element.rawname, expected }); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3486 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3487 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3488 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3489 |
reportSchemaError("cvc-complex-type.2.4.b", new Object[] { element.rawname, expected }); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3490 |
} |
12005 | 3491 |
} else { |
3492 |
// Constant space algorithm for a{n,m} for n > 1 and m <= unbounded |
|
3493 |
// After the DFA has completed, check minOccurs and maxOccurs |
|
3494 |
// for all elements and wildcards in this content model where |
|
3495 |
// a{n,m} is subsumed to a* or a+ |
|
3496 |
ArrayList errors = fCurrentCM.checkMinMaxBounds(); |
|
3497 |
if (errors != null) { |
|
3498 |
for (int i = 0; i < errors.size(); i += 2) { |
|
3499 |
reportSchemaError( |
|
3500 |
(String) errors.get(i), |
|
3501 |
new Object[] { element.rawname, errors.get(i + 1) }); |
|
3502 |
} |
|
3503 |
} |
|
3504 |
} |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3505 |
} |
12005 | 3506 |
} |
3507 |
return actualValue; |
|
3508 |
} // elementLocallyValidComplexType |
|
3509 |
||
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3510 |
void processRootTypeQName(final javax.xml.namespace.QName rootTypeQName) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3511 |
String rootTypeNamespace = rootTypeQName.getNamespaceURI(); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3512 |
// Add namespace to symbol table, to make sure it's interned. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3513 |
// This namespace may be later compared with other values using ==. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3514 |
rootTypeNamespace = fSymbolTable.addSymbol(rootTypeNamespace); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3515 |
if (rootTypeNamespace != null && rootTypeNamespace.equals(XMLConstants.NULL_NS_URI)) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3516 |
rootTypeNamespace = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3517 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3518 |
if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(rootTypeNamespace)) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3519 |
fCurrentType = SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(rootTypeQName.getLocalPart()); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3520 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3521 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3522 |
final SchemaGrammar grammarForRootType = findSchemaGrammar( |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3523 |
XSDDescription.CONTEXT_ELEMENT, rootTypeNamespace, null, null, null); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3524 |
if (grammarForRootType != null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3525 |
fCurrentType = grammarForRootType.getGlobalTypeDecl(rootTypeQName.getLocalPart()); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3526 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3527 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3528 |
if (fCurrentType == null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3529 |
String typeName = (rootTypeQName.getPrefix().equals(XMLConstants.DEFAULT_NS_PREFIX)) ? |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3530 |
rootTypeQName.getLocalPart() : |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3531 |
rootTypeQName.getPrefix()+":"+rootTypeQName.getLocalPart(); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3532 |
reportSchemaError("cvc-type.1", new Object[] {typeName}); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3533 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3534 |
} // processRootTypeQName |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3535 |
|
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3536 |
void processRootElementDeclQName(final javax.xml.namespace.QName rootElementDeclQName, final QName element) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3537 |
String rootElementDeclNamespace = rootElementDeclQName.getNamespaceURI(); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3538 |
// Add namespace to symbol table, to make sure it's interned. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3539 |
// This namespace may be later compared with other values using ==. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3540 |
rootElementDeclNamespace = fSymbolTable.addSymbol(rootElementDeclNamespace); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3541 |
if (rootElementDeclNamespace != null && rootElementDeclNamespace.equals(XMLConstants.NULL_NS_URI)) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3542 |
rootElementDeclNamespace = null; |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3543 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3544 |
final SchemaGrammar grammarForRootElement = findSchemaGrammar( |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3545 |
XSDDescription.CONTEXT_ELEMENT, rootElementDeclNamespace, null, null, null); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3546 |
if (grammarForRootElement != null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3547 |
fCurrentElemDecl = grammarForRootElement.getGlobalElementDecl(rootElementDeclQName.getLocalPart()); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3548 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3549 |
if (fCurrentElemDecl == null) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3550 |
String declName = (rootElementDeclQName.getPrefix().equals(XMLConstants.DEFAULT_NS_PREFIX)) ? |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3551 |
rootElementDeclQName.getLocalPart() : |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3552 |
rootElementDeclQName.getPrefix()+":"+rootElementDeclQName.getLocalPart(); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3553 |
reportSchemaError("cvc-elt.1.a", new Object[] {declName}); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3554 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3555 |
else { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3556 |
checkElementMatchesRootElementDecl(fCurrentElemDecl, element); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3557 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3558 |
} // processRootElementDeclQName |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3559 |
|
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3560 |
void checkElementMatchesRootElementDecl(final XSElementDecl rootElementDecl, final QName element) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3561 |
// Report an error if the name of the element does |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3562 |
// not match the name of the specified element declaration. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3563 |
if (element.localpart != rootElementDecl.fName || |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3564 |
element.uri != rootElementDecl.fTargetNamespace) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3565 |
reportSchemaError("cvc-elt.1.b", new Object[] {element.rawname, rootElementDecl.fName}); |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3566 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3567 |
} // checkElementMatchesRootElementDecl |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3568 |
|
12005 | 3569 |
void reportSchemaError(String key, Object[] arguments) { |
3570 |
if (fDoValidation) |
|
3571 |
fXSIErrorReporter.reportError( |
|
3572 |
XSMessageFormatter.SCHEMA_DOMAIN, |
|
3573 |
key, |
|
3574 |
arguments, |
|
3575 |
XMLErrorReporter.SEVERITY_ERROR); |
|
3576 |
} |
|
3577 |
||
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3578 |
private String expectedStr(ArrayList expected) { |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3579 |
StringBuilder ret = new StringBuilder("{"); |
12005 | 3580 |
int size = expected.size(); |
3581 |
for (int i = 0; i < size; i++) { |
|
3582 |
if (i > 0) |
|
3583 |
ret.append(", "); |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3584 |
ret.append(expected.get(i).toString()); |
12005 | 3585 |
} |
3586 |
ret.append('}'); |
|
3587 |
return ret.toString(); |
|
3588 |
} |
|
3589 |
||
3590 |
/**********************************/ |
|
3591 |
||
3592 |
// xpath matcher information |
|
3593 |
||
3594 |
/** |
|
3595 |
* Stack of XPath matchers for identity constraints. |
|
3596 |
* |
|
3597 |
* @author Andy Clark, IBM |
|
3598 |
*/ |
|
3599 |
protected static class XPathMatcherStack { |
|
3600 |
||
3601 |
// |
|
3602 |
// Data |
|
3603 |
// |
|
3604 |
||
3605 |
/** Active matchers. */ |
|
3606 |
protected XPathMatcher[] fMatchers = new XPathMatcher[4]; |
|
3607 |
||
3608 |
/** Count of active matchers. */ |
|
3609 |
protected int fMatchersCount; |
|
3610 |
||
3611 |
/** Offset stack for contexts. */ |
|
3612 |
protected IntStack fContextStack = new IntStack(); |
|
3613 |
||
3614 |
// |
|
3615 |
// Constructors |
|
3616 |
// |
|
3617 |
||
3618 |
public XPathMatcherStack() { |
|
3619 |
} // <init>() |
|
3620 |
||
3621 |
// |
|
3622 |
// Public methods |
|
3623 |
// |
|
3624 |
||
3625 |
/** Resets the XPath matcher stack. */ |
|
3626 |
public void clear() { |
|
3627 |
for (int i = 0; i < fMatchersCount; i++) { |
|
3628 |
fMatchers[i] = null; |
|
3629 |
} |
|
3630 |
fMatchersCount = 0; |
|
3631 |
fContextStack.clear(); |
|
3632 |
} // clear() |
|
3633 |
||
3634 |
/** Returns the size of the stack. */ |
|
3635 |
public int size() { |
|
3636 |
return fContextStack.size(); |
|
3637 |
} // size():int |
|
3638 |
||
3639 |
/** Returns the count of XPath matchers. */ |
|
3640 |
public int getMatcherCount() { |
|
3641 |
return fMatchersCount; |
|
3642 |
} // getMatcherCount():int |
|
3643 |
||
3644 |
/** Adds a matcher. */ |
|
3645 |
public void addMatcher(XPathMatcher matcher) { |
|
3646 |
ensureMatcherCapacity(); |
|
3647 |
fMatchers[fMatchersCount++] = matcher; |
|
3648 |
} // addMatcher(XPathMatcher) |
|
3649 |
||
3650 |
/** Returns the XPath matcher at the specified index. */ |
|
3651 |
public XPathMatcher getMatcherAt(int index) { |
|
3652 |
return fMatchers[index]; |
|
3653 |
} // getMatcherAt(index):XPathMatcher |
|
3654 |
||
3655 |
/** Pushes a new context onto the stack. */ |
|
3656 |
public void pushContext() { |
|
3657 |
fContextStack.push(fMatchersCount); |
|
3658 |
} // pushContext() |
|
3659 |
||
3660 |
/** Pops a context off of the stack. */ |
|
3661 |
public void popContext() { |
|
3662 |
fMatchersCount = fContextStack.pop(); |
|
3663 |
} // popContext() |
|
3664 |
||
3665 |
// |
|
3666 |
// Private methods |
|
3667 |
// |
|
3668 |
||
3669 |
/** Ensures the size of the matchers array. */ |
|
3670 |
private void ensureMatcherCapacity() { |
|
3671 |
if (fMatchersCount == fMatchers.length) { |
|
3672 |
XPathMatcher[] array = new XPathMatcher[fMatchers.length * 2]; |
|
3673 |
System.arraycopy(fMatchers, 0, array, 0, fMatchers.length); |
|
3674 |
fMatchers = array; |
|
3675 |
} |
|
3676 |
} // ensureMatcherCapacity() |
|
3677 |
||
3678 |
} // class XPathMatcherStack |
|
3679 |
||
3680 |
// value store implementations |
|
3681 |
||
3682 |
/** |
|
3683 |
* Value store implementation base class. There are specific subclasses |
|
3684 |
* for handling unique, key, and keyref. |
|
3685 |
* |
|
3686 |
* @author Andy Clark, IBM |
|
3687 |
*/ |
|
3688 |
protected abstract class ValueStoreBase implements ValueStore { |
|
3689 |
||
3690 |
// |
|
3691 |
// Data |
|
3692 |
// |
|
3693 |
||
3694 |
/** Identity constraint. */ |
|
3695 |
protected IdentityConstraint fIdentityConstraint; |
|
3696 |
protected int fFieldCount = 0; |
|
3697 |
protected Field[] fFields = null; |
|
3698 |
/** current data */ |
|
3699 |
protected Object[] fLocalValues = null; |
|
3700 |
protected short[] fLocalValueTypes = null; |
|
3701 |
protected ShortList[] fLocalItemValueTypes = null; |
|
3702 |
||
3703 |
/** Current data value count. */ |
|
3704 |
protected int fValuesCount; |
|
3705 |
||
3706 |
/** global data */ |
|
3707 |
public final Vector fValues = new Vector(); |
|
3708 |
public ShortVector fValueTypes = null; |
|
3709 |
public Vector fItemValueTypes = null; |
|
3710 |
||
3711 |
private boolean fUseValueTypeVector = false; |
|
3712 |
private int fValueTypesLength = 0; |
|
3713 |
private short fValueType = 0; |
|
3714 |
||
3715 |
private boolean fUseItemValueTypeVector = false; |
|
3716 |
private int fItemValueTypesLength = 0; |
|
3717 |
private ShortList fItemValueType = null; |
|
3718 |
||
3719 |
/** buffer for error messages */ |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3720 |
final StringBuilder fTempBuffer = new StringBuilder(); |
12005 | 3721 |
|
3722 |
// |
|
3723 |
// Constructors |
|
3724 |
// |
|
3725 |
||
3726 |
/** Constructs a value store for the specified identity constraint. */ |
|
3727 |
protected ValueStoreBase(IdentityConstraint identityConstraint) { |
|
3728 |
fIdentityConstraint = identityConstraint; |
|
3729 |
fFieldCount = fIdentityConstraint.getFieldCount(); |
|
3730 |
fFields = new Field[fFieldCount]; |
|
3731 |
fLocalValues = new Object[fFieldCount]; |
|
3732 |
fLocalValueTypes = new short[fFieldCount]; |
|
3733 |
fLocalItemValueTypes = new ShortList[fFieldCount]; |
|
3734 |
for (int i = 0; i < fFieldCount; i++) { |
|
3735 |
fFields[i] = fIdentityConstraint.getFieldAt(i); |
|
3736 |
} |
|
3737 |
} // <init>(IdentityConstraint) |
|
3738 |
||
3739 |
// |
|
3740 |
// Public methods |
|
3741 |
// |
|
3742 |
||
3743 |
// destroys this ValueStore; useful when, for instance, a |
|
3744 |
// locally-scoped ID constraint is involved. |
|
3745 |
public void clear() { |
|
3746 |
fValuesCount = 0; |
|
3747 |
fUseValueTypeVector = false; |
|
3748 |
fValueTypesLength = 0; |
|
3749 |
fValueType = 0; |
|
3750 |
fUseItemValueTypeVector = false; |
|
3751 |
fItemValueTypesLength = 0; |
|
3752 |
fItemValueType = null; |
|
3753 |
fValues.setSize(0); |
|
3754 |
if (fValueTypes != null) { |
|
3755 |
fValueTypes.clear(); |
|
3756 |
} |
|
3757 |
if (fItemValueTypes != null) { |
|
3758 |
fItemValueTypes.setSize(0); |
|
3759 |
} |
|
3760 |
} // end clear():void |
|
3761 |
||
3762 |
// appends the contents of one ValueStore to those of us. |
|
3763 |
public void append(ValueStoreBase newVal) { |
|
3764 |
for (int i = 0; i < newVal.fValues.size(); i++) { |
|
3765 |
fValues.addElement(newVal.fValues.elementAt(i)); |
|
3766 |
} |
|
3767 |
} // append(ValueStoreBase) |
|
3768 |
||
3769 |
/** Start scope for value store. */ |
|
3770 |
public void startValueScope() { |
|
3771 |
fValuesCount = 0; |
|
3772 |
for (int i = 0; i < fFieldCount; i++) { |
|
3773 |
fLocalValues[i] = null; |
|
3774 |
fLocalValueTypes[i] = 0; |
|
3775 |
fLocalItemValueTypes[i] = null; |
|
3776 |
} |
|
3777 |
} // startValueScope() |
|
3778 |
||
3779 |
/** Ends scope for value store. */ |
|
3780 |
public void endValueScope() { |
|
3781 |
||
3782 |
if (fValuesCount == 0) { |
|
3783 |
if (fIdentityConstraint.getCategory() == IdentityConstraint.IC_KEY) { |
|
3784 |
String code = "AbsentKeyValue"; |
|
3785 |
String eName = fIdentityConstraint.getElementName(); |
|
12458 | 3786 |
String cName = fIdentityConstraint.getIdentityConstraintName(); |
3787 |
reportSchemaError(code, new Object[] { eName, cName }); |
|
12005 | 3788 |
} |
3789 |
return; |
|
3790 |
} |
|
3791 |
||
3792 |
// Validation Rule: Identity-constraint Satisfied |
|
3793 |
// 4.2 If the {identity-constraint category} is key, then all of the following must be true: |
|
3794 |
// 4.2.1 The target node set and the qualified node set are equal, that is, every member of the |
|
3795 |
// target node set is also a member of the qualified node set and vice versa. |
|
3796 |
// |
|
3797 |
// If the IDC is a key check whether we have all the fields. |
|
3798 |
if (fValuesCount != fFieldCount) { |
|
3799 |
if (fIdentityConstraint.getCategory() == IdentityConstraint.IC_KEY) { |
|
3800 |
String code = "KeyNotEnoughValues"; |
|
3801 |
UniqueOrKey key = (UniqueOrKey) fIdentityConstraint; |
|
12458 | 3802 |
String eName = fIdentityConstraint.getElementName(); |
3803 |
String cName = key.getIdentityConstraintName(); |
|
3804 |
reportSchemaError(code, new Object[] { eName, cName }); |
|
12005 | 3805 |
} |
3806 |
return; |
|
3807 |
} |
|
3808 |
||
3809 |
} // endValueScope() |
|
3810 |
||
3811 |
// This is needed to allow keyref's to look for matched keys |
|
3812 |
// in the correct scope. Unique and Key may also need to |
|
3813 |
// override this method for purposes of their own. |
|
3814 |
// This method is called whenever the DocumentFragment |
|
3815 |
// of an ID Constraint goes out of scope. |
|
3816 |
public void endDocumentFragment() { |
|
3817 |
} // endDocumentFragment():void |
|
3818 |
||
3819 |
/** |
|
3820 |
* Signals the end of the document. This is where the specific |
|
3821 |
* instances of value stores can verify the integrity of the |
|
3822 |
* identity constraints. |
|
3823 |
*/ |
|
3824 |
public void endDocument() { |
|
3825 |
} // endDocument() |
|
3826 |
||
3827 |
// |
|
3828 |
// ValueStore methods |
|
3829 |
// |
|
3830 |
||
3831 |
/* reports an error if an element is matched |
|
3832 |
* has nillable true and is matched by a key. |
|
3833 |
*/ |
|
3834 |
||
3835 |
public void reportError(String key, Object[] args) { |
|
3836 |
reportSchemaError(key, args); |
|
3837 |
} // reportError(String,Object[]) |
|
3838 |
||
3839 |
/** |
|
3840 |
* Adds the specified value to the value store. |
|
3841 |
* |
|
3842 |
* @param field The field associated to the value. This reference |
|
3843 |
* is used to ensure that each field only adds a value |
|
3844 |
* once within a selection scope. |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3845 |
* @param mayMatch a flag indiciating whether the field may be matched. |
12005 | 3846 |
* @param actualValue The value to add. |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3847 |
* @param valueType Type of the value to add. |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3848 |
* @param itemValueType If the value is a list, a list of types for each of the values in the list. |
12005 | 3849 |
*/ |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3850 |
public void addValue(Field field, boolean mayMatch, Object actualValue, short valueType, ShortList itemValueType) { |
12005 | 3851 |
int i; |
3852 |
for (i = fFieldCount - 1; i > -1; i--) { |
|
3853 |
if (fFields[i] == field) { |
|
3854 |
break; |
|
3855 |
} |
|
3856 |
} |
|
3857 |
// do we even know this field? |
|
3858 |
if (i == -1) { |
|
3859 |
String code = "UnknownField"; |
|
12458 | 3860 |
String eName = fIdentityConstraint.getElementName(); |
3861 |
String cName = fIdentityConstraint.getIdentityConstraintName(); |
|
3862 |
reportSchemaError(code, new Object[] { field.toString(), eName, cName }); |
|
12005 | 3863 |
return; |
3864 |
} |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3865 |
if (!mayMatch) { |
12005 | 3866 |
String code = "FieldMultipleMatch"; |
12458 | 3867 |
String cName = fIdentityConstraint.getIdentityConstraintName(); |
3868 |
reportSchemaError(code, new Object[] { field.toString(), cName }); |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3869 |
} |
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
3870 |
else { |
12005 | 3871 |
fValuesCount++; |
3872 |
} |
|
3873 |
fLocalValues[i] = actualValue; |
|
3874 |
fLocalValueTypes[i] = valueType; |
|
3875 |
fLocalItemValueTypes[i] = itemValueType; |
|
3876 |
if (fValuesCount == fFieldCount) { |
|
3877 |
checkDuplicateValues(); |
|
3878 |
// store values |
|
3879 |
for (i = 0; i < fFieldCount; i++) { |
|
3880 |
fValues.addElement(fLocalValues[i]); |
|
3881 |
addValueType(fLocalValueTypes[i]); |
|
3882 |
addItemValueType(fLocalItemValueTypes[i]); |
|
3883 |
} |
|
3884 |
} |
|
3885 |
} // addValue(String,Field) |
|
3886 |
||
3887 |
/** |
|
3888 |
* Returns true if this value store contains the locally scoped value stores |
|
3889 |
*/ |
|
3890 |
public boolean contains() { |
|
3891 |
// REVISIT: we can improve performance by using hash codes, instead of |
|
3892 |
// traversing global vector that could be quite large. |
|
3893 |
int next = 0; |
|
3894 |
final int size = fValues.size(); |
|
3895 |
LOOP : for (int i = 0; i < size; i = next) { |
|
3896 |
next = i + fFieldCount; |
|
3897 |
for (int j = 0; j < fFieldCount; j++) { |
|
3898 |
Object value1 = fLocalValues[j]; |
|
3899 |
Object value2 = fValues.elementAt(i); |
|
3900 |
short valueType1 = fLocalValueTypes[j]; |
|
3901 |
short valueType2 = getValueTypeAt(i); |
|
3902 |
if (value1 == null || value2 == null || valueType1 != valueType2 || !(value1.equals(value2))) { |
|
3903 |
continue LOOP; |
|
3904 |
} |
|
3905 |
else if(valueType1 == XSConstants.LIST_DT || valueType1 == XSConstants.LISTOFUNION_DT) { |
|
3906 |
ShortList list1 = fLocalItemValueTypes[j]; |
|
3907 |
ShortList list2 = getItemValueTypeAt(i); |
|
3908 |
if(list1 == null || list2 == null || !list1.equals(list2)) |
|
3909 |
continue LOOP; |
|
3910 |
} |
|
3911 |
i++; |
|
3912 |
} |
|
3913 |
// found it |
|
3914 |
return true; |
|
3915 |
} |
|
3916 |
// didn't find it |
|
3917 |
return false; |
|
3918 |
} // contains():boolean |
|
3919 |
||
3920 |
/** |
|
3921 |
* Returns -1 if this value store contains the specified |
|
3922 |
* values, otherwise the index of the first field in the |
|
3923 |
* key sequence. |
|
3924 |
*/ |
|
3925 |
public int contains(ValueStoreBase vsb) { |
|
3926 |
||
3927 |
final Vector values = vsb.fValues; |
|
3928 |
final int size1 = values.size(); |
|
3929 |
if (fFieldCount <= 1) { |
|
3930 |
for (int i = 0; i < size1; ++i) { |
|
3931 |
short val = vsb.getValueTypeAt(i); |
|
3932 |
if (!valueTypeContains(val) || !fValues.contains(values.elementAt(i))) { |
|
3933 |
return i; |
|
3934 |
} |
|
3935 |
else if(val == XSConstants.LIST_DT || val == XSConstants.LISTOFUNION_DT) { |
|
3936 |
ShortList list1 = vsb.getItemValueTypeAt(i); |
|
3937 |
if (!itemValueTypeContains(list1)) { |
|
3938 |
return i; |
|
3939 |
} |
|
3940 |
} |
|
3941 |
} |
|
3942 |
} |
|
3943 |
/** Handle n-tuples. **/ |
|
3944 |
else { |
|
3945 |
final int size2 = fValues.size(); |
|
3946 |
/** Iterate over each set of fields. **/ |
|
3947 |
OUTER: for (int i = 0; i < size1; i += fFieldCount) { |
|
3948 |
/** Check whether this set is contained in the value store. **/ |
|
3949 |
INNER: for (int j = 0; j < size2; j += fFieldCount) { |
|
3950 |
for (int k = 0; k < fFieldCount; ++k) { |
|
3951 |
final Object value1 = values.elementAt(i+k); |
|
3952 |
final Object value2 = fValues.elementAt(j+k); |
|
3953 |
final short valueType1 = vsb.getValueTypeAt(i+k); |
|
3954 |
final short valueType2 = getValueTypeAt(j+k); |
|
3955 |
if (value1 != value2 && (valueType1 != valueType2 || value1 == null || !value1.equals(value2))) { |
|
3956 |
continue INNER; |
|
3957 |
} |
|
3958 |
else if(valueType1 == XSConstants.LIST_DT || valueType1 == XSConstants.LISTOFUNION_DT) { |
|
3959 |
ShortList list1 = vsb.getItemValueTypeAt(i+k); |
|
3960 |
ShortList list2 = getItemValueTypeAt(j+k); |
|
3961 |
if (list1 == null || list2 == null || !list1.equals(list2)) { |
|
3962 |
continue INNER; |
|
3963 |
} |
|
3964 |
} |
|
3965 |
} |
|
3966 |
continue OUTER; |
|
3967 |
} |
|
3968 |
return i; |
|
3969 |
} |
|
3970 |
} |
|
3971 |
return -1; |
|
3972 |
||
3973 |
} // contains(Vector):Object |
|
3974 |
||
3975 |
// |
|
3976 |
// Protected methods |
|
3977 |
// |
|
3978 |
||
3979 |
protected void checkDuplicateValues() { |
|
3980 |
// no-op |
|
33349 | 3981 |
} // duplicateValue(Map) |
12005 | 3982 |
|
3983 |
/** Returns a string of the specified values. */ |
|
3984 |
protected String toString(Object[] values) { |
|
3985 |
||
3986 |
// no values |
|
3987 |
int size = values.length; |
|
3988 |
if (size == 0) { |
|
3989 |
return ""; |
|
3990 |
} |
|
3991 |
||
3992 |
fTempBuffer.setLength(0); |
|
3993 |
||
3994 |
// construct value string |
|
3995 |
for (int i = 0; i < size; i++) { |
|
3996 |
if (i > 0) { |
|
3997 |
fTempBuffer.append(','); |
|
3998 |
} |
|
3999 |
fTempBuffer.append(values[i]); |
|
4000 |
} |
|
4001 |
return fTempBuffer.toString(); |
|
4002 |
||
4003 |
} // toString(Object[]):String |
|
4004 |
||
4005 |
/** Returns a string of the specified values. */ |
|
4006 |
protected String toString(Vector values, int start, int length) { |
|
4007 |
||
4008 |
// no values |
|
4009 |
if (length == 0) { |
|
4010 |
return ""; |
|
4011 |
} |
|
4012 |
||
4013 |
// one value |
|
4014 |
if (length == 1) { |
|
4015 |
return String.valueOf(values.elementAt(start)); |
|
4016 |
} |
|
4017 |
||
4018 |
// construct value string |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
4019 |
StringBuilder str = new StringBuilder(); |
12005 | 4020 |
for (int i = 0; i < length; i++) { |
4021 |
if (i > 0) { |
|
4022 |
str.append(','); |
|
4023 |
} |
|
4024 |
str.append(values.elementAt(start + i)); |
|
4025 |
} |
|
4026 |
return str.toString(); |
|
4027 |
||
4028 |
} // toString(Vector,int,int):String |
|
4029 |
||
4030 |
// |
|
4031 |
// Object methods |
|
4032 |
// |
|
4033 |
||
4034 |
/** Returns a string representation of this object. */ |
|
4035 |
public String toString() { |
|
4036 |
String s = super.toString(); |
|
4037 |
int index1 = s.lastIndexOf('$'); |
|
4038 |
if (index1 != -1) { |
|
4039 |
s = s.substring(index1 + 1); |
|
4040 |
} |
|
4041 |
int index2 = s.lastIndexOf('.'); |
|
4042 |
if (index2 != -1) { |
|
4043 |
s = s.substring(index2 + 1); |
|
4044 |
} |
|
4045 |
return s + '[' + fIdentityConstraint + ']'; |
|
4046 |
} // toString():String |
|
4047 |
||
4048 |
// |
|
4049 |
// Private methods |
|
4050 |
// |
|
4051 |
||
4052 |
private void addValueType(short type) { |
|
4053 |
if (fUseValueTypeVector) { |
|
4054 |
fValueTypes.add(type); |
|
4055 |
} |
|
4056 |
else if (fValueTypesLength++ == 0) { |
|
4057 |
fValueType = type; |
|
4058 |
} |
|
4059 |
else if (fValueType != type) { |
|
4060 |
fUseValueTypeVector = true; |
|
4061 |
if (fValueTypes == null) { |
|
4062 |
fValueTypes = new ShortVector(fValueTypesLength * 2); |
|
4063 |
} |
|
4064 |
for (int i = 1; i < fValueTypesLength; ++i) { |
|
4065 |
fValueTypes.add(fValueType); |
|
4066 |
} |
|
4067 |
fValueTypes.add(type); |
|
4068 |
} |
|
4069 |
} |
|
4070 |
||
4071 |
private short getValueTypeAt(int index) { |
|
4072 |
if (fUseValueTypeVector) { |
|
4073 |
return fValueTypes.valueAt(index); |
|
4074 |
} |
|
4075 |
return fValueType; |
|
4076 |
} |
|
4077 |
||
4078 |
private boolean valueTypeContains(short value) { |
|
4079 |
if (fUseValueTypeVector) { |
|
4080 |
return fValueTypes.contains(value); |
|
4081 |
} |
|
4082 |
return fValueType == value; |
|
4083 |
} |
|
4084 |
||
4085 |
private void addItemValueType(ShortList itemValueType) { |
|
4086 |
if (fUseItemValueTypeVector) { |
|
4087 |
fItemValueTypes.add(itemValueType); |
|
4088 |
} |
|
4089 |
else if (fItemValueTypesLength++ == 0) { |
|
4090 |
fItemValueType = itemValueType; |
|
4091 |
} |
|
4092 |
else if (!(fItemValueType == itemValueType || |
|
4093 |
(fItemValueType != null && fItemValueType.equals(itemValueType)))) { |
|
4094 |
fUseItemValueTypeVector = true; |
|
4095 |
if (fItemValueTypes == null) { |
|
4096 |
fItemValueTypes = new Vector(fItemValueTypesLength * 2); |
|
4097 |
} |
|
4098 |
for (int i = 1; i < fItemValueTypesLength; ++i) { |
|
4099 |
fItemValueTypes.add(fItemValueType); |
|
4100 |
} |
|
4101 |
fItemValueTypes.add(itemValueType); |
|
4102 |
} |
|
4103 |
} |
|
4104 |
||
4105 |
private ShortList getItemValueTypeAt(int index) { |
|
4106 |
if (fUseItemValueTypeVector) { |
|
4107 |
return (ShortList) fItemValueTypes.elementAt(index); |
|
4108 |
} |
|
4109 |
return fItemValueType; |
|
4110 |
} |
|
4111 |
||
4112 |
private boolean itemValueTypeContains(ShortList value) { |
|
4113 |
if (fUseItemValueTypeVector) { |
|
4114 |
return fItemValueTypes.contains(value); |
|
4115 |
} |
|
4116 |
return fItemValueType == value || |
|
4117 |
(fItemValueType != null && fItemValueType.equals(value)); |
|
4118 |
} |
|
4119 |
||
4120 |
} // class ValueStoreBase |
|
4121 |
||
4122 |
/** |
|
4123 |
* Unique value store. |
|
4124 |
* |
|
4125 |
* @author Andy Clark, IBM |
|
4126 |
*/ |
|
4127 |
protected class UniqueValueStore extends ValueStoreBase { |
|
4128 |
||
4129 |
// |
|
4130 |
// Constructors |
|
4131 |
// |
|
4132 |
||
4133 |
/** Constructs a unique value store. */ |
|
4134 |
public UniqueValueStore(UniqueOrKey unique) { |
|
4135 |
super(unique); |
|
4136 |
} // <init>(Unique) |
|
4137 |
||
4138 |
// |
|
4139 |
// ValueStoreBase protected methods |
|
4140 |
// |
|
4141 |
||
4142 |
/** |
|
4143 |
* Called when a duplicate value is added. |
|
4144 |
*/ |
|
4145 |
protected void checkDuplicateValues() { |
|
4146 |
// is this value as a group duplicated? |
|
4147 |
if (contains()) { |
|
4148 |
String code = "DuplicateUnique"; |
|
4149 |
String value = toString(fLocalValues); |
|
12458 | 4150 |
String eName = fIdentityConstraint.getElementName(); |
4151 |
String cName = fIdentityConstraint.getIdentityConstraintName(); |
|
4152 |
reportSchemaError(code, new Object[] { value, eName, cName }); |
|
12005 | 4153 |
} |
33349 | 4154 |
} // duplicateValue(Map) |
12005 | 4155 |
|
4156 |
} // class UniqueValueStore |
|
4157 |
||
4158 |
/** |
|
4159 |
* Key value store. |
|
4160 |
* |
|
4161 |
* @author Andy Clark, IBM |
|
4162 |
*/ |
|
4163 |
protected class KeyValueStore extends ValueStoreBase { |
|
4164 |
||
4165 |
// REVISIT: Implement a more efficient storage mechanism. -Ac |
|
4166 |
||
4167 |
// |
|
4168 |
// Constructors |
|
4169 |
// |
|
4170 |
||
4171 |
/** Constructs a key value store. */ |
|
4172 |
public KeyValueStore(UniqueOrKey key) { |
|
4173 |
super(key); |
|
4174 |
} // <init>(Key) |
|
4175 |
||
4176 |
// |
|
4177 |
// ValueStoreBase protected methods |
|
4178 |
// |
|
4179 |
||
4180 |
/** |
|
4181 |
* Called when a duplicate value is added. |
|
4182 |
*/ |
|
4183 |
protected void checkDuplicateValues() { |
|
4184 |
if (contains()) { |
|
4185 |
String code = "DuplicateKey"; |
|
4186 |
String value = toString(fLocalValues); |
|
12458 | 4187 |
String eName = fIdentityConstraint.getElementName(); |
4188 |
String cName = fIdentityConstraint.getIdentityConstraintName(); |
|
4189 |
reportSchemaError(code, new Object[] { value, eName, cName }); |
|
12005 | 4190 |
} |
33349 | 4191 |
} // duplicateValue(Map) |
12005 | 4192 |
|
4193 |
} // class KeyValueStore |
|
4194 |
||
4195 |
/** |
|
4196 |
* Key reference value store. |
|
4197 |
* |
|
4198 |
* @author Andy Clark, IBM |
|
4199 |
*/ |
|
4200 |
protected class KeyRefValueStore extends ValueStoreBase { |
|
4201 |
||
4202 |
// |
|
4203 |
// Data |
|
4204 |
// |
|
4205 |
||
4206 |
/** Key value store. */ |
|
4207 |
protected ValueStoreBase fKeyValueStore; |
|
4208 |
||
4209 |
// |
|
4210 |
// Constructors |
|
4211 |
// |
|
4212 |
||
4213 |
/** Constructs a key value store. */ |
|
4214 |
public KeyRefValueStore(KeyRef keyRef, KeyValueStore keyValueStore) { |
|
4215 |
super(keyRef); |
|
4216 |
fKeyValueStore = keyValueStore; |
|
4217 |
} // <init>(KeyRef) |
|
4218 |
||
4219 |
// |
|
4220 |
// ValueStoreBase methods |
|
4221 |
// |
|
4222 |
||
4223 |
// end the value Scope; here's where we have to tie |
|
4224 |
// up keyRef loose ends. |
|
4225 |
public void endDocumentFragment() { |
|
4226 |
||
4227 |
// do all the necessary management... |
|
4228 |
super.endDocumentFragment(); |
|
4229 |
||
4230 |
// verify references |
|
4231 |
// get the key store corresponding (if it exists): |
|
4232 |
fKeyValueStore = |
|
4233 |
(ValueStoreBase) fValueStoreCache.fGlobalIDConstraintMap.get( |
|
4234 |
((KeyRef) fIdentityConstraint).getKey()); |
|
4235 |
||
4236 |
if (fKeyValueStore == null) { |
|
4237 |
// report error |
|
4238 |
String code = "KeyRefOutOfScope"; |
|
4239 |
String value = fIdentityConstraint.toString(); |
|
4240 |
reportSchemaError(code, new Object[] { value }); |
|
4241 |
return; |
|
4242 |
} |
|
4243 |
int errorIndex = fKeyValueStore.contains(this); |
|
4244 |
if (errorIndex != -1) { |
|
4245 |
String code = "KeyNotFound"; |
|
4246 |
String values = toString(fValues, errorIndex, fFieldCount); |
|
4247 |
String element = fIdentityConstraint.getElementName(); |
|
4248 |
String name = fIdentityConstraint.getName(); |
|
4249 |
reportSchemaError(code, new Object[] { name, values, element }); |
|
4250 |
} |
|
4251 |
||
4252 |
} // endDocumentFragment() |
|
4253 |
||
4254 |
/** End document. */ |
|
4255 |
public void endDocument() { |
|
4256 |
super.endDocument(); |
|
4257 |
||
4258 |
} // endDocument() |
|
4259 |
||
4260 |
} // class KeyRefValueStore |
|
4261 |
||
4262 |
// value store management |
|
4263 |
||
4264 |
/** |
|
4265 |
* Value store cache. This class is used to store the values for |
|
4266 |
* identity constraints. |
|
4267 |
* |
|
4268 |
* @author Andy Clark, IBM |
|
4269 |
*/ |
|
4270 |
protected class ValueStoreCache { |
|
4271 |
||
4272 |
// |
|
4273 |
// Data |
|
4274 |
// |
|
4275 |
final LocalIDKey fLocalId = new LocalIDKey(); |
|
4276 |
// values stores |
|
4277 |
||
4278 |
/** stores all global Values stores. */ |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
4279 |
protected final ArrayList fValueStores = new ArrayList(); |
12005 | 4280 |
|
4281 |
/** |
|
4282 |
* Values stores associated to specific identity constraints. |
|
33349 | 4283 |
* This map maps IdentityConstraints and |
12005 | 4284 |
* the 0-based element on which their selectors first matched to |
4285 |
* a corresponding ValueStore. This should take care |
|
4286 |
* of all cases, including where ID constraints with |
|
4287 |
* descendant-or-self axes occur on recursively-defined |
|
4288 |
* elements. |
|
4289 |
*/ |
|
33349 | 4290 |
protected final Map<LocalIDKey, ValueStoreBase> |
4291 |
fIdentityConstraint2ValueStoreMap = new HashMap<>(); |
|
12005 | 4292 |
|
4293 |
// sketch of algorithm: |
|
4294 |
// - when a constraint is first encountered, its |
|
4295 |
// values are stored in the (local) fIdentityConstraint2ValueStoreMap; |
|
4296 |
// - Once it is validated (i.e., when it goes out of scope), |
|
4297 |
// its values are merged into the fGlobalIDConstraintMap; |
|
4298 |
// - as we encounter keyref's, we look at the global table to |
|
4299 |
// validate them. |
|
4300 |
// |
|
4301 |
// The fGlobalIDMapStack has the following structure: |
|
4302 |
// - validation always occurs against the fGlobalIDConstraintMap |
|
4303 |
// (which comprises all the "eligible" id constraints); |
|
33349 | 4304 |
// When an endElement is found, this Map is merged with the one |
12005 | 4305 |
// below in the stack. |
4306 |
// When a start tag is encountered, we create a new |
|
4307 |
// fGlobalIDConstraintMap. |
|
4308 |
// i.e., the top of the fGlobalIDMapStack always contains |
|
4309 |
// the preceding siblings' eligible id constraints; |
|
4310 |
// the fGlobalIDConstraintMap contains descendants+self. |
|
4311 |
// keyrefs can only match descendants+self. |
|
33349 | 4312 |
protected final Stack<Map<IdentityConstraint, ValueStoreBase>> |
4313 |
fGlobalMapStack = new Stack<>(); |
|
4314 |
protected final Map<IdentityConstraint, ValueStoreBase> |
|
4315 |
fGlobalIDConstraintMap = new HashMap<>(); |
|
12005 | 4316 |
|
4317 |
// |
|
4318 |
// Constructors |
|
4319 |
// |
|
4320 |
||
4321 |
/** Default constructor. */ |
|
4322 |
public ValueStoreCache() { |
|
4323 |
} // <init>() |
|
4324 |
||
4325 |
// |
|
4326 |
// Public methods |
|
4327 |
// |
|
4328 |
||
4329 |
/** Resets the identity constraint cache. */ |
|
4330 |
public void startDocument() { |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
4331 |
fValueStores.clear(); |
12005 | 4332 |
fIdentityConstraint2ValueStoreMap.clear(); |
4333 |
fGlobalIDConstraintMap.clear(); |
|
4334 |
fGlobalMapStack.removeAllElements(); |
|
4335 |
} // startDocument() |
|
4336 |
||
4337 |
// startElement: pushes the current fGlobalIDConstraintMap |
|
4338 |
// onto fGlobalMapStack and clears fGlobalIDConstraint map. |
|
4339 |
public void startElement() { |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
4340 |
// only clone the map when there are elements |
12005 | 4341 |
if (fGlobalIDConstraintMap.size() > 0) |
33349 | 4342 |
fGlobalMapStack.push((Map<IdentityConstraint, ValueStoreBase>) |
4343 |
((HashMap)fGlobalIDConstraintMap).clone()); |
|
12005 | 4344 |
else |
4345 |
fGlobalMapStack.push(null); |
|
4346 |
fGlobalIDConstraintMap.clear(); |
|
4347 |
} // startElement(void) |
|
4348 |
||
4349 |
/** endElement(): merges contents of fGlobalIDConstraintMap with the |
|
4350 |
* top of fGlobalMapStack into fGlobalIDConstraintMap. |
|
4351 |
*/ |
|
4352 |
public void endElement() { |
|
4353 |
if (fGlobalMapStack.isEmpty()) { |
|
4354 |
return; // must be an invalid doc! |
|
4355 |
} |
|
33349 | 4356 |
Map<IdentityConstraint, ValueStoreBase> oldMap = fGlobalMapStack.pop(); |
12005 | 4357 |
// return if there is no element |
4358 |
if (oldMap == null) { |
|
4359 |
return; |
|
4360 |
} |
|
4361 |
||
33349 | 4362 |
for (Map.Entry<IdentityConstraint, ValueStoreBase> entry : oldMap.entrySet()) { |
4363 |
IdentityConstraint id = entry.getKey(); |
|
4364 |
ValueStoreBase oldVal = entry.getValue(); |
|
12005 | 4365 |
if (oldVal != null) { |
33349 | 4366 |
ValueStoreBase currVal = fGlobalIDConstraintMap.get(id); |
12005 | 4367 |
if (currVal == null) { |
4368 |
fGlobalIDConstraintMap.put(id, oldVal); |
|
4369 |
} |
|
4370 |
else if (currVal != oldVal) { |
|
4371 |
currVal.append(oldVal); |
|
4372 |
} |
|
4373 |
} |
|
4374 |
} |
|
4375 |
} // endElement() |
|
4376 |
||
4377 |
/** |
|
4378 |
* Initializes the value stores for the specified element |
|
4379 |
* declaration. |
|
4380 |
*/ |
|
4381 |
public void initValueStoresFor(XSElementDecl eDecl, FieldActivator activator) { |
|
4382 |
// initialize value stores for unique fields |
|
4383 |
IdentityConstraint[] icArray = eDecl.fIDConstraints; |
|
4384 |
int icCount = eDecl.fIDCPos; |
|
4385 |
for (int i = 0; i < icCount; i++) { |
|
4386 |
switch (icArray[i].getCategory()) { |
|
4387 |
case (IdentityConstraint.IC_UNIQUE) : |
|
4388 |
// initialize value stores for unique fields |
|
4389 |
UniqueOrKey unique = (UniqueOrKey) icArray[i]; |
|
4390 |
LocalIDKey toHash = new LocalIDKey(unique, fElementDepth); |
|
4391 |
UniqueValueStore uniqueValueStore = |
|
4392 |
(UniqueValueStore) fIdentityConstraint2ValueStoreMap.get(toHash); |
|
4393 |
if (uniqueValueStore == null) { |
|
4394 |
uniqueValueStore = new UniqueValueStore(unique); |
|
4395 |
fIdentityConstraint2ValueStoreMap.put(toHash, uniqueValueStore); |
|
4396 |
} else { |
|
4397 |
uniqueValueStore.clear(); |
|
4398 |
} |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
4399 |
fValueStores.add(uniqueValueStore); |
12005 | 4400 |
activateSelectorFor(icArray[i]); |
4401 |
break; |
|
4402 |
case (IdentityConstraint.IC_KEY) : |
|
4403 |
// initialize value stores for key fields |
|
4404 |
UniqueOrKey key = (UniqueOrKey) icArray[i]; |
|
4405 |
toHash = new LocalIDKey(key, fElementDepth); |
|
4406 |
KeyValueStore keyValueStore = |
|
4407 |
(KeyValueStore) fIdentityConstraint2ValueStoreMap.get(toHash); |
|
4408 |
if (keyValueStore == null) { |
|
4409 |
keyValueStore = new KeyValueStore(key); |
|
4410 |
fIdentityConstraint2ValueStoreMap.put(toHash, keyValueStore); |
|
4411 |
} else { |
|
4412 |
keyValueStore.clear(); |
|
4413 |
} |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
4414 |
fValueStores.add(keyValueStore); |
12005 | 4415 |
activateSelectorFor(icArray[i]); |
4416 |
break; |
|
4417 |
case (IdentityConstraint.IC_KEYREF) : |
|
4418 |
// initialize value stores for keyRef fields |
|
4419 |
KeyRef keyRef = (KeyRef) icArray[i]; |
|
4420 |
toHash = new LocalIDKey(keyRef, fElementDepth); |
|
4421 |
KeyRefValueStore keyRefValueStore = |
|
4422 |
(KeyRefValueStore) fIdentityConstraint2ValueStoreMap.get(toHash); |
|
4423 |
if (keyRefValueStore == null) { |
|
4424 |
keyRefValueStore = new KeyRefValueStore(keyRef, null); |
|
4425 |
fIdentityConstraint2ValueStoreMap.put(toHash, keyRefValueStore); |
|
4426 |
} else { |
|
4427 |
keyRefValueStore.clear(); |
|
4428 |
} |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
4429 |
fValueStores.add(keyRefValueStore); |
12005 | 4430 |
activateSelectorFor(icArray[i]); |
4431 |
break; |
|
4432 |
} |
|
4433 |
} |
|
4434 |
} // initValueStoresFor(XSElementDecl) |
|
4435 |
||
4436 |
/** Returns the value store associated to the specified IdentityConstraint. */ |
|
4437 |
public ValueStoreBase getValueStoreFor(IdentityConstraint id, int initialDepth) { |
|
4438 |
fLocalId.fDepth = initialDepth; |
|
4439 |
fLocalId.fId = id; |
|
33349 | 4440 |
return fIdentityConstraint2ValueStoreMap.get(fLocalId); |
12005 | 4441 |
} // getValueStoreFor(IdentityConstraint, int):ValueStoreBase |
4442 |
||
4443 |
/** Returns the global value store associated to the specified IdentityConstraint. */ |
|
4444 |
public ValueStoreBase getGlobalValueStoreFor(IdentityConstraint id) { |
|
33349 | 4445 |
return fGlobalIDConstraintMap.get(id); |
12005 | 4446 |
} // getValueStoreFor(IdentityConstraint):ValueStoreBase |
4447 |
||
4448 |
// This method takes the contents of the (local) ValueStore |
|
4449 |
// associated with id and moves them into the global |
|
33349 | 4450 |
// map, if id is a <unique> or a <key>. |
12005 | 4451 |
// If it's a <keyRef>, then we leave it for later. |
4452 |
public void transplant(IdentityConstraint id, int initialDepth) { |
|
4453 |
fLocalId.fDepth = initialDepth; |
|
4454 |
fLocalId.fId = id; |
|
33349 | 4455 |
ValueStoreBase newVals = fIdentityConstraint2ValueStoreMap.get(fLocalId); |
12005 | 4456 |
if (id.getCategory() == IdentityConstraint.IC_KEYREF) |
4457 |
return; |
|
33349 | 4458 |
ValueStoreBase currVals = fGlobalIDConstraintMap.get(id); |
12005 | 4459 |
if (currVals != null) { |
4460 |
currVals.append(newVals); |
|
4461 |
fGlobalIDConstraintMap.put(id, currVals); |
|
4462 |
} else |
|
4463 |
fGlobalIDConstraintMap.put(id, newVals); |
|
4464 |
||
4465 |
} // transplant(id) |
|
4466 |
||
4467 |
/** Check identity constraints. */ |
|
4468 |
public void endDocument() { |
|
4469 |
||
4470 |
int count = fValueStores.size(); |
|
4471 |
for (int i = 0; i < count; i++) { |
|
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
4472 |
ValueStoreBase valueStore = (ValueStoreBase) fValueStores.get(i); |
12005 | 4473 |
valueStore.endDocument(); |
4474 |
} |
|
4475 |
||
4476 |
} // endDocument() |
|
4477 |
||
4478 |
// |
|
4479 |
// Object methods |
|
4480 |
// |
|
4481 |
||
4482 |
/** Returns a string representation of this object. */ |
|
4483 |
public String toString() { |
|
4484 |
String s = super.toString(); |
|
4485 |
int index1 = s.lastIndexOf('$'); |
|
4486 |
if (index1 != -1) { |
|
4487 |
return s.substring(index1 + 1); |
|
4488 |
} |
|
4489 |
int index2 = s.lastIndexOf('.'); |
|
4490 |
if (index2 != -1) { |
|
4491 |
return s.substring(index2 + 1); |
|
4492 |
} |
|
4493 |
return s; |
|
4494 |
} // toString():String |
|
4495 |
||
4496 |
} // class ValueStoreCache |
|
4497 |
||
4498 |
// the purpose of this class is to enable IdentityConstraint,int |
|
33349 | 4499 |
// pairs to be used easily as keys in Maps. |
27111
7a491d709b83
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
26257
diff
changeset
|
4500 |
protected static final class LocalIDKey { |
12005 | 4501 |
|
4502 |
public IdentityConstraint fId; |
|
4503 |
public int fDepth; |
|
4504 |
||
4505 |
public LocalIDKey() { |
|
4506 |
} |
|
4507 |
||
4508 |
public LocalIDKey(IdentityConstraint id, int depth) { |
|
4509 |
fId = id; |
|
4510 |
fDepth = depth; |
|
4511 |
} // init(IdentityConstraint, int) |
|
4512 |
||
4513 |
// object method |
|
4514 |
public int hashCode() { |
|
4515 |
return fId.hashCode() + fDepth; |
|
4516 |
} |
|
4517 |
||
4518 |
public boolean equals(Object localIDKey) { |
|
4519 |
if (localIDKey instanceof LocalIDKey) { |
|
4520 |
LocalIDKey lIDKey = (LocalIDKey) localIDKey; |
|
4521 |
return (lIDKey.fId == fId && lIDKey.fDepth == fDepth); |
|
4522 |
} |
|
4523 |
return false; |
|
4524 |
} |
|
4525 |
} // class LocalIDKey |
|
4526 |
||
4527 |
/** |
|
4528 |
* A simple vector for <code>short</code>s. |
|
4529 |
*/ |
|
4530 |
protected static final class ShortVector { |
|
4531 |
||
4532 |
// |
|
4533 |
// Data |
|
4534 |
// |
|
4535 |
||
4536 |
/** Current length. */ |
|
4537 |
private int fLength; |
|
4538 |
||
4539 |
/** Data. */ |
|
4540 |
private short[] fData; |
|
4541 |
||
4542 |
// |
|
4543 |
// Constructors |
|
4544 |
// |
|
4545 |
||
4546 |
public ShortVector() {} |
|
4547 |
||
4548 |
public ShortVector(int initialCapacity) { |
|
4549 |
fData = new short[initialCapacity]; |
|
4550 |
} |
|
4551 |
||
4552 |
// |
|
4553 |
// Public methods |
|
4554 |
// |
|
4555 |
||
4556 |
/** Returns the length of the vector. */ |
|
4557 |
public int length() { |
|
4558 |
return fLength; |
|
4559 |
} |
|
4560 |
||
4561 |
/** Adds the value to the vector. */ |
|
4562 |
public void add(short value) { |
|
4563 |
ensureCapacity(fLength + 1); |
|
4564 |
fData[fLength++] = value; |
|
4565 |
} |
|
4566 |
||
4567 |
/** Returns the short value at the specified position in the vector. */ |
|
4568 |
public short valueAt(int position) { |
|
4569 |
return fData[position]; |
|
4570 |
} |
|
4571 |
||
4572 |
/** Clears the vector. */ |
|
4573 |
public void clear() { |
|
4574 |
fLength = 0; |
|
4575 |
} |
|
4576 |
||
4577 |
/** Returns whether the short is contained in the vector. */ |
|
4578 |
public boolean contains(short value) { |
|
4579 |
for (int i = 0; i < fLength; ++i) { |
|
4580 |
if (fData[i] == value) { |
|
4581 |
return true; |
|
4582 |
} |
|
4583 |
} |
|
4584 |
return false; |
|
4585 |
} |
|
4586 |
||
4587 |
// |
|
4588 |
// Private methods |
|
4589 |
// |
|
4590 |
||
4591 |
/** Ensures capacity. */ |
|
4592 |
private void ensureCapacity(int size) { |
|
4593 |
if (fData == null) { |
|
4594 |
fData = new short[8]; |
|
4595 |
} |
|
4596 |
else if (fData.length <= size) { |
|
4597 |
short[] newdata = new short[fData.length * 2]; |
|
4598 |
System.arraycopy(fData, 0, newdata, 0, fData.length); |
|
4599 |
fData = newdata; |
|
4600 |
} |
|
4601 |
} |
|
4602 |
} |
|
4603 |
||
4604 |
} // class SchemaValidator |