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