jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java
changeset 27111 7a491d709b83
parent 26257 4ec17c54acb3
child 33349 975138b77cff
equal deleted inserted replaced
26996:a137992d750c 27111:7a491d709b83
       
     1 /*
       
     2  * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
       
     3  */
     1 /*
     4 /*
     2  * Licensed to the Apache Software Foundation (ASF) under one or more
     5  * Licensed to the Apache Software Foundation (ASF) under one or more
     3  * contributor license agreements.  See the NOTICE file distributed with
     6  * contributor license agreements.  See the NOTICE file distributed with
     4  * this work for additional information regarding copyright ownership.
     7  * this work for additional information regarding copyright ownership.
     5  * The ASF licenses this file to You under the Apache License, Version 2.0
     8  * The ASF licenses this file to You under the Apache License, Version 2.0
    23 import java.util.Hashtable;
    26 import java.util.Hashtable;
    24 import java.util.Iterator;
    27 import java.util.Iterator;
    25 import java.util.Map;
    28 import java.util.Map;
    26 import java.util.Stack;
    29 import java.util.Stack;
    27 import java.util.Vector;
    30 import java.util.Vector;
    28 import java.util.ArrayList;
       
    29 import javax.xml.XMLConstants;
    31 import javax.xml.XMLConstants;
    30 import com.sun.org.apache.xerces.internal.impl.Constants;
    32 import com.sun.org.apache.xerces.internal.impl.Constants;
    31 import com.sun.org.apache.xerces.internal.impl.RevalidationHandler;
    33 import com.sun.org.apache.xerces.internal.impl.RevalidationHandler;
    32 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
    34 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager;
    33 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
    35 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
    34 import com.sun.org.apache.xerces.internal.impl.dv.DatatypeException;
    36 import com.sun.org.apache.xerces.internal.impl.dv.DatatypeException;
    35 import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException;
    37 import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException;
    36 import com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo;
    38 import com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo;
    37 import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;
    39 import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;
       
    40 import com.sun.org.apache.xerces.internal.impl.dv.xs.XSSimpleTypeDecl;
    38 import com.sun.org.apache.xerces.internal.impl.validation.ConfigurableValidationState;
    41 import com.sun.org.apache.xerces.internal.impl.validation.ConfigurableValidationState;
    39 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
    42 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
    40 import com.sun.org.apache.xerces.internal.impl.validation.ValidationState;
    43 import com.sun.org.apache.xerces.internal.impl.validation.ValidationState;
    41 import com.sun.org.apache.xerces.internal.impl.xs.identity.Field;
    44 import com.sun.org.apache.xerces.internal.impl.xs.identity.Field;
    42 import com.sun.org.apache.xerces.internal.impl.xs.identity.FieldActivator;
    45 import com.sun.org.apache.xerces.internal.impl.xs.identity.FieldActivator;
    47 import com.sun.org.apache.xerces.internal.impl.xs.identity.ValueStore;
    50 import com.sun.org.apache.xerces.internal.impl.xs.identity.ValueStore;
    48 import com.sun.org.apache.xerces.internal.impl.xs.identity.XPathMatcher;
    51 import com.sun.org.apache.xerces.internal.impl.xs.identity.XPathMatcher;
    49 import com.sun.org.apache.xerces.internal.impl.xs.models.CMBuilder;
    52 import com.sun.org.apache.xerces.internal.impl.xs.models.CMBuilder;
    50 import com.sun.org.apache.xerces.internal.impl.xs.models.CMNodeFactory;
    53 import com.sun.org.apache.xerces.internal.impl.xs.models.CMNodeFactory;
    51 import com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator;
    54 import com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator;
       
    55 import com.sun.org.apache.xerces.internal.impl.xs.util.XS10TypeHelper;
    52 import com.sun.org.apache.xerces.internal.util.AugmentationsImpl;
    56 import com.sun.org.apache.xerces.internal.util.AugmentationsImpl;
    53 import com.sun.org.apache.xerces.internal.util.IntStack;
    57 import com.sun.org.apache.xerces.internal.util.IntStack;
    54 import com.sun.org.apache.xerces.internal.util.SymbolTable;
    58 import com.sun.org.apache.xerces.internal.util.SymbolTable;
    55 import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl;
    59 import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl;
    56 import com.sun.org.apache.xerces.internal.util.XMLChar;
    60 import com.sun.org.apache.xerces.internal.util.XMLChar;
   105  * @author Elena Litani IBM
   109  * @author Elena Litani IBM
   106  * @author Andy Clark IBM
   110  * @author Andy Clark IBM
   107  * @author Neeraj Bajaj, Sun Microsystems, inc.
   111  * @author Neeraj Bajaj, Sun Microsystems, inc.
   108  */
   112  */
   109 public class XMLSchemaValidator
   113 public class XMLSchemaValidator
   110     implements XMLComponent, XMLDocumentFilter, FieldActivator, RevalidationHandler {
   114     implements XMLComponent, XMLDocumentFilter, FieldActivator, RevalidationHandler, XSElementDeclHelper {
   111 
   115 
   112     //
   116     //
   113     // Constants
   117     // Constants
   114     //
   118     //
   115     private static final boolean DEBUG = false;
   119     private static final boolean DEBUG = false;
   243         Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE;
   247         Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE;
   244 
   248 
   245     /** Property identifier: root type definition. */
   249     /** Property identifier: root type definition. */
   246     protected static final String ROOT_TYPE_DEF =
   250     protected static final String ROOT_TYPE_DEF =
   247         Constants.XERCES_PROPERTY_PREFIX + Constants.ROOT_TYPE_DEFINITION_PROPERTY;
   251         Constants.XERCES_PROPERTY_PREFIX + Constants.ROOT_TYPE_DEFINITION_PROPERTY;
       
   252 
       
   253     /** Property identifier: root element declaration. */
       
   254     protected static final String ROOT_ELEMENT_DECL =
       
   255         Constants.XERCES_PROPERTY_PREFIX + Constants.ROOT_ELEMENT_DECLARATION_PROPERTY;
   248 
   256 
   249     /** Property identifier: Schema DV Factory */
   257     /** Property identifier: Schema DV Factory */
   250     protected static final String SCHEMA_DV_FACTORY =
   258     protected static final String SCHEMA_DV_FACTORY =
   251         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY;
   259         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY;
   252 
   260 
   277             IDENTITY_CONSTRAINT_CHECKING,
   285             IDENTITY_CONSTRAINT_CHECKING,
   278             UNPARSED_ENTITY_CHECKING,
   286             UNPARSED_ENTITY_CHECKING,
   279             NAMESPACE_GROWTH,
   287             NAMESPACE_GROWTH,
   280             TOLERATE_DUPLICATES,
   288             TOLERATE_DUPLICATES,
   281             USE_SERVICE_MECHANISM
   289             USE_SERVICE_MECHANISM
   282     };
   290         };
   283 
   291 
   284     /** Feature defaults. */
   292     /** Feature defaults. */
   285     private static final Boolean[] FEATURE_DEFAULTS = { null,
   293     private static final Boolean[] FEATURE_DEFAULTS = { null,
   286         // NOTE: The following defaults are nulled out on purpose.
   294         // NOTE: The following defaults are nulled out on purpose.
   287         //       If they are set, then when the XML Schema validator
   295         //       If they are set, then when the XML Schema validator
   322             SCHEMA_LOCATION,
   330             SCHEMA_LOCATION,
   323             SCHEMA_NONS_LOCATION,
   331             SCHEMA_NONS_LOCATION,
   324             JAXP_SCHEMA_SOURCE,
   332             JAXP_SCHEMA_SOURCE,
   325             JAXP_SCHEMA_LANGUAGE,
   333             JAXP_SCHEMA_LANGUAGE,
   326             ROOT_TYPE_DEF,
   334             ROOT_TYPE_DEF,
       
   335             ROOT_ELEMENT_DECL,
   327             SCHEMA_DV_FACTORY,
   336             SCHEMA_DV_FACTORY,
   328             XML_SECURITY_PROPERTY_MANAGER
   337             XML_SECURITY_PROPERTY_MANAGER
   329             };
   338         };
   330 
   339 
   331     /** Property defaults. */
   340     /** Property defaults. */
   332     private static final Object[] PROPERTY_DEFAULTS =
   341     private static final Object[] PROPERTY_DEFAULTS =
   333         { null, null, null, null, null, null, null, null, null, null, null};
   342         { null, null, null, null, null, null, null, null, null, null, null, null};
   334 
   343 
   335     // this is the number of valuestores of each kind
   344     // this is the number of valuestores of each kind
   336     // we expect an element to have.  It's almost
   345     // we expect an element to have.  It's almost
   337     // never > 1; so leave it at that.
   346     // never > 1; so leave it at that.
   338     protected static final int ID_CONSTRAINT_NUM = 1;
   347     protected static final int ID_CONSTRAINT_NUM = 1;
       
   348 
       
   349     // xsi:* attribute declarations
       
   350     static final XSAttributeDecl XSI_TYPE = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_TYPE);
       
   351     static final XSAttributeDecl XSI_NIL = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NIL);
       
   352     static final XSAttributeDecl XSI_SCHEMALOCATION = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_SCHEMALOCATION);
       
   353     static final XSAttributeDecl XSI_NONAMESPACESCHEMALOCATION = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION);
   339 
   354 
   340     //
   355     //
   341     private static final Hashtable EMPTY_TABLE = new Hashtable();
   356     private static final Hashtable EMPTY_TABLE = new Hashtable();
   342 
   357 
   343     //
   358     //
   351     // Augmentations parameter if one is null, to save ourselves from
   366     // Augmentations parameter if one is null, to save ourselves from
   352     // having to create this object continually, it is created here.
   367     // having to create this object continually, it is created here.
   353     // If it is not present in calls that we're passing on, we *must*
   368     // If it is not present in calls that we're passing on, we *must*
   354     // clear this before we introduce it into the pipeline.
   369     // clear this before we introduce it into the pipeline.
   355     protected final AugmentationsImpl fAugmentations = new AugmentationsImpl();
   370     protected final AugmentationsImpl fAugmentations = new AugmentationsImpl();
   356 
       
   357     /**
       
   358      * Map which is used to catch instance documents that try
       
   359      * and match a field several times in the same scope.
       
   360      */
       
   361     protected final HashMap fMayMatchFieldMap = new HashMap();
       
   362 
   371 
   363     // this is included for the convenience of handleEndElement
   372     // this is included for the convenience of handleEndElement
   364     protected XMLString fDefaultValue;
   373     protected XMLString fDefaultValue;
   365 
   374 
   366     // Validation features
   375     // Validation features
   483             return errors;
   492             return errors;
   484         }
   493         }
   485 
   494 
   486         public void reportError(String domain, String key, Object[] arguments, short severity)
   495         public void reportError(String domain, String key, Object[] arguments, short severity)
   487             throws XNIException {
   496             throws XNIException {
   488             fErrorReporter.reportError(domain, key, arguments, severity);
   497             String message = fErrorReporter.reportError(domain, key, arguments, severity);
   489             if (fAugPSVI) {
   498             if (fAugPSVI) {
   490                 fErrors.addElement(key);
   499                 fErrors.addElement(key);
       
   500                 fErrors.addElement(message);
   491             }
   501             }
   492         } // reportError(String,String,Object[],short)
   502         } // reportError(String,String,Object[],short)
   493 
   503 
   494         public void reportError(
   504         public void reportError(
   495             XMLLocator location,
   505             XMLLocator location,
   496             String domain,
   506             String domain,
   497             String key,
   507             String key,
   498             Object[] arguments,
   508             Object[] arguments,
   499             short severity)
   509             short severity)
   500             throws XNIException {
   510             throws XNIException {
   501             fErrorReporter.reportError(location, domain, key, arguments, severity);
   511             String message = fErrorReporter.reportError(location, domain, key, arguments, severity);
   502             if (fAugPSVI) {
   512             if (fAugPSVI) {
   503                 fErrors.addElement(key);
   513                 fErrors.addElement(key);
       
   514                 fErrors.addElement(message);
   504             }
   515             }
   505         } // reportError(XMLLocator,String,String,Object[],short)
   516         } // reportError(XMLLocator,String,String,Object[],short)
   506     }
   517     }
   507 
   518 
   508     /** Error reporter. */
   519     /** Error reporter. */
   592      * @throws SAXNotSupportedException The component should not throw
   603      * @throws SAXNotSupportedException The component should not throw
   593      *                                  this exception.
   604      *                                  this exception.
   594      */
   605      */
   595     public void setProperty(String propertyId, Object value) throws XMLConfigurationException {
   606     public void setProperty(String propertyId, Object value) throws XMLConfigurationException {
   596         if (propertyId.equals(ROOT_TYPE_DEF)) {
   607         if (propertyId.equals(ROOT_TYPE_DEF)) {
   597             fRootTypeQName = (javax.xml.namespace.QName)value;
   608             if (value == null) {
       
   609                 fRootTypeQName = null;
       
   610                 fRootTypeDefinition = null;
       
   611             }
       
   612             else if (value instanceof javax.xml.namespace.QName) {
       
   613                 fRootTypeQName = (javax.xml.namespace.QName) value;
       
   614                 fRootTypeDefinition = null;
       
   615             }
       
   616             else {
       
   617                 fRootTypeDefinition = (XSTypeDefinition) value;
       
   618                 fRootTypeQName = null;
       
   619             }
       
   620         }
       
   621         else if (propertyId.equals(ROOT_ELEMENT_DECL)) {
       
   622             if (value == null) {
       
   623                 fRootElementDeclQName = null;
       
   624                 fRootElementDeclaration = null;
       
   625             }
       
   626             else if (value instanceof javax.xml.namespace.QName) {
       
   627                 fRootElementDeclQName = (javax.xml.namespace.QName) value;
       
   628                 fRootElementDeclaration = null;
       
   629             }
       
   630             else {
       
   631                 fRootElementDeclaration = (XSElementDecl) value;
       
   632                 fRootElementDeclQName = null;
       
   633             }
   598         }
   634         }
   599     } // setProperty(String,Object)
   635     } // setProperty(String,Object)
   600 
   636 
   601     /**
   637     /**
   602      * Returns the default state for a feature, or null if this
   638      * Returns the default state for a feature, or null if this
   866      * @param augs     Additional information that may include infoset augmentations
   902      * @param augs     Additional information that may include infoset augmentations
   867      *
   903      *
   868      * @throws XNIException Thrown by handler to signal an error.
   904      * @throws XNIException Thrown by handler to signal an error.
   869      */
   905      */
   870     public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException {
   906     public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException {
       
   907 
   871         handleIgnorableWhitespace(text);
   908         handleIgnorableWhitespace(text);
   872         // call handlers
   909         // call handlers
   873         if (fDocumentHandler != null) {
   910         if (fDocumentHandler != null) {
   874             fDocumentHandler.ignorableWhitespace(text, augs);
   911             fDocumentHandler.ignorableWhitespace(text, augs);
   875         }
   912         }
  1158     private short fWhiteSpace = -1; //whiteSpace: preserve/replace/collapse
  1195     private short fWhiteSpace = -1; //whiteSpace: preserve/replace/collapse
  1159     private boolean fUnionType = false;
  1196     private boolean fUnionType = false;
  1160 
  1197 
  1161     /** Schema grammar resolver. */
  1198     /** Schema grammar resolver. */
  1162     private final XSGrammarBucket fGrammarBucket = new XSGrammarBucket();
  1199     private final XSGrammarBucket fGrammarBucket = new XSGrammarBucket();
  1163     private final SubstitutionGroupHandler fSubGroupHandler = new SubstitutionGroupHandler(fGrammarBucket);
  1200     private final SubstitutionGroupHandler fSubGroupHandler = new SubstitutionGroupHandler(this);
  1164 
  1201 
  1165     /** the DV usd to convert xsi:type to a QName */
  1202     /** the DV usd to convert xsi:type to a QName */
  1166     // REVISIT: in new simple type design, make things in DVs static,
  1203     // REVISIT: in new simple type design, make things in DVs static,
  1167     //          so that we can QNameDV.getCompiledForm()
  1204     //          so that we can QNameDV.getCompiledForm()
  1168     private final XSSimpleType fQNameDV =
  1205     private final XSSimpleType fQNameDV =
  1246 
  1283 
  1247     /** strict assess stack */
  1284     /** strict assess stack */
  1248     private boolean[] fStrictAssessStack = new boolean[INITIAL_STACK_SIZE];
  1285     private boolean[] fStrictAssessStack = new boolean[INITIAL_STACK_SIZE];
  1249 
  1286 
  1250     /** Temporary string buffers. */
  1287     /** Temporary string buffers. */
  1251     private final StringBuffer fBuffer = new StringBuffer();
  1288     private final StringBuilder fBuffer = new StringBuilder();
  1252 
  1289 
  1253     /** Whether need to append characters to fBuffer */
  1290     /** Whether need to append characters to fBuffer */
  1254     private boolean fAppendBuffer = true;
  1291     private boolean fAppendBuffer = true;
  1255 
  1292 
  1256     /** Did we see any character data? */
  1293     /** Did we see any character data? */
  1266     private boolean[] fStringContent = new boolean[INITIAL_STACK_SIZE];
  1303     private boolean[] fStringContent = new boolean[INITIAL_STACK_SIZE];
  1267 
  1304 
  1268     /** temporary qname */
  1305     /** temporary qname */
  1269     private final QName fTempQName = new QName();
  1306     private final QName fTempQName = new QName();
  1270 
  1307 
       
  1308     /** value of the "root-type-definition" property. */
  1271     private javax.xml.namespace.QName fRootTypeQName = null;
  1309     private javax.xml.namespace.QName fRootTypeQName = null;
       
  1310     private XSTypeDefinition fRootTypeDefinition = null;
       
  1311 
       
  1312     /** value of the "root-element-declaration" property. */
       
  1313     private javax.xml.namespace.QName fRootElementDeclQName = null;
       
  1314     private XSElementDecl fRootElementDeclaration = null;
  1272 
  1315 
  1273     private int fIgnoreXSITypeDepth;
  1316     private int fIgnoreXSITypeDepth;
  1274 
  1317 
  1275     private boolean fIDCChecking;
  1318     private boolean fIDCChecking;
  1276 
  1319 
  1339         fLocationPairs.clear();
  1382         fLocationPairs.clear();
  1340 
  1383 
  1341         // cleanup id table
  1384         // cleanup id table
  1342         fValidationState.resetIDTables();
  1385         fValidationState.resetIDTables();
  1343 
  1386 
  1344         //pass the component manager to the factory..
       
  1345         nodeFactory.reset(componentManager);
       
  1346 
       
  1347         // reset schema loader
  1387         // reset schema loader
  1348         fSchemaLoader.reset(componentManager);
  1388         fSchemaLoader.reset(componentManager);
  1349 
  1389 
  1350         // initialize state
  1390         // initialize state
  1351         fCurrentElemDecl = null;
  1391         fCurrentElemDecl = null;
  1362         fEntityRef = false;
  1402         fEntityRef = false;
  1363         fInCDATA = false;
  1403         fInCDATA = false;
  1364 
  1404 
  1365         fMatcherStack.clear();
  1405         fMatcherStack.clear();
  1366 
  1406 
  1367         if (!fMayMatchFieldMap.isEmpty()) {
       
  1368             // should only clear this if the last schema had identity constraints.
       
  1369             fMayMatchFieldMap.clear();
       
  1370         }
       
  1371 
       
  1372         // get error reporter
  1407         // get error reporter
  1373         fXSIErrorReporter.reset((XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER));
  1408         fXSIErrorReporter.reset((XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER));
  1374 
  1409 
  1375         boolean parser_settings = componentManager.getFeature(PARSER_SETTINGS, true);
  1410         boolean parser_settings = componentManager.getFeature(PARSER_SETTINGS, true);
  1376 
  1411 
  1377         if (!parser_settings){
  1412         if (!parser_settings) {
  1378             // parser settings have not been changed
  1413             // parser settings have not been changed
  1379             fValidationManager.addValidationState(fValidationState);
  1414             fValidationManager.addValidationState(fValidationState);
       
  1415             // the node limit on the SecurityManager may have changed so need to refresh.
       
  1416             nodeFactory.reset();
  1380             // Re-parse external schema location properties.
  1417             // Re-parse external schema location properties.
  1381             XMLSchemaLoader.processExternalHints(
  1418             XMLSchemaLoader.processExternalHints(
  1382                 fExternalSchemas,
  1419                 fExternalSchemas,
  1383                 fExternalNoNamespaceSchema,
  1420                 fExternalNoNamespaceSchema,
  1384                 fLocationPairs,
  1421                 fLocationPairs,
  1385                 fXSIErrorReporter.fErrorReporter);
  1422                 fXSIErrorReporter.fErrorReporter);
  1386             return;
  1423             return;
  1387         }
  1424         }
  1388 
  1425 
       
  1426         // pass the component manager to the factory..
       
  1427         nodeFactory.reset(componentManager);
  1389 
  1428 
  1390         // get symbol table. if it's a new one, add symbols to it.
  1429         // get symbol table. if it's a new one, add symbols to it.
  1391         SymbolTable symbolTable = (SymbolTable) componentManager.getProperty(SYMBOL_TABLE);
  1430         SymbolTable symbolTable = (SymbolTable) componentManager.getProperty(SYMBOL_TABLE);
  1392         if (symbolTable != fSymbolTable) {
  1431         if (symbolTable != fSymbolTable) {
  1393             fSymbolTable = symbolTable;
  1432             fSymbolTable = symbolTable;
  1411         fSchemaElementDefault = componentManager.getFeature(SCHEMA_ELEMENT_DEFAULT, false);
  1450         fSchemaElementDefault = componentManager.getFeature(SCHEMA_ELEMENT_DEFAULT, false);
  1412 
  1451 
  1413         fAugPSVI = componentManager.getFeature(SCHEMA_AUGMENT_PSVI, true);
  1452         fAugPSVI = componentManager.getFeature(SCHEMA_AUGMENT_PSVI, true);
  1414 
  1453 
  1415         fSchemaType =
  1454         fSchemaType =
  1416                 (String) componentManager.getProperty(
  1455             (String) componentManager.getProperty(
  1417                     Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, null);
  1456                 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, null);
  1418 
  1457 
  1419         fUseGrammarPoolOnly = componentManager.getFeature(USE_GRAMMAR_POOL_ONLY, false);
  1458         fUseGrammarPoolOnly = componentManager.getFeature(USE_GRAMMAR_POOL_ONLY, false);
  1420 
  1459 
  1421         fEntityResolver = (XMLEntityResolver) componentManager.getProperty(ENTITY_MANAGER);
  1460         fEntityResolver = (XMLEntityResolver) componentManager.getProperty(ENTITY_MANAGER);
  1422 
  1461 
  1423         fValidationManager = (ValidationManager) componentManager.getProperty(VALIDATION_MANAGER);
  1462         fValidationManager = (ValidationManager) componentManager.getProperty(VALIDATION_MANAGER);
  1424         fValidationManager.addValidationState(fValidationState);
  1463         fValidationManager.addValidationState(fValidationState);
  1425         fValidationState.setSymbolTable(fSymbolTable);
  1464         fValidationState.setSymbolTable(fSymbolTable);
  1426 
  1465 
  1427         boolean ignoreXSIType;
       
  1428         try {
  1466         try {
  1429             ignoreXSIType = componentManager.getFeature(IGNORE_XSI_TYPE);
  1467             final Object rootType = componentManager.getProperty(ROOT_TYPE_DEF);
       
  1468             if (rootType == null) {
       
  1469                 fRootTypeQName = null;
       
  1470                 fRootTypeDefinition = null;
       
  1471             }
       
  1472             else if (rootType instanceof javax.xml.namespace.QName) {
       
  1473                 fRootTypeQName = (javax.xml.namespace.QName) rootType;
       
  1474                 fRootTypeDefinition = null;
       
  1475             }
       
  1476             else {
       
  1477                 fRootTypeDefinition = (XSTypeDefinition) rootType;
       
  1478                 fRootTypeQName = null;
       
  1479             }
  1430         }
  1480         }
  1431         catch (XMLConfigurationException e) {
  1481         catch (XMLConfigurationException e) {
  1432             ignoreXSIType = false;
  1482             fRootTypeQName = null;
  1433         }
  1483             fRootTypeDefinition = null;
       
  1484         }
       
  1485 
       
  1486         try {
       
  1487             final Object rootDecl = componentManager.getProperty(ROOT_ELEMENT_DECL);
       
  1488             if (rootDecl == null) {
       
  1489                 fRootElementDeclQName = null;
       
  1490                 fRootElementDeclaration = null;
       
  1491             }
       
  1492             else if (rootDecl instanceof javax.xml.namespace.QName) {
       
  1493                 fRootElementDeclQName = (javax.xml.namespace.QName) rootDecl;
       
  1494                 fRootElementDeclaration = null;
       
  1495             }
       
  1496             else {
       
  1497                 fRootElementDeclaration = (XSElementDecl) rootDecl;
       
  1498                 fRootElementDeclQName = null;
       
  1499             }
       
  1500         }
       
  1501         catch (XMLConfigurationException e) {
       
  1502             fRootElementDeclQName = null;
       
  1503             fRootElementDeclaration = null;
       
  1504         }
       
  1505 
       
  1506         boolean ignoreXSIType = componentManager.getFeature(IGNORE_XSI_TYPE, false);
       
  1507 
  1434         // An initial value of -1 means that the root element considers itself
  1508         // An initial value of -1 means that the root element considers itself
  1435         // below the depth where xsi:type stopped being ignored (which means that
  1509         // below the depth where xsi:type stopped being ignored (which means that
  1436         // xsi:type attributes will not be ignored for the entire document)
  1510         // xsi:type attributes will not be ignored for the entire document)
  1437         fIgnoreXSITypeDepth = ignoreXSIType ? 0 : -1;
  1511         fIgnoreXSITypeDepth = ignoreXSIType ? 0 : -1;
  1438 
  1512 
  1513      * @param field The field to activate.
  1587      * @param field The field to activate.
  1514      */
  1588      */
  1515     public XPathMatcher activateField(Field field, int initialDepth) {
  1589     public XPathMatcher activateField(Field field, int initialDepth) {
  1516         ValueStore valueStore =
  1590         ValueStore valueStore =
  1517             fValueStoreCache.getValueStoreFor(field.getIdentityConstraint(), initialDepth);
  1591             fValueStoreCache.getValueStoreFor(field.getIdentityConstraint(), initialDepth);
  1518         setMayMatch(field, Boolean.TRUE);
  1592         XPathMatcher matcher = field.createMatcher(valueStore);
  1519         XPathMatcher matcher = field.createMatcher(this, valueStore);
       
  1520         fMatcherStack.addMatcher(matcher);
  1593         fMatcherStack.addMatcher(matcher);
  1521         matcher.startDocumentFragment();
  1594         matcher.startDocumentFragment();
  1522         return matcher;
  1595         return matcher;
  1523     } // activateField(Field):XPathMatcher
  1596     } // activateField(Field):XPathMatcher
  1524 
  1597 
  1532         ValueStoreBase valueStore =
  1605         ValueStoreBase valueStore =
  1533             fValueStoreCache.getValueStoreFor(identityConstraint, initialDepth);
  1606             fValueStoreCache.getValueStoreFor(identityConstraint, initialDepth);
  1534         valueStore.endValueScope();
  1607         valueStore.endValueScope();
  1535 
  1608 
  1536     } // endValueScopeFor(IdentityConstraint)
  1609     } // endValueScopeFor(IdentityConstraint)
  1537 
       
  1538     /**
       
  1539      * Sets whether the given field is permitted to match a value.
       
  1540      * This should be used to catch instance documents that try
       
  1541      * and match a field several times in the same scope.
       
  1542      *
       
  1543      * @param field The field that may be permitted to be matched.
       
  1544      * @param state Boolean indiciating whether the field may be matched.
       
  1545      */
       
  1546     public void setMayMatch(Field field, Boolean state) {
       
  1547         fMayMatchFieldMap.put(field, state);
       
  1548     } // setMayMatch(Field, Boolean)
       
  1549 
       
  1550     /**
       
  1551      * Returns whether the given field is permitted to match a value.
       
  1552      *
       
  1553      * @param field The field that may be permitted to be matched.
       
  1554      * @return Boolean indicating whether the field may be matched.
       
  1555      */
       
  1556     public Boolean mayMatch(Field field) {
       
  1557         return (Boolean) fMayMatchFieldMap.get(field);
       
  1558     } // mayMatch(Field):Boolean
       
  1559 
  1610 
  1560     // a utility method for Identity constraints
  1611     // a utility method for Identity constraints
  1561     private void activateSelectorFor(IdentityConstraint ic) {
  1612     private void activateSelectorFor(IdentityConstraint ic) {
  1562         Selector selector = ic.getSelector();
  1613         Selector selector = ic.getSelector();
  1563         FieldActivator activator = this;
  1614         FieldActivator activator = this;
  1564         if (selector == null)
  1615         if (selector == null)
  1565             return;
  1616             return;
  1566         XPathMatcher matcher = selector.createMatcher(activator, fElementDepth);
  1617         XPathMatcher matcher = selector.createMatcher(activator, fElementDepth);
  1567         fMatcherStack.addMatcher(matcher);
  1618         fMatcherStack.addMatcher(matcher);
  1568         matcher.startDocumentFragment();
  1619         matcher.startDocumentFragment();
       
  1620     }
       
  1621 
       
  1622     // Implements XSElementDeclHelper interface
       
  1623     public XSElementDecl getGlobalElementDecl(QName element) {
       
  1624         final SchemaGrammar sGrammar =
       
  1625             findSchemaGrammar(
       
  1626                 XSDDescription.CONTEXT_ELEMENT,
       
  1627                 element.uri,
       
  1628                 null,
       
  1629                 element,
       
  1630                 null);
       
  1631         if (sGrammar != null) {
       
  1632             return sGrammar.getGlobalElementDecl(element.localpart);
       
  1633         }
       
  1634         return null;
  1569     }
  1635     }
  1570 
  1636 
  1571     //
  1637     //
  1572     // Protected methods
  1638     // Protected methods
  1573     //
  1639     //
  1821             }
  1887             }
  1822 
  1888 
  1823         }
  1889         }
  1824 
  1890 
  1825         // get xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes,
  1891         // get xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes,
  1826         // parse them to get the grammars
  1892         // parse them to get the grammars. But only do this if the grammar can grow.
  1827 
  1893         if (!fUseGrammarPoolOnly) {
  1828         String sLocation =
  1894             String sLocation =
  1829             attributes.getValue(SchemaSymbols.URI_XSI, SchemaSymbols.XSI_SCHEMALOCATION);
  1895                 attributes.getValue(SchemaSymbols.URI_XSI, SchemaSymbols.XSI_SCHEMALOCATION);
  1830         String nsLocation =
  1896             String nsLocation =
  1831             attributes.getValue(SchemaSymbols.URI_XSI, SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION);
  1897                 attributes.getValue(SchemaSymbols.URI_XSI, SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION);
  1832         //store the location hints..  we need to do it so that we can defer the loading of grammar until
  1898             //store the location hints..  we need to do it so that we can defer the loading of grammar until
  1833         //there is a reference to a component from that namespace. To provide location hints to the
  1899             //there is a reference to a component from that namespace. To provide location hints to the
  1834         //application for a namespace
  1900             //application for a namespace
  1835         storeLocations(sLocation, nsLocation);
  1901             storeLocations(sLocation, nsLocation);
       
  1902         }
  1836 
  1903 
  1837         // if we are in the content of "skip", then just skip this element
  1904         // if we are in the content of "skip", then just skip this element
  1838         // REVISIT:  is this the correct behaviour for ID constraints?  -NG
  1905         // REVISIT:  is this the correct behaviour for ID constraints?  -NG
  1839         if (fSkipValidationDepth >= 0) {
  1906         if (fSkipValidationDepth >= 0) {
  1840             fElementDepth++;
  1907             fElementDepth++;
  1841             if (fAugPSVI)
  1908             if (fAugPSVI)
  1842                 augs = getEmptyAugs(augs);
  1909                 augs = getEmptyAugs(augs);
  1843             return augs;
  1910             return augs;
  1844         }
  1911         }
  1845 
       
  1846         //try to find schema grammar by different means..
       
  1847         SchemaGrammar sGrammar =
       
  1848             findSchemaGrammar(
       
  1849                 XSDDescription.CONTEXT_ELEMENT,
       
  1850                 element.uri,
       
  1851                 null,
       
  1852                 element,
       
  1853                 attributes);
       
  1854 
  1912 
  1855         // if we are not skipping this element, and there is a content model,
  1913         // if we are not skipping this element, and there is a content model,
  1856         // we try to find the corresponding decl object for this element.
  1914         // we try to find the corresponding decl object for this element.
  1857         // the reason we move this part of code here is to make sure the
  1915         // the reason we move this part of code here is to make sure the
  1858         // error reported here (if any) is stored within the parent element's
  1916         // error reported here (if any) is stored within the parent element's
  1862             decl = fCurrentCM.oneTransition(element, fCurrCMState, fSubGroupHandler);
  1920             decl = fCurrentCM.oneTransition(element, fCurrCMState, fSubGroupHandler);
  1863             // it could be an element decl or a wildcard decl
  1921             // it could be an element decl or a wildcard decl
  1864             if (fCurrCMState[0] == XSCMValidator.FIRST_ERROR) {
  1922             if (fCurrCMState[0] == XSCMValidator.FIRST_ERROR) {
  1865                 XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType;
  1923                 XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType;
  1866                 //REVISIT: is it the only case we will have particle = null?
  1924                 //REVISIT: is it the only case we will have particle = null?
  1867                 Vector next;
  1925                 ArrayList next;
  1868                 if (ctype.fParticle != null
  1926                 if (ctype.fParticle != null
  1869                     && (next = fCurrentCM.whatCanGoHere(fCurrCMState)).size() > 0) {
  1927                     && (next = fCurrentCM.whatCanGoHere(fCurrCMState)).size() > 0) {
  1870                     String expected = expectedStr(next);
  1928                     String expected = expectedStr(next);
  1871                     reportSchemaError(
  1929                     final int[] occurenceInfo = fCurrentCM.occurenceInfo(fCurrCMState);
  1872                         "cvc-complex-type.2.4.a",
  1930                     String elemExpandedQname = (element.uri != null) ? "{"+'"'+element.uri+'"'+":"+element.localpart+"}" : element.localpart;
  1873                         new Object[] { element.rawname, expected });
  1931                     if (occurenceInfo != null) {
  1874                 } else {
  1932                         final int minOccurs = occurenceInfo[0];
  1875                     reportSchemaError("cvc-complex-type.2.4.d", new Object[] { element.rawname });
  1933                         final int maxOccurs = occurenceInfo[1];
       
  1934                         final int count = occurenceInfo[2];
       
  1935                         // Check if this is a violation of minOccurs
       
  1936                         if (count < minOccurs) {
       
  1937                             final int required = minOccurs - count;
       
  1938                             if (required > 1) {
       
  1939                                 reportSchemaError("cvc-complex-type.2.4.h", new Object[] { element.rawname,
       
  1940                                         fCurrentCM.getTermName(occurenceInfo[3]), Integer.toString(minOccurs), Integer.toString(required) });
       
  1941                             }
       
  1942                             else {
       
  1943                                 reportSchemaError("cvc-complex-type.2.4.g", new Object[] { element.rawname,
       
  1944                                         fCurrentCM.getTermName(occurenceInfo[3]), Integer.toString(minOccurs) });
       
  1945                             }
       
  1946                         }
       
  1947                         // Check if this is a violation of maxOccurs
       
  1948                         else if (count >= maxOccurs && maxOccurs != SchemaSymbols.OCCURRENCE_UNBOUNDED) {
       
  1949                             reportSchemaError("cvc-complex-type.2.4.e", new Object[] { element.rawname,
       
  1950                                     expected, Integer.toString(maxOccurs) });
       
  1951                         }
       
  1952                         else {
       
  1953                             reportSchemaError("cvc-complex-type.2.4.a", new Object[] { elemExpandedQname, expected });
       
  1954                         }
       
  1955                     }
       
  1956                     else {
       
  1957                         reportSchemaError("cvc-complex-type.2.4.a", new Object[] { elemExpandedQname, expected });
       
  1958                     }
       
  1959                 }
       
  1960                 else {
       
  1961                     final int[] occurenceInfo = fCurrentCM.occurenceInfo(fCurrCMState);
       
  1962                     if (occurenceInfo != null) {
       
  1963                         final int maxOccurs = occurenceInfo[1];
       
  1964                         final int count = occurenceInfo[2];
       
  1965                         // Check if this is a violation of maxOccurs
       
  1966                         if (count >= maxOccurs && maxOccurs != SchemaSymbols.OCCURRENCE_UNBOUNDED) {
       
  1967                             reportSchemaError("cvc-complex-type.2.4.f", new Object[] { fCurrentCM.getTermName(occurenceInfo[3]), Integer.toString(maxOccurs) });
       
  1968                         }
       
  1969                         else {
       
  1970                             reportSchemaError("cvc-complex-type.2.4.d", new Object[] { element.rawname });
       
  1971                         }
       
  1972                     }
       
  1973                     else {
       
  1974                         reportSchemaError("cvc-complex-type.2.4.d", new Object[] { element.rawname });
       
  1975                     }
  1876                 }
  1976                 }
  1877             }
  1977             }
  1878         }
  1978         }
  1879 
  1979 
  1880         // if it's not the root element, we push the current states in the stacks
  1980         // if it's not the root element, we push the current states in the stacks
  1924             if (fAugPSVI)
  2024             if (fAugPSVI)
  1925                 augs = getEmptyAugs(augs);
  2025                 augs = getEmptyAugs(augs);
  1926             return augs;
  2026             return augs;
  1927         }
  2027         }
  1928 
  2028 
  1929         // 1.2.1.1 A type definition was stipulated by the processor
  2029         if (fElementDepth == 0) {
  1930         if (fElementDepth == 0 && fRootTypeQName != null) {
  2030             // 1.1.1.1 An element declaration was stipulated by the processor
  1931             String rootTypeNamespace = fRootTypeQName.getNamespaceURI();
  2031             if (fRootElementDeclaration != null) {
  1932             if (rootTypeNamespace != null && rootTypeNamespace.equals(XMLConstants.NULL_NS_URI)) {
  2032                 fCurrentElemDecl = fRootElementDeclaration;
  1933                 rootTypeNamespace = null;
  2033                 checkElementMatchesRootElementDecl(fCurrentElemDecl, element);
  1934             }
  2034             }
  1935             SchemaGrammar grammarForRootType =
  2035             else if (fRootElementDeclQName != null) {
  1936                 findSchemaGrammar(
  2036                 processRootElementDeclQName(fRootElementDeclQName, element);
  1937                         XSDDescription.CONTEXT_ELEMENT, rootTypeNamespace, null, null, null);
  2037             }
  1938             if (grammarForRootType != null) {
  2038             // 1.2.1.1 A type definition was stipulated by the processor
  1939                 fCurrentType = grammarForRootType.getGlobalTypeDecl(fRootTypeQName.getLocalPart());
  2039             else if (fRootTypeDefinition != null) {
  1940             }
  2040                 fCurrentType = fRootTypeDefinition;
  1941             if (fCurrentType == null) {
  2041             }
  1942                 String typeName = (fRootTypeQName.getPrefix().equals(XMLConstants.DEFAULT_NS_PREFIX)) ?
  2042             else if (fRootTypeQName != null) {
  1943                         fRootTypeQName.getLocalPart() :
  2043                 processRootTypeQName(fRootTypeQName);
  1944                             fRootTypeQName.getPrefix()+":"+fRootTypeQName.getLocalPart();
       
  1945                         reportSchemaError("cvc-type.1", new Object[] {typeName});
       
  1946             }
  2044             }
  1947         }
  2045         }
  1948 
  2046 
  1949         // if there was no processor stipulated type
  2047         // if there was no processor stipulated type
  1950         if (fCurrentType == null) {
  2048         if (fCurrentType == null) {
  1951             // try again to get the element decl:
  2049             // try again to get the element decl:
  1952             // case 1: find declaration for root element
  2050             // case 1: find declaration for root element
  1953             // case 2: find declaration for element from another namespace
  2051             // case 2: find declaration for element from another namespace
  1954             if (fCurrentElemDecl == null) {
  2052             if (fCurrentElemDecl == null) {
       
  2053                 // try to find schema grammar by different means..
       
  2054                 SchemaGrammar sGrammar =
       
  2055                     findSchemaGrammar(
       
  2056                         XSDDescription.CONTEXT_ELEMENT,
       
  2057                         element.uri,
       
  2058                         null,
       
  2059                         element,
       
  2060                         attributes);
  1955                 if (sGrammar != null) {
  2061                 if (sGrammar != null) {
  1956                     fCurrentElemDecl = sGrammar.getGlobalElementDecl(element.localpart);
  2062                     fCurrentElemDecl = sGrammar.getGlobalElementDecl(element.localpart);
  1957                 }
  2063                 }
  1958             }
  2064             }
  1959 
  2065 
  1960             if (fCurrentElemDecl != null) {
  2066             if (fCurrentElemDecl != null) {
  1961                 // then get the type
  2067                 // then get the type
  1962                 fCurrentType = fCurrentElemDecl.fType;
  2068                 fCurrentType = fCurrentElemDecl.fType;
  1963             }
  2069             }
  1964         }
  2070         }
  1965 
       
  1966 
  2071 
  1967         // check if we should be ignoring xsi:type on this element
  2072         // check if we should be ignoring xsi:type on this element
  1968         if (fElementDepth == fIgnoreXSITypeDepth && fCurrentElemDecl == null) {
  2073         if (fElementDepth == fIgnoreXSITypeDepth && fCurrentElemDecl == null) {
  1969             fIgnoreXSITypeDepth++;
  2074             fIgnoreXSITypeDepth++;
  1970         }
  2075         }
  2010                 // reporting it as an error for historical reasons, but in
  2115                 // reporting it as an error for historical reasons, but in
  2011                 // PSVI, we shouldn't mark this element as invalid because
  2116                 // PSVI, we shouldn't mark this element as invalid because
  2012                 // of this. - SG
  2117                 // of this. - SG
  2013                 fXSIErrorReporter.fErrorReporter.reportError(
  2118                 fXSIErrorReporter.fErrorReporter.reportError(
  2014                     XSMessageFormatter.SCHEMA_DOMAIN,
  2119                     XSMessageFormatter.SCHEMA_DOMAIN,
  2015                     "cvc-elt.1",
  2120                     "cvc-elt.1.a",
  2016                     new Object[] { element.rawname },
  2121                     new Object[] { element.rawname },
  2017                     XMLErrorReporter.SEVERITY_ERROR);
  2122                     XMLErrorReporter.SEVERITY_ERROR);
  2018             }
  2123             }
  2019             // if wildcard = strict, report error.
  2124             // if wildcard = strict, report error.
  2020             // needs to be called before fXSIErrorReporter.pushContext()
  2125             // needs to be called before fXSIErrorReporter.pushContext()
  2187             fCurrentPSVI.fDeclaration = fCurrentElemDecl;
  2292             fCurrentPSVI.fDeclaration = fCurrentElemDecl;
  2188             // PSVI: add element type
  2293             // PSVI: add element type
  2189             fCurrentPSVI.fTypeDecl = fCurrentType;
  2294             fCurrentPSVI.fTypeDecl = fCurrentType;
  2190             // PSVI: add notation attribute
  2295             // PSVI: add notation attribute
  2191             fCurrentPSVI.fNotation = fNotation;
  2296             fCurrentPSVI.fNotation = fNotation;
       
  2297             // PSVI: add nil
       
  2298             fCurrentPSVI.fNil = fNil;
  2192         }
  2299         }
  2193 
  2300 
  2194         return augs;
  2301         return augs;
  2195 
  2302 
  2196     } // handleStartElement(QName,XMLAttributes,boolean)
  2303     } // handleStartElement(QName,XMLAttributes,boolean)
  2232             // PSVI: validation attempted:
  2339             // PSVI: validation attempted:
  2233             // use default values in psvi item for
  2340             // use default values in psvi item for
  2234             // validation attempted, validity, and error codes
  2341             // validation attempted, validity, and error codes
  2235 
  2342 
  2236             // check extra schema constraints on root element
  2343             // check extra schema constraints on root element
  2237             if (fElementDepth == -1 && fFullChecking) {
  2344             if (fElementDepth == -1 && fFullChecking && !fUseGrammarPoolOnly) {
  2238                 XSConstraints.fullSchemaChecking(
  2345                 XSConstraints.fullSchemaChecking(
  2239                     fGrammarBucket,
  2346                     fGrammarBucket,
  2240                     fSubGroupHandler,
  2347                     fSubGroupHandler,
  2241                     fCMBuilder,
  2348                     fCMBuilder,
  2242                     fXSIErrorReporter.fErrorReporter);
  2349                     fXSIErrorReporter.fErrorReporter);
  2256 
  2363 
  2257             // call matchers and de-activate context
  2364             // call matchers and de-activate context
  2258             int oldCount = fMatcherStack.getMatcherCount();
  2365             int oldCount = fMatcherStack.getMatcherCount();
  2259             for (int i = oldCount - 1; i >= 0; i--) {
  2366             for (int i = oldCount - 1; i >= 0; i--) {
  2260                 XPathMatcher matcher = fMatcherStack.getMatcherAt(i);
  2367                 XPathMatcher matcher = fMatcherStack.getMatcherAt(i);
  2261                 if (fCurrentElemDecl == null)
  2368                 if (fCurrentElemDecl == null) {
  2262                     matcher.endElement(element, null, false, fValidatedInfo.actualValue, fValidatedInfo.actualValueType, fValidatedInfo.itemValueTypes);
  2369                     matcher.endElement(element, fCurrentType, false, fValidatedInfo.actualValue, fValidatedInfo.actualValueType, fValidatedInfo.itemValueTypes);
  2263 
  2370                 }
  2264                 else
  2371                 else {
  2265                     matcher.endElement(
  2372                     matcher.endElement(
  2266                             element,
  2373                             element,
  2267                             fCurrentType,
  2374                             fCurrentType,
  2268                             fCurrentElemDecl.getNillable(),
  2375                             fCurrentElemDecl.getNillable(),
  2269                             fDefaultValue == null
  2376                             fDefaultValue == null
  2273                                 ? fValidatedInfo.actualValueType
  2380                                 ? fValidatedInfo.actualValueType
  2274                                 : fCurrentElemDecl.fDefault.actualValueType,
  2381                                 : fCurrentElemDecl.fDefault.actualValueType,
  2275                             fDefaultValue == null
  2382                             fDefaultValue == null
  2276                                 ? fValidatedInfo.itemValueTypes
  2383                                 ? fValidatedInfo.itemValueTypes
  2277                                 : fCurrentElemDecl.fDefault.itemValueTypes);
  2384                                 : fCurrentElemDecl.fDefault.itemValueTypes);
       
  2385                 }
  2278             }
  2386             }
  2279 
  2387 
  2280             if (fMatcherStack.size() > 0) {
  2388             if (fMatcherStack.size() > 0) {
  2281                 fMatcherStack.popContext();
  2389                 fMatcherStack.popContext();
  2282             }
  2390             }
  2303                     IdentityConstraint id;
  2411                     IdentityConstraint id;
  2304                     if ((id = selMatcher.getIdentityConstraint()) != null
  2412                     if ((id = selMatcher.getIdentityConstraint()) != null
  2305                             && id.getCategory() == IdentityConstraint.IC_KEYREF) {
  2413                             && id.getCategory() == IdentityConstraint.IC_KEYREF) {
  2306                         ValueStoreBase values =
  2414                         ValueStoreBase values =
  2307                             fValueStoreCache.getValueStoreFor(id, selMatcher.getInitialDepth());
  2415                             fValueStoreCache.getValueStoreFor(id, selMatcher.getInitialDepth());
  2308                         if (values != null) // nothing to do if nothing matched!
  2416                         // nothing to do if nothing matched, or if not all
       
  2417                         // fields are present.
       
  2418                         if (values != null && values.fValuesCount == values.fFieldCount)
  2309                             values.endDocumentFragment();
  2419                             values.endDocumentFragment();
  2310                     }
  2420                     }
  2311                 }
  2421                 }
  2312             }
  2422             }
  2313             fValueStoreCache.endElement();
  2423             fValueStoreCache.endElement();
  2322 
  2432 
  2323         SchemaGrammar[] grammars = null;
  2433         SchemaGrammar[] grammars = null;
  2324         // have we reached the end tag of the validation root?
  2434         // have we reached the end tag of the validation root?
  2325         if (fElementDepth == 0) {
  2435         if (fElementDepth == 0) {
  2326             // 7 If the element information item is the validation root, it must be valid per Validation Root Valid (ID/IDREF) (3.3.4).
  2436             // 7 If the element information item is the validation root, it must be valid per Validation Root Valid (ID/IDREF) (3.3.4).
  2327             String invIdRef = fValidationState.checkIDRefID();
  2437             Iterator invIdRefs = fValidationState.checkIDRefID();
  2328             fValidationState.resetIDTables();
  2438             fValidationState.resetIDTables();
  2329             if (invIdRef != null) {
  2439             if (invIdRefs != null) {
  2330                 reportSchemaError("cvc-id.1", new Object[] { invIdRef });
  2440                 while (invIdRefs.hasNext()) {
       
  2441                     reportSchemaError("cvc-id.1", new Object[] { invIdRefs.next() });
       
  2442                 }
  2331             }
  2443             }
  2332             // check extra schema constraints
  2444             // check extra schema constraints
  2333             if (fFullChecking) {
  2445             if (fFullChecking && !fUseGrammarPoolOnly) {
  2334                 XSConstraints.fullSchemaChecking(
  2446                 XSConstraints.fullSchemaChecking(
  2335                     fGrammarBucket,
  2447                     fGrammarBucket,
  2336                     fSubGroupHandler,
  2448                     fSubGroupHandler,
  2337                     fCMBuilder,
  2449                     fCMBuilder,
  2338                     fXSIErrorReporter.fErrorReporter);
  2450                     fXSIErrorReporter.fErrorReporter);
  2388         Augmentations augs) {
  2500         Augmentations augs) {
  2389 
  2501 
  2390         if (fAugPSVI) {
  2502         if (fAugPSVI) {
  2391             augs = getEmptyAugs(augs);
  2503             augs = getEmptyAugs(augs);
  2392 
  2504 
  2393             // the 4 properties sent on startElement calls
  2505             // the 5 properties sent on startElement calls
  2394             fCurrentPSVI.fDeclaration = this.fCurrentElemDecl;
  2506             fCurrentPSVI.fDeclaration = this.fCurrentElemDecl;
  2395             fCurrentPSVI.fTypeDecl = this.fCurrentType;
  2507             fCurrentPSVI.fTypeDecl = this.fCurrentType;
  2396             fCurrentPSVI.fNotation = this.fNotation;
  2508             fCurrentPSVI.fNotation = this.fNotation;
  2397             fCurrentPSVI.fValidationContext = this.fValidationRoot;
  2509             fCurrentPSVI.fValidationContext = this.fValidationRoot;
       
  2510             fCurrentPSVI.fNil = this.fNil;
  2398             // PSVI: validation attempted
  2511             // PSVI: validation attempted
  2399             // nothing below or at the same level has none or partial
  2512             // nothing below or at the same level has none or partial
  2400             // (which means this level is strictly assessed, and all chidren
  2513             // (which means this level is strictly assessed, and all chidren
  2401             // are full), so this one has full
  2514             // are full), so this one has full
  2402             if (fElementDepth > fNFullValidationDepth) {
  2515             if (fElementDepth > fNFullValidationDepth) {
  2421                 fNNoneValidationDepth = fElementDepth - 1;
  2534                 fNNoneValidationDepth = fElementDepth - 1;
  2422             }
  2535             }
  2423 
  2536 
  2424             if (fDefaultValue != null)
  2537             if (fDefaultValue != null)
  2425                 fCurrentPSVI.fSpecified = true;
  2538                 fCurrentPSVI.fSpecified = true;
  2426             fCurrentPSVI.fNil = fNil;
  2539             fCurrentPSVI.fValue.copyFrom(fValidatedInfo);
  2427             fCurrentPSVI.fMemberType = fValidatedInfo.memberType;
       
  2428             fCurrentPSVI.fNormalizedValue = fValidatedInfo.normalizedValue;
       
  2429             fCurrentPSVI.fActualValue = fValidatedInfo.actualValue;
       
  2430             fCurrentPSVI.fActualValueType = fValidatedInfo.actualValueType;
       
  2431             fCurrentPSVI.fItemValueTypes = fValidatedInfo.itemValueTypes;
       
  2432 
  2540 
  2433             if (fStrictAssess) {
  2541             if (fStrictAssess) {
  2434                 // get all errors for the current element, its attribute,
  2542                 // get all errors for the current element, its attribute,
  2435                 // and subelements (if they were strictly assessed).
  2543                 // and subelements (if they were strictly assessed).
  2436                 // any error would make this element invalid.
  2544                 // any error would make this element invalid.
  2437                 // and we merge these errors to the parent element.
  2545                 // and we merge these errors to the parent element.
  2438                 String[] errors = fXSIErrorReporter.mergeContext();
  2546                 String[] errors = fXSIErrorReporter.mergeContext();
  2439 
  2547 
  2440                 // PSVI: error codes
  2548                 // PSVI: error codes
  2441                 fCurrentPSVI.fErrorCodes = errors;
  2549                 fCurrentPSVI.fErrors = errors;
  2442                 // PSVI: validity
  2550                 // PSVI: validity
  2443                 fCurrentPSVI.fValidity =
  2551                 fCurrentPSVI.fValidity =
  2444                     (errors == null) ? ElementPSVI.VALIDITY_VALID : ElementPSVI.VALIDITY_INVALID;
  2552                     (errors == null) ? ElementPSVI.VALIDITY_VALID : ElementPSVI.VALIDITY_INVALID;
  2445             } else {
  2553             } else {
  2446                 // PSVI: validity
  2554                 // PSVI: validity
  2473         return augs;
  2581         return augs;
  2474     }
  2582     }
  2475 
  2583 
  2476     void storeLocations(String sLocation, String nsLocation) {
  2584     void storeLocations(String sLocation, String nsLocation) {
  2477         if (sLocation != null) {
  2585         if (sLocation != null) {
  2478             if (!XMLSchemaLoader.tokenizeSchemaLocationStr(sLocation, fLocationPairs)) {
  2586             if (!XMLSchemaLoader.tokenizeSchemaLocationStr(sLocation, fLocationPairs, fLocator == null ? null : fLocator.getExpandedSystemId())) {
  2479                 // error!
  2587                 // error!
  2480                 fXSIErrorReporter.reportError(
  2588                 fXSIErrorReporter.reportError(
  2481                     XSMessageFormatter.SCHEMA_DOMAIN,
  2589                     XSMessageFormatter.SCHEMA_DOMAIN,
  2482                     "SchemaLocation",
  2590                     "SchemaLocation",
  2483                     new Object[] { sLocation },
  2591                     new Object[] { sLocation },
  2488             XMLSchemaLoader.LocationArray la =
  2596             XMLSchemaLoader.LocationArray la =
  2489                 ((XMLSchemaLoader.LocationArray) fLocationPairs.get(XMLSymbols.EMPTY_STRING));
  2597                 ((XMLSchemaLoader.LocationArray) fLocationPairs.get(XMLSymbols.EMPTY_STRING));
  2490             if (la == null) {
  2598             if (la == null) {
  2491                 la = new XMLSchemaLoader.LocationArray();
  2599                 la = new XMLSchemaLoader.LocationArray();
  2492                 fLocationPairs.put(XMLSymbols.EMPTY_STRING, la);
  2600                 fLocationPairs.put(XMLSymbols.EMPTY_STRING, la);
       
  2601             }
       
  2602             if (fLocator != null) {
       
  2603                 try {
       
  2604                     nsLocation = XMLEntityManager.expandSystemId(nsLocation, fLocator.getExpandedSystemId(), false);
       
  2605                 } catch (MalformedURIException e) {
       
  2606                 }
  2493             }
  2607             }
  2494             la.addLocation(nsLocation);
  2608             la.addLocation(nsLocation);
  2495         }
  2609         }
  2496 
  2610 
  2497     } //storeLocations
  2611     } //storeLocations
  2501     //tries to parse the grammar using location hints from the give namespace.
  2615     //tries to parse the grammar using location hints from the give namespace.
  2502     SchemaGrammar findSchemaGrammar(
  2616     SchemaGrammar findSchemaGrammar(
  2503         short contextType,
  2617         short contextType,
  2504         String namespace,
  2618         String namespace,
  2505         QName enclosingElement,
  2619         QName enclosingElement,
  2506         QName triggeringComponet,
  2620         QName triggeringComponent,
  2507         XMLAttributes attributes) {
  2621         XMLAttributes attributes) {
  2508         SchemaGrammar grammar = null;
  2622         SchemaGrammar grammar = null;
  2509         //get the grammar from local pool...
  2623         //get the grammar from local pool...
  2510         grammar = fGrammarBucket.getGrammar(namespace);
  2624         grammar = fGrammarBucket.getGrammar(namespace);
  2511 
  2625 
  2528                         grammar = null;
  2642                         grammar = null;
  2529                     }
  2643                     }
  2530                 }
  2644                 }
  2531             }
  2645             }
  2532         }
  2646         }
  2533         if ((grammar == null && !fUseGrammarPoolOnly) || fNamespaceGrowth) {
  2647 
       
  2648         if (!fUseGrammarPoolOnly && (grammar == null ||
       
  2649             (fNamespaceGrowth && !hasSchemaComponent(grammar, contextType, triggeringComponent)))) {
  2534             fXSDDescription.reset();
  2650             fXSDDescription.reset();
  2535             fXSDDescription.fContextType = contextType;
  2651             fXSDDescription.fContextType = contextType;
  2536             fXSDDescription.setNamespace(namespace);
  2652             fXSDDescription.setNamespace(namespace);
  2537             fXSDDescription.fEnclosedElementName = enclosingElement;
  2653             fXSDDescription.fEnclosedElementName = enclosingElement;
  2538             fXSDDescription.fTriggeringComponent = triggeringComponet;
  2654             fXSDDescription.fTriggeringComponent = triggeringComponent;
  2539             fXSDDescription.fAttributes = attributes;
  2655             fXSDDescription.fAttributes = attributes;
  2540             if (fLocator != null) {
  2656             if (fLocator != null) {
  2541                 fXSDDescription.setBaseSystemId(fLocator.getExpandedSystemId());
  2657                 fXSDDescription.setBaseSystemId(fLocator.getExpandedSystemId());
  2542             }
  2658             }
  2543 
  2659 
  2577                         }
  2693                         }
  2578                     }
  2694                     }
  2579                     if (toParseSchema) {
  2695                     if (toParseSchema) {
  2580                         grammar = fSchemaLoader.loadSchema(fXSDDescription, xis, fLocationPairs);
  2696                         grammar = fSchemaLoader.loadSchema(fXSDDescription, xis, fLocationPairs);
  2581                     }
  2697                     }
  2582                 } catch (IOException ex) {
  2698                 }
       
  2699                 catch (IOException ex) {
  2583                     final String [] locationHints = fXSDDescription.getLocationHints();
  2700                     final String [] locationHints = fXSDDescription.getLocationHints();
  2584                     fXSIErrorReporter.fErrorReporter.reportError(
  2701                     fXSIErrorReporter.fErrorReporter.reportError(
  2585                         XSMessageFormatter.SCHEMA_DOMAIN,
  2702                         XSMessageFormatter.SCHEMA_DOMAIN,
  2586                         "schema_reference.4",
  2703                         "schema_reference.4",
  2587                         new Object[] { locationHints != null ? locationHints[0] : XMLSymbols.EMPTY_STRING },
  2704                         new Object[] { locationHints != null ? locationHints[0] : XMLSymbols.EMPTY_STRING },
  2588                         XMLErrorReporter.SEVERITY_WARNING);
  2705                         XMLErrorReporter.SEVERITY_WARNING, ex);
  2589                 }
  2706                 }
  2590             }
  2707             }
  2591         }
  2708         }
  2592 
  2709 
  2593         return grammar;
  2710         return grammar;
  2594 
  2711 
  2595     } //findSchemaGrammar
  2712     } //findSchemaGrammar
       
  2713 
       
  2714     private boolean hasSchemaComponent(SchemaGrammar grammar, short contextType, QName triggeringComponent) {
       
  2715         if (grammar != null && triggeringComponent != null) {
       
  2716             String localName = triggeringComponent.localpart;
       
  2717             if (localName != null && localName.length() > 0) {
       
  2718                 switch (contextType) {
       
  2719                     case XSDDescription.CONTEXT_ELEMENT:
       
  2720                         return grammar.getElementDeclaration(localName) != null;
       
  2721                     case XSDDescription.CONTEXT_ATTRIBUTE:
       
  2722                         return grammar.getAttributeDeclaration(localName) != null;
       
  2723                     case XSDDescription.CONTEXT_XSITYPE:
       
  2724                         return grammar.getTypeDefinition(localName) != null;
       
  2725                 }
       
  2726             }
       
  2727         }
       
  2728         return false;
       
  2729     }
       
  2730 
  2596     private void setLocationHints(XSDDescription desc, String[] locations, SchemaGrammar grammar) {
  2731     private void setLocationHints(XSDDescription desc, String[] locations, SchemaGrammar grammar) {
  2597         int length = locations.length;
  2732         int length = locations.length;
  2598         if (grammar == null) {
  2733         if (grammar == null) {
  2599             fXSDDescription.fLocationHints = new String[length];
  2734             fXSDDescription.fLocationHints = new String[length];
  2600             System.arraycopy(locations, 0, fXSDDescription.fLocationHints, 0, length);
  2735             System.arraycopy(locations, 0, fXSDDescription.fLocationHints, 0, length);
  2608         int length = locations.length;
  2743         int length = locations.length;
  2609         String[] hints = new String[length];
  2744         String[] hints = new String[length];
  2610         int counter = 0;
  2745         int counter = 0;
  2611 
  2746 
  2612         for (int i=0; i<length; i++) {
  2747         for (int i=0; i<length; i++) {
  2613             try {
  2748             if (!docLocations.contains(locations[i])) {
  2614                 String id = XMLEntityManager.expandSystemId(locations[i], desc.getBaseSystemId(), false);
  2749                 hints[counter++] = locations[i];
  2615                 if (!docLocations.contains(id)) {
       
  2616                     hints[counter++] = locations[i];
       
  2617                 }
       
  2618             }
       
  2619             catch (MalformedURIException e) {
       
  2620             }
  2750             }
  2621         }
  2751         }
  2622 
  2752 
  2623         if (counter > 0) {
  2753         if (counter > 0) {
  2624             if (counter == length) {
  2754             if (counter == length) {
  2628                 fXSDDescription.fLocationHints = new String[counter];
  2758                 fXSDDescription.fLocationHints = new String[counter];
  2629                 System.arraycopy(hints, 0, fXSDDescription.fLocationHints, 0, counter);
  2759                 System.arraycopy(hints, 0, fXSDDescription.fLocationHints, 0, counter);
  2630             }
  2760             }
  2631         }
  2761         }
  2632     }
  2762     }
  2633 
       
  2634 
  2763 
  2635     XSTypeDefinition getAndCheckXsiType(QName element, String xsiType, XMLAttributes attributes) {
  2764     XSTypeDefinition getAndCheckXsiType(QName element, String xsiType, XMLAttributes attributes) {
  2636         // This method also deals with clause 1.2.1.2 of the constraint
  2765         // This method also deals with clause 1.2.1.2 of the constraint
  2637         // Validation Rule: Schema-Validity Assessment (Element)
  2766         // Validation Rule: Schema-Validity Assessment (Element)
  2638 
  2767 
  2694                 block |= ((XSComplexTypeDecl) fCurrentType).fBlock;
  2823                 block |= ((XSComplexTypeDecl) fCurrentType).fBlock;
  2695             }
  2824             }
  2696             if (!XSConstraints.checkTypeDerivationOk(type, fCurrentType, block)) {
  2825             if (!XSConstraints.checkTypeDerivationOk(type, fCurrentType, block)) {
  2697                 reportSchemaError(
  2826                 reportSchemaError(
  2698                         "cvc-elt.4.3",
  2827                         "cvc-elt.4.3",
  2699                         new Object[] { element.rawname, xsiType, fCurrentType.getName()});
  2828                         new Object[] { element.rawname, xsiType, XS10TypeHelper.getSchemaTypeName(fCurrentType)});
  2700             }
  2829             }
  2701         }
  2830         }
  2702 
  2831 
  2703         return type;
  2832         return type;
  2704     } //getAndCheckXsiType
  2833     } //getAndCheckXsiType
  2791             // whose [local name] is one of type, nil, schemaLocation or noNamespaceSchemaLocation.
  2920             // whose [local name] is one of type, nil, schemaLocation or noNamespaceSchemaLocation.
  2792 
  2921 
  2793             // for the 4 xsi attributes, get appropriate decl, and validate
  2922             // for the 4 xsi attributes, get appropriate decl, and validate
  2794             if (fTempQName.uri == SchemaSymbols.URI_XSI) {
  2923             if (fTempQName.uri == SchemaSymbols.URI_XSI) {
  2795                 XSAttributeDecl attrDecl = null;
  2924                 XSAttributeDecl attrDecl = null;
  2796                 if (fTempQName.localpart == SchemaSymbols.XSI_SCHEMALOCATION)
  2925                 if (fTempQName.localpart == SchemaSymbols.XSI_TYPE) {
  2797                     attrDecl =
  2926                     attrDecl = XSI_TYPE;
  2798                         SchemaGrammar.SG_XSI.getGlobalAttributeDecl(
  2927                 }
  2799                             SchemaSymbols.XSI_SCHEMALOCATION);
  2928                 else if (fTempQName.localpart == SchemaSymbols.XSI_NIL) {
  2800                 else if (fTempQName.localpart == SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION)
  2929                     attrDecl = XSI_NIL;
  2801                     attrDecl =
  2930                 }
  2802                         SchemaGrammar.SG_XSI.getGlobalAttributeDecl(
  2931                 else if (fTempQName.localpart == SchemaSymbols.XSI_SCHEMALOCATION) {
  2803                             SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION);
  2932                     attrDecl = XSI_SCHEMALOCATION;
  2804                 else if (fTempQName.localpart == SchemaSymbols.XSI_NIL)
  2933                 }
  2805                     attrDecl = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NIL);
  2934                 else if (fTempQName.localpart == SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION) {
  2806                 else if (fTempQName.localpart == SchemaSymbols.XSI_TYPE)
  2935                     attrDecl = XSI_NONAMESPACESCHEMALOCATION;
  2807                     attrDecl = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_TYPE);
  2936                 }
  2808                 if (attrDecl != null) {
  2937                 if (attrDecl != null) {
  2809                     processOneAttribute(element, attributes, index, attrDecl, null, attrPSVI);
  2938                     processOneAttribute(element, attributes, index, attrDecl, null, attrPSVI);
  2810                     continue;
  2939                     continue;
  2811                 }
  2940                 }
  2812             }
  2941             }
  2847                 if (attrWildcard == null || !attrWildcard.allowNamespace(fTempQName.uri)) {
  2976                 if (attrWildcard == null || !attrWildcard.allowNamespace(fTempQName.uri)) {
  2848                     // so this attribute is not allowed
  2977                     // so this attribute is not allowed
  2849                     reportSchemaError(
  2978                     reportSchemaError(
  2850                         "cvc-complex-type.3.2.2",
  2979                         "cvc-complex-type.3.2.2",
  2851                         new Object[] { element.rawname, fTempQName.rawname });
  2980                         new Object[] { element.rawname, fTempQName.rawname });
       
  2981 
       
  2982                     // We have seen an attribute that was not declared
       
  2983                     fNFullValidationDepth = fElementDepth;
       
  2984 
  2852                     continue;
  2985                     continue;
  2853                 }
  2986                 }
  2854             }
  2987             }
  2855 
  2988 
  2856             XSAttributeDecl currDecl = null;
  2989             XSAttributeDecl currDecl = null;
  2934 
  3067 
  2935         Object actualValue = null;
  3068         Object actualValue = null;
  2936         try {
  3069         try {
  2937             actualValue = attDV.validate(attrValue, fValidationState, fValidatedInfo);
  3070             actualValue = attDV.validate(attrValue, fValidationState, fValidatedInfo);
  2938             // store the normalized value
  3071             // store the normalized value
  2939             if (fNormalizeData)
  3072             if (fNormalizeData) {
  2940                 attributes.setValue(index, fValidatedInfo.normalizedValue);
  3073                 attributes.setValue(index, fValidatedInfo.normalizedValue);
  2941             if (attributes instanceof XMLAttributesImpl) {
  3074             }
  2942                 XMLAttributesImpl attrs = (XMLAttributesImpl) attributes;
       
  2943                 boolean schemaId =
       
  2944                     fValidatedInfo.memberType != null
       
  2945                         ? fValidatedInfo.memberType.isIDType()
       
  2946                         : attDV.isIDType();
       
  2947                 attrs.setSchemaId(index, schemaId);
       
  2948             }
       
  2949 
       
  2950             // PSVI: element notation
  3075             // PSVI: element notation
  2951             if (attDV.getVariety() == XSSimpleType.VARIETY_ATOMIC
  3076             if (attDV.getVariety() == XSSimpleType.VARIETY_ATOMIC
  2952                 && attDV.getPrimitiveKind() == XSSimpleType.PRIMITIVE_NOTATION) {
  3077                 && attDV.getPrimitiveKind() == XSSimpleType.PRIMITIVE_NOTATION) {
  2953                 QName qName = (QName) actualValue;
  3078                 QName qName = (QName) actualValue;
  2954                 SchemaGrammar grammar = fGrammarBucket.getGrammar(qName.uri);
  3079                 SchemaGrammar grammar = fGrammarBucket.getGrammar(qName.uri);
  2961 
  3086 
  2962                 if (grammar != null) {
  3087                 if (grammar != null) {
  2963                     fNotation = grammar.getGlobalNotationDecl(qName.localpart);
  3088                     fNotation = grammar.getGlobalNotationDecl(qName.localpart);
  2964                 }
  3089                 }
  2965             }
  3090             }
  2966         } catch (InvalidDatatypeValueException idve) {
  3091         }
       
  3092         catch (InvalidDatatypeValueException idve) {
  2967             reportSchemaError(idve.getKey(), idve.getArgs());
  3093             reportSchemaError(idve.getKey(), idve.getArgs());
  2968             reportSchemaError(
  3094             reportSchemaError(
  2969                 "cvc-attribute.3",
  3095                 "cvc-attribute.3",
  2970                 new Object[] { element.rawname, fTempQName.rawname, attrValue, attDV.getName()});
  3096                 new Object[] { element.rawname, fTempQName.rawname, attrValue,
       
  3097                         (attDV instanceof XSSimpleTypeDecl) ?
       
  3098                                 ((XSSimpleTypeDecl) attDV).getTypeName() : attDV.getName()});
  2971         }
  3099         }
  2972 
  3100 
  2973         // get the value constraint from use or decl
  3101         // get the value constraint from use or decl
  2974         // 4 The item's actual value must match the value of the {value constraint}, if it is present and fixed.
  3102         // 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
  2975         // now check the value against the simpleType
       
  2976         if (actualValue != null && currDecl.getConstraintType() == XSConstants.VC_FIXED) {
  3103         if (actualValue != null && currDecl.getConstraintType() == XSConstants.VC_FIXED) {
  2977             if (!ValidatedInfo.isComparable(fValidatedInfo, currDecl.fDefault) || !actualValue.equals(currDecl.fDefault.actualValue)) {
  3104             if (!ValidatedInfo.isComparable(fValidatedInfo, currDecl.fDefault) || !actualValue.equals(currDecl.fDefault.actualValue)) {
  2978                 reportSchemaError(
  3105                 reportSchemaError(
  2979                     "cvc-attribute.4",
  3106                     "cvc-attribute.4",
  2980                     new Object[] {
  3107                     new Object[] {
  2998                         attrValue,
  3125                         attrValue,
  2999                         currUse.fDefault.stringValue()});
  3126                         currUse.fDefault.stringValue()});
  3000             }
  3127             }
  3001         }
  3128         }
  3002         if (fIdConstraint) {
  3129         if (fIdConstraint) {
  3003             attrPSVI.fActualValue = actualValue;
  3130             attrPSVI.fValue.copyFrom(fValidatedInfo);
  3004         }
  3131         }
  3005 
  3132 
  3006         if (fAugPSVI) {
  3133         if (fAugPSVI) {
  3007             // PSVI: attribute declaration
  3134             // PSVI: attribute declaration
  3008             attrPSVI.fDeclaration = currDecl;
  3135             attrPSVI.fDeclaration = currDecl;
  3009             // PSVI: attribute type
  3136             // PSVI: attribute type
  3010             attrPSVI.fTypeDecl = attDV;
  3137             attrPSVI.fTypeDecl = attDV;
  3011 
  3138 
  3012             // PSVI: attribute memberType
       
  3013             attrPSVI.fMemberType = fValidatedInfo.memberType;
       
  3014             // PSVI: attribute normalized value
  3139             // PSVI: attribute normalized value
  3015             // NOTE: we always store the normalized value, even if it's invlid,
  3140             // NOTE: we always store the normalized value, even if it's invlid,
  3016             // because it might still be useful to the user. But when the it's
  3141             // because it might still be useful to the user. But when the it's
  3017             // not valid, the normalized value is not trustable.
  3142             // not valid, the normalized value is not trustable.
  3018             attrPSVI.fNormalizedValue = fValidatedInfo.normalizedValue;
  3143             attrPSVI.fValue.copyFrom(fValidatedInfo);
  3019             attrPSVI.fActualValue = fValidatedInfo.actualValue;
       
  3020             attrPSVI.fActualValueType = fValidatedInfo.actualValueType;
       
  3021             attrPSVI.fItemValueTypes = fValidatedInfo.itemValueTypes;
       
  3022 
       
  3023 
       
  3024 
  3144 
  3025             // PSVI: validation attempted:
  3145             // PSVI: validation attempted:
  3026             attrPSVI.fValidationAttempted = AttributePSVI.VALIDATION_FULL;
  3146             attrPSVI.fValidationAttempted = AttributePSVI.VALIDATION_FULL;
  3027 
  3147 
       
  3148             // We have seen an attribute that was declared.
       
  3149             if (!fUseGrammarPoolOnly &&
       
  3150                     !(fElementDepth < fIgnoreXSITypeDepth && fCurrentElemDecl == null)) {
       
  3151                 //only when USE_GRAMMAR_POOL_ONLY and IGNORE_XSI_TYPE are not set
       
  3152                 fNNoneValidationDepth = fElementDepth;
       
  3153             }
       
  3154 
  3028             String[] errors = fXSIErrorReporter.mergeContext();
  3155             String[] errors = fXSIErrorReporter.mergeContext();
  3029             // PSVI: error codes
  3156             // PSVI: error codes
  3030             attrPSVI.fErrorCodes = errors;
  3157             attrPSVI.fErrors = errors;
  3031             // PSVI: validity
  3158             // PSVI: validity
  3032             attrPSVI.fValidity =
  3159             attrPSVI.fValidity =
  3033                 (errors == null) ? AttributePSVI.VALIDITY_VALID : AttributePSVI.VALIDITY_INVALID;
  3160                 (errors == null) ? AttributePSVI.VALIDITY_VALID : AttributePSVI.VALIDITY_INVALID;
  3034         }
  3161         }
  3035     }
  3162     }
  3083             // if the attribute is not specified, then apply the value constraint
  3210             // if the attribute is not specified, then apply the value constraint
  3084             if (!isSpecified && constType != XSConstants.VC_NONE) {
  3211             if (!isSpecified && constType != XSConstants.VC_NONE) {
  3085                 attName =
  3212                 attName =
  3086                     new QName(null, currDecl.fName, currDecl.fName, currDecl.fTargetNamespace);
  3213                     new QName(null, currDecl.fName, currDecl.fName, currDecl.fTargetNamespace);
  3087                 String normalized = (defaultValue != null) ? defaultValue.stringValue() : "";
  3214                 String normalized = (defaultValue != null) ? defaultValue.stringValue() : "";
  3088                 int attrIndex = attributes.addAttribute(attName, "CDATA", normalized);
  3215                 int attrIndex;
  3089                 if (attributes instanceof XMLAttributesImpl) {
  3216                 if (attributes instanceof XMLAttributesImpl) {
  3090                     XMLAttributesImpl attrs = (XMLAttributesImpl) attributes;
  3217                     XMLAttributesImpl attrs = (XMLAttributesImpl) attributes;
  3091                     boolean schemaId =
  3218                     attrIndex = attrs.getLength();
  3092                         defaultValue != null
  3219                     attrs.addAttributeNS(attName, "CDATA", normalized);
  3093                             && defaultValue.memberType != null
  3220                 }
  3094                                 ? defaultValue.memberType.isIDType()
  3221                 else {
  3095                                 : currDecl.fType.isIDType();
  3222                     attrIndex = attributes.addAttribute(attName, "CDATA", normalized);
  3096                     attrs.setSchemaId(attrIndex, schemaId);
       
  3097                 }
  3223                 }
  3098 
  3224 
  3099                 if (fAugPSVI) {
  3225                 if (fAugPSVI) {
  3100 
  3226 
  3101                     // PSVI: attribute is "schema" specified
  3227                     // PSVI: attribute is "schema" specified
  3103                     AttributePSVImpl attrPSVI = new AttributePSVImpl();
  3229                     AttributePSVImpl attrPSVI = new AttributePSVImpl();
  3104                     augs.putItem(Constants.ATTRIBUTE_PSVI, attrPSVI);
  3230                     augs.putItem(Constants.ATTRIBUTE_PSVI, attrPSVI);
  3105 
  3231 
  3106                     attrPSVI.fDeclaration = currDecl;
  3232                     attrPSVI.fDeclaration = currDecl;
  3107                     attrPSVI.fTypeDecl = currDecl.fType;
  3233                     attrPSVI.fTypeDecl = currDecl.fType;
  3108                     attrPSVI.fMemberType = defaultValue.memberType;
  3234                     attrPSVI.fValue.copyFrom(defaultValue);
  3109                     attrPSVI.fNormalizedValue = normalized;
       
  3110                     attrPSVI.fActualValue = defaultValue.actualValue;
       
  3111                     attrPSVI.fActualValueType = defaultValue.actualValueType;
       
  3112                     attrPSVI.fItemValueTypes = defaultValue.itemValueTypes;
       
  3113                     attrPSVI.fValidationContext = fValidationRoot;
  3235                     attrPSVI.fValidationContext = fValidationRoot;
  3114                     attrPSVI.fValidity = AttributePSVI.VALIDITY_VALID;
  3236                     attrPSVI.fValidity = AttributePSVI.VALIDITY_VALID;
  3115                     attrPSVI.fValidationAttempted = AttributePSVI.VALIDATION_FULL;
  3237                     attrPSVI.fValidationAttempted = AttributePSVI.VALIDATION_FULL;
  3116                     attrPSVI.fSpecified = true;
  3238                     attrPSVI.fSpecified = true;
  3117                 }
  3239                 }
  3344                 if (DEBUG) {
  3466                 if (DEBUG) {
  3345                     System.out.println(fCurrCMState);
  3467                     System.out.println(fCurrCMState);
  3346                 }
  3468                 }
  3347                 if (fCurrCMState[0] >= 0 && !fCurrentCM.endContentModel(fCurrCMState)) {
  3469                 if (fCurrCMState[0] >= 0 && !fCurrentCM.endContentModel(fCurrCMState)) {
  3348                     String expected = expectedStr(fCurrentCM.whatCanGoHere(fCurrCMState));
  3470                     String expected = expectedStr(fCurrentCM.whatCanGoHere(fCurrCMState));
  3349                     reportSchemaError(
  3471                     final int[] occurenceInfo = fCurrentCM.occurenceInfo(fCurrCMState);
  3350                         "cvc-complex-type.2.4.b",
  3472                     if (occurenceInfo != null) {
  3351                         new Object[] { element.rawname, expected });
  3473                         final int minOccurs = occurenceInfo[0];
       
  3474                         final int count = occurenceInfo[2];
       
  3475                         // Check if this is a violation of minOccurs
       
  3476                         if (count < minOccurs) {
       
  3477                             final int required = minOccurs - count;
       
  3478                             if (required > 1) {
       
  3479                                 reportSchemaError("cvc-complex-type.2.4.j", new Object[] { element.rawname,
       
  3480                                         fCurrentCM.getTermName(occurenceInfo[3]), Integer.toString(minOccurs), Integer.toString(required) });
       
  3481                             }
       
  3482                             else {
       
  3483                                 reportSchemaError("cvc-complex-type.2.4.i", new Object[] { element.rawname,
       
  3484                                         fCurrentCM.getTermName(occurenceInfo[3]), Integer.toString(minOccurs) });
       
  3485                             }
       
  3486                         }
       
  3487                         else {
       
  3488                             reportSchemaError("cvc-complex-type.2.4.b", new Object[] { element.rawname, expected });
       
  3489                         }
       
  3490                     }
       
  3491                     else {
       
  3492                         reportSchemaError("cvc-complex-type.2.4.b", new Object[] { element.rawname, expected });
       
  3493                     }
  3352                 } else {
  3494                 } else {
  3353                     // Constant space algorithm for a{n,m} for n > 1 and m <= unbounded
  3495                     // Constant space algorithm for a{n,m} for n > 1 and m <= unbounded
  3354                     // After the DFA has completed, check minOccurs and maxOccurs
  3496                     // After the DFA has completed, check minOccurs and maxOccurs
  3355                     // for all elements and wildcards in this content model where
  3497                     // for all elements and wildcards in this content model where
  3356                     // a{n,m} is subsumed to a* or a+
  3498                     // a{n,m} is subsumed to a* or a+
  3361                                 (String) errors.get(i),
  3503                                 (String) errors.get(i),
  3362                                 new Object[] { element.rawname, errors.get(i + 1) });
  3504                                 new Object[] { element.rawname, errors.get(i + 1) });
  3363                         }
  3505                         }
  3364                     }
  3506                     }
  3365                 }
  3507                 }
  3366              }
  3508             }
  3367         }
  3509         }
  3368         return actualValue;
  3510         return actualValue;
  3369     } // elementLocallyValidComplexType
  3511     } // elementLocallyValidComplexType
       
  3512 
       
  3513     void processRootTypeQName(final javax.xml.namespace.QName rootTypeQName) {
       
  3514         String rootTypeNamespace = rootTypeQName.getNamespaceURI();
       
  3515         // Add namespace to symbol table, to make sure it's interned.
       
  3516         // This namespace may be later compared with other values using ==.
       
  3517         rootTypeNamespace = fSymbolTable.addSymbol(rootTypeNamespace);
       
  3518         if (rootTypeNamespace != null && rootTypeNamespace.equals(XMLConstants.NULL_NS_URI)) {
       
  3519             rootTypeNamespace = null;
       
  3520         }
       
  3521         if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(rootTypeNamespace)) {
       
  3522             fCurrentType = SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(rootTypeQName.getLocalPart());
       
  3523         }
       
  3524         else {
       
  3525             final SchemaGrammar grammarForRootType = findSchemaGrammar(
       
  3526                     XSDDescription.CONTEXT_ELEMENT, rootTypeNamespace, null, null, null);
       
  3527             if (grammarForRootType != null) {
       
  3528                 fCurrentType = grammarForRootType.getGlobalTypeDecl(rootTypeQName.getLocalPart());
       
  3529             }
       
  3530         }
       
  3531         if (fCurrentType == null) {
       
  3532             String typeName = (rootTypeQName.getPrefix().equals(XMLConstants.DEFAULT_NS_PREFIX)) ?
       
  3533                     rootTypeQName.getLocalPart() :
       
  3534                         rootTypeQName.getPrefix()+":"+rootTypeQName.getLocalPart();
       
  3535                     reportSchemaError("cvc-type.1", new Object[] {typeName});
       
  3536         }
       
  3537     } // processRootTypeQName
       
  3538 
       
  3539     void processRootElementDeclQName(final javax.xml.namespace.QName rootElementDeclQName, final QName element) {
       
  3540         String rootElementDeclNamespace = rootElementDeclQName.getNamespaceURI();
       
  3541         // Add namespace to symbol table, to make sure it's interned.
       
  3542         // This namespace may be later compared with other values using ==.
       
  3543         rootElementDeclNamespace = fSymbolTable.addSymbol(rootElementDeclNamespace);
       
  3544         if (rootElementDeclNamespace != null && rootElementDeclNamespace.equals(XMLConstants.NULL_NS_URI)) {
       
  3545             rootElementDeclNamespace = null;
       
  3546         }
       
  3547         final SchemaGrammar grammarForRootElement = findSchemaGrammar(
       
  3548                 XSDDescription.CONTEXT_ELEMENT, rootElementDeclNamespace, null, null, null);
       
  3549         if (grammarForRootElement != null) {
       
  3550             fCurrentElemDecl = grammarForRootElement.getGlobalElementDecl(rootElementDeclQName.getLocalPart());
       
  3551         }
       
  3552         if (fCurrentElemDecl == null) {
       
  3553             String declName = (rootElementDeclQName.getPrefix().equals(XMLConstants.DEFAULT_NS_PREFIX)) ?
       
  3554                     rootElementDeclQName.getLocalPart() :
       
  3555                         rootElementDeclQName.getPrefix()+":"+rootElementDeclQName.getLocalPart();
       
  3556                     reportSchemaError("cvc-elt.1.a", new Object[] {declName});
       
  3557         }
       
  3558         else {
       
  3559             checkElementMatchesRootElementDecl(fCurrentElemDecl, element);
       
  3560         }
       
  3561     } // processRootElementDeclQName
       
  3562 
       
  3563     void checkElementMatchesRootElementDecl(final XSElementDecl rootElementDecl, final QName element) {
       
  3564         // Report an error if the name of the element does
       
  3565         // not match the name of the specified element declaration.
       
  3566         if (element.localpart != rootElementDecl.fName ||
       
  3567             element.uri != rootElementDecl.fTargetNamespace) {
       
  3568             reportSchemaError("cvc-elt.1.b", new Object[] {element.rawname, rootElementDecl.fName});
       
  3569         }
       
  3570     } // checkElementMatchesRootElementDecl
  3370 
  3571 
  3371     void reportSchemaError(String key, Object[] arguments) {
  3572     void reportSchemaError(String key, Object[] arguments) {
  3372         if (fDoValidation)
  3573         if (fDoValidation)
  3373             fXSIErrorReporter.reportError(
  3574             fXSIErrorReporter.reportError(
  3374                 XSMessageFormatter.SCHEMA_DOMAIN,
  3575                 XSMessageFormatter.SCHEMA_DOMAIN,
  3375                 key,
  3576                 key,
  3376                 arguments,
  3577                 arguments,
  3377                 XMLErrorReporter.SEVERITY_ERROR);
  3578                 XMLErrorReporter.SEVERITY_ERROR);
  3378     }
  3579     }
  3379 
  3580 
  3380 
  3581     private String expectedStr(ArrayList expected) {
  3381     private String expectedStr(Vector expected) {
  3582         StringBuilder ret = new StringBuilder("{");
  3382         StringBuffer ret = new StringBuffer("{");
       
  3383         int size = expected.size();
  3583         int size = expected.size();
  3384         for (int i = 0; i < size; i++) {
  3584         for (int i = 0; i < size; i++) {
  3385             if (i > 0)
  3585             if (i > 0)
  3386                 ret.append(", ");
  3586                 ret.append(", ");
  3387             ret.append(expected.elementAt(i).toString());
  3587             ret.append(expected.get(i).toString());
  3388         }
  3588         }
  3389         ret.append('}');
  3589         ret.append('}');
  3390         return ret.toString();
  3590         return ret.toString();
  3391     }
  3591     }
  3392 
  3592 
  3518         private boolean fUseItemValueTypeVector = false;
  3718         private boolean fUseItemValueTypeVector = false;
  3519         private int fItemValueTypesLength = 0;
  3719         private int fItemValueTypesLength = 0;
  3520         private ShortList fItemValueType = null;
  3720         private ShortList fItemValueType = null;
  3521 
  3721 
  3522         /** buffer for error messages */
  3722         /** buffer for error messages */
  3523         final StringBuffer fTempBuffer = new StringBuffer();
  3723         final StringBuilder fTempBuffer = new StringBuilder();
  3524 
  3724 
  3525         //
  3725         //
  3526         // Constructors
  3726         // Constructors
  3527         //
  3727         //
  3528 
  3728 
  3643          * Adds the specified value to the value store.
  3843          * Adds the specified value to the value store.
  3644          *
  3844          *
  3645          * @param field The field associated to the value. This reference
  3845          * @param field The field associated to the value. This reference
  3646          *              is used to ensure that each field only adds a value
  3846          *              is used to ensure that each field only adds a value
  3647          *              once within a selection scope.
  3847          *              once within a selection scope.
       
  3848          * @param mayMatch a flag indiciating whether the field may be matched.
  3648          * @param actualValue The value to add.
  3849          * @param actualValue The value to add.
       
  3850          * @param valueType Type of the value to add.
       
  3851          * @param itemValueType If the value is a list, a list of types for each of the values in the list.
  3649          */
  3852          */
  3650         public void addValue(Field field, Object actualValue, short valueType, ShortList itemValueType) {
  3853         public void addValue(Field field, boolean mayMatch, Object actualValue, short valueType, ShortList itemValueType) {
  3651             int i;
  3854             int i;
  3652             for (i = fFieldCount - 1; i > -1; i--) {
  3855             for (i = fFieldCount - 1; i > -1; i--) {
  3653                 if (fFields[i] == field) {
  3856                 if (fFields[i] == field) {
  3654                     break;
  3857                     break;
  3655                 }
  3858                 }
  3660                 String eName = fIdentityConstraint.getElementName();
  3863                 String eName = fIdentityConstraint.getElementName();
  3661                 String cName = fIdentityConstraint.getIdentityConstraintName();
  3864                 String cName = fIdentityConstraint.getIdentityConstraintName();
  3662                 reportSchemaError(code, new Object[] { field.toString(), eName, cName });
  3865                 reportSchemaError(code, new Object[] { field.toString(), eName, cName });
  3663                 return;
  3866                 return;
  3664             }
  3867             }
  3665             if (Boolean.TRUE != mayMatch(field)) {
  3868             if (!mayMatch) {
  3666                 String code = "FieldMultipleMatch";
  3869                 String code = "FieldMultipleMatch";
  3667                 String cName = fIdentityConstraint.getIdentityConstraintName();
  3870                 String cName = fIdentityConstraint.getIdentityConstraintName();
  3668                 reportSchemaError(code, new Object[] { field.toString(), cName });
  3871                 reportSchemaError(code, new Object[] { field.toString(), cName });
  3669             } else {
  3872             }
       
  3873             else {
  3670                 fValuesCount++;
  3874                 fValuesCount++;
  3671             }
  3875             }
  3672             fLocalValues[i] = actualValue;
  3876             fLocalValues[i] = actualValue;
  3673             fLocalValueTypes[i] = valueType;
  3877             fLocalValueTypes[i] = valueType;
  3674             fLocalItemValueTypes[i] = itemValueType;
  3878             fLocalItemValueTypes[i] = itemValueType;
  3813             if (length == 1) {
  4017             if (length == 1) {
  3814                 return String.valueOf(values.elementAt(start));
  4018                 return String.valueOf(values.elementAt(start));
  3815             }
  4019             }
  3816 
  4020 
  3817             // construct value string
  4021             // construct value string
  3818             StringBuffer str = new StringBuffer();
  4022             StringBuilder str = new StringBuilder();
  3819             for (int i = 0; i < length; i++) {
  4023             for (int i = 0; i < length; i++) {
  3820                 if (i > 0) {
  4024                 if (i > 0) {
  3821                     str.append(',');
  4025                     str.append(',');
  3822                 }
  4026                 }
  3823                 str.append(values.elementAt(start + i));
  4027                 str.append(values.elementAt(start + i));
  4073         //
  4277         //
  4074         final LocalIDKey fLocalId = new LocalIDKey();
  4278         final LocalIDKey fLocalId = new LocalIDKey();
  4075         // values stores
  4279         // values stores
  4076 
  4280 
  4077         /** stores all global Values stores. */
  4281         /** stores all global Values stores. */
  4078         protected final Vector fValueStores = new Vector();
  4282         protected final ArrayList fValueStores = new ArrayList();
  4079 
  4283 
  4080         /**
  4284         /**
  4081          * Values stores associated to specific identity constraints.
  4285          * Values stores associated to specific identity constraints.
  4082          * This hashtable maps IdentityConstraints and
  4286          * This hashtable maps IdentityConstraints and
  4083          * the 0-based element on which their selectors first matched to
  4287          * the 0-based element on which their selectors first matched to
  4084          * a corresponding ValueStore.  This should take care
  4288          * a corresponding ValueStore.  This should take care
  4085          * of all cases, including where ID constraints with
  4289          * of all cases, including where ID constraints with
  4086          * descendant-or-self axes occur on recursively-defined
  4290          * descendant-or-self axes occur on recursively-defined
  4087          * elements.
  4291          * elements.
  4088          */
  4292          */
  4089         protected final Hashtable fIdentityConstraint2ValueStoreMap = new Hashtable();
  4293         protected final HashMap fIdentityConstraint2ValueStoreMap = new HashMap();
  4090 
  4294 
  4091         // sketch of algorithm:
  4295         // sketch of algorithm:
  4092         // - when a constraint is first encountered, its
  4296         // - when a constraint is first encountered, its
  4093         //   values are stored in the (local) fIdentityConstraint2ValueStoreMap;
  4297         //   values are stored in the (local) fIdentityConstraint2ValueStoreMap;
  4094         // - Once it is validated (i.e., when it goes out of scope),
  4298         // - Once it is validated (i.e., when it goes out of scope),
  4106         // i.e., the top of the fGlobalIDMapStack always contains
  4310         // i.e., the top of the fGlobalIDMapStack always contains
  4107         // the preceding siblings' eligible id constraints;
  4311         // the preceding siblings' eligible id constraints;
  4108         // the fGlobalIDConstraintMap contains descendants+self.
  4312         // the fGlobalIDConstraintMap contains descendants+self.
  4109         // keyrefs can only match descendants+self.
  4313         // keyrefs can only match descendants+self.
  4110         protected final Stack fGlobalMapStack = new Stack();
  4314         protected final Stack fGlobalMapStack = new Stack();
  4111         protected final Hashtable fGlobalIDConstraintMap = new Hashtable();
  4315         protected final HashMap fGlobalIDConstraintMap = new HashMap();
  4112 
  4316 
  4113         //
  4317         //
  4114         // Constructors
  4318         // Constructors
  4115         //
  4319         //
  4116 
  4320 
  4122         // Public methods
  4326         // Public methods
  4123         //
  4327         //
  4124 
  4328 
  4125         /** Resets the identity constraint cache. */
  4329         /** Resets the identity constraint cache. */
  4126         public void startDocument() {
  4330         public void startDocument() {
  4127             fValueStores.removeAllElements();
  4331             fValueStores.clear();
  4128             fIdentityConstraint2ValueStoreMap.clear();
  4332             fIdentityConstraint2ValueStoreMap.clear();
  4129             fGlobalIDConstraintMap.clear();
  4333             fGlobalIDConstraintMap.clear();
  4130             fGlobalMapStack.removeAllElements();
  4334             fGlobalMapStack.removeAllElements();
  4131         } // startDocument()
  4335         } // startDocument()
  4132 
  4336 
  4133         // startElement:  pushes the current fGlobalIDConstraintMap
  4337         // startElement:  pushes the current fGlobalIDConstraintMap
  4134         // onto fGlobalMapStack and clears fGlobalIDConstraint map.
  4338         // onto fGlobalMapStack and clears fGlobalIDConstraint map.
  4135         public void startElement() {
  4339         public void startElement() {
  4136             // only clone the hashtable when there are elements
  4340             // only clone the map when there are elements
  4137             if (fGlobalIDConstraintMap.size() > 0)
  4341             if (fGlobalIDConstraintMap.size() > 0)
  4138                 fGlobalMapStack.push(fGlobalIDConstraintMap.clone());
  4342                 fGlobalMapStack.push(fGlobalIDConstraintMap.clone());
  4139             else
  4343             else
  4140                 fGlobalMapStack.push(null);
  4344                 fGlobalMapStack.push(null);
  4141             fGlobalIDConstraintMap.clear();
  4345             fGlobalIDConstraintMap.clear();
  4146          */
  4350          */
  4147         public void endElement() {
  4351         public void endElement() {
  4148             if (fGlobalMapStack.isEmpty()) {
  4352             if (fGlobalMapStack.isEmpty()) {
  4149                 return; // must be an invalid doc!
  4353                 return; // must be an invalid doc!
  4150             }
  4354             }
  4151             Hashtable oldMap = (Hashtable) fGlobalMapStack.pop();
  4355             HashMap oldMap = (HashMap) fGlobalMapStack.pop();
  4152             // return if there is no element
  4356             // return if there is no element
  4153             if (oldMap == null) {
  4357             if (oldMap == null) {
  4154                 return;
  4358                 return;
  4155             }
  4359             }
  4156 
  4360 
  4191                             uniqueValueStore = new UniqueValueStore(unique);
  4395                             uniqueValueStore = new UniqueValueStore(unique);
  4192                             fIdentityConstraint2ValueStoreMap.put(toHash, uniqueValueStore);
  4396                             fIdentityConstraint2ValueStoreMap.put(toHash, uniqueValueStore);
  4193                         } else {
  4397                         } else {
  4194                             uniqueValueStore.clear();
  4398                             uniqueValueStore.clear();
  4195                         }
  4399                         }
  4196                         fValueStores.addElement(uniqueValueStore);
  4400                         fValueStores.add(uniqueValueStore);
  4197                         activateSelectorFor(icArray[i]);
  4401                         activateSelectorFor(icArray[i]);
  4198                         break;
  4402                         break;
  4199                     case (IdentityConstraint.IC_KEY) :
  4403                     case (IdentityConstraint.IC_KEY) :
  4200                         // initialize value stores for key fields
  4404                         // initialize value stores for key fields
  4201                         UniqueOrKey key = (UniqueOrKey) icArray[i];
  4405                         UniqueOrKey key = (UniqueOrKey) icArray[i];
  4206                             keyValueStore = new KeyValueStore(key);
  4410                             keyValueStore = new KeyValueStore(key);
  4207                             fIdentityConstraint2ValueStoreMap.put(toHash, keyValueStore);
  4411                             fIdentityConstraint2ValueStoreMap.put(toHash, keyValueStore);
  4208                         } else {
  4412                         } else {
  4209                             keyValueStore.clear();
  4413                             keyValueStore.clear();
  4210                         }
  4414                         }
  4211                         fValueStores.addElement(keyValueStore);
  4415                         fValueStores.add(keyValueStore);
  4212                         activateSelectorFor(icArray[i]);
  4416                         activateSelectorFor(icArray[i]);
  4213                         break;
  4417                         break;
  4214                     case (IdentityConstraint.IC_KEYREF) :
  4418                     case (IdentityConstraint.IC_KEYREF) :
  4215                         // initialize value stores for keyRef fields
  4419                         // initialize value stores for keyRef fields
  4216                         KeyRef keyRef = (KeyRef) icArray[i];
  4420                         KeyRef keyRef = (KeyRef) icArray[i];
  4221                             keyRefValueStore = new KeyRefValueStore(keyRef, null);
  4425                             keyRefValueStore = new KeyRefValueStore(keyRef, null);
  4222                             fIdentityConstraint2ValueStoreMap.put(toHash, keyRefValueStore);
  4426                             fIdentityConstraint2ValueStoreMap.put(toHash, keyRefValueStore);
  4223                         } else {
  4427                         } else {
  4224                             keyRefValueStore.clear();
  4428                             keyRefValueStore.clear();
  4225                         }
  4429                         }
  4226                         fValueStores.addElement(keyRefValueStore);
  4430                         fValueStores.add(keyRefValueStore);
  4227                         activateSelectorFor(icArray[i]);
  4431                         activateSelectorFor(icArray[i]);
  4228                         break;
  4432                         break;
  4229                 }
  4433                 }
  4230             }
  4434             }
  4231         } // initValueStoresFor(XSElementDecl)
  4435         } // initValueStoresFor(XSElementDecl)
  4265         /** Check identity constraints. */
  4469         /** Check identity constraints. */
  4266         public void endDocument() {
  4470         public void endDocument() {
  4267 
  4471 
  4268             int count = fValueStores.size();
  4472             int count = fValueStores.size();
  4269             for (int i = 0; i < count; i++) {
  4473             for (int i = 0; i < count; i++) {
  4270                 ValueStoreBase valueStore = (ValueStoreBase) fValueStores.elementAt(i);
  4474                 ValueStoreBase valueStore = (ValueStoreBase) fValueStores.get(i);
  4271                 valueStore.endDocument();
  4475                 valueStore.endDocument();
  4272             }
  4476             }
  4273 
  4477 
  4274         } // endDocument()
  4478         } // endDocument()
  4275 
  4479 
  4293 
  4497 
  4294     } // class ValueStoreCache
  4498     } // class ValueStoreCache
  4295 
  4499 
  4296     // the purpose of this class is to enable IdentityConstraint,int
  4500     // the purpose of this class is to enable IdentityConstraint,int
  4297     // pairs to be used easily as keys in Hashtables.
  4501     // pairs to be used easily as keys in Hashtables.
  4298     protected class LocalIDKey {
  4502     protected static final class LocalIDKey {
  4299 
  4503 
  4300         public IdentityConstraint fId;
  4504         public IdentityConstraint fId;
  4301         public int fDepth;
  4505         public int fDepth;
  4302 
  4506 
  4303         public LocalIDKey() {
  4507         public LocalIDKey() {