jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSDHandler.java
changeset 36146 eca249f3c768
parent 35729 49f1515c5f5c
child 39080 57563e513b11
equal deleted inserted replaced
36047:1c076468bf7d 36146:eca249f3c768
     1 /*
     1 /*
     2  * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
     3  */
     3  */
     4 /*
     4 /*
     5  * Licensed to the Apache Software Foundation (ASF) under one or more
     5  * Licensed to the Apache Software Foundation (ASF) under one or more
     6  * contributor license agreements.  See the NOTICE file distributed with
     6  * contributor license agreements.  See the NOTICE file distributed with
     7  * this work for additional information regarding copyright ownership.
     7  * this work for additional information regarding copyright ownership.
   192         Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;
   192         Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;
   193 
   193 
   194     /** Property identifier: entity resolver. */
   194     /** Property identifier: entity resolver. */
   195     public static final String ENTITY_RESOLVER =
   195     public static final String ENTITY_RESOLVER =
   196         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
   196         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
       
   197 
   197     /** Property identifier: entity manager. */
   198     /** Property identifier: entity manager. */
   198     protected static final String ENTITY_MANAGER =
   199     protected static final String ENTITY_MANAGER =
   199         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
   200         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
   200 
   201 
   201     /** Property identifier: error reporter. */
   202     /** Property identifier: error reporter. */
   212 
   213 
   213     /** Property identifier: security manager. */
   214     /** Property identifier: security manager. */
   214     protected static final String SECURITY_MANAGER =
   215     protected static final String SECURITY_MANAGER =
   215         Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY;
   216         Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY;
   216 
   217 
   217     private static final String SECURE_PROCESSING =
       
   218         Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY;
       
   219 
       
   220     /** Property identifier: locale. */
   218     /** Property identifier: locale. */
   221     protected static final String LOCALE =
   219     protected static final String LOCALE =
   222         Constants.XERCES_PROPERTY_PREFIX + Constants.LOCALE_PROPERTY;
   220         Constants.XERCES_PROPERTY_PREFIX + Constants.LOCALE_PROPERTY;
   223 
   221 
   224         /** Property identifier: Security property manager. */
   222     /** Property identifier: Security property manager. */
   225     private static final String XML_SECURITY_PROPERTY_MANAGER =
   223     private static final String XML_SECURITY_PROPERTY_MANAGER =
   226             Constants.XML_SECURITY_PROPERTY_MANAGER;
   224         Constants.XML_SECURITY_PROPERTY_MANAGER;
   227 
   225 
   228     protected static final boolean DEBUG_NODE_POOL = false;
   226     protected static final boolean DEBUG_NODE_POOL = false;
   229 
   227 
   230     // Data
   228     // Data
   231 
   229 
   241 
   239 
   242     // this string gets appended to redefined names; it's purpose is to be
   240     // this string gets appended to redefined names; it's purpose is to be
   243     // as unlikely as possible to cause collisions.
   241     // as unlikely as possible to cause collisions.
   244     public final static String REDEF_IDENTIFIER = "_fn3dktizrknc9pi";
   242     public final static String REDEF_IDENTIFIER = "_fn3dktizrknc9pi";
   245 
   243 
   246     //
   244     //protected data that can be accessible by any traverser
   247     //protected data that can be accessable by any traverser
       
   248 
   245 
   249     protected XSDeclarationPool fDeclPool = null;
   246     protected XSDeclarationPool fDeclPool = null;
   250 
   247 
   251     /**
   248     // the Security manager in effect.
   252      * <p>Security manager in effect.</p>
   249     protected XMLSecurityManager fSecurityManager = null;
   253      *
       
   254      * <p>Protected to allow access by any traverser.</p>
       
   255      */
       
   256     protected XMLSecurityManager fSecureProcessing = null;
       
   257 
   250 
   258     private String fAccessExternalSchema;
   251     private String fAccessExternalSchema;
   259     private String fAccessExternalDTD;
   252     private String fAccessExternalDTD;
   260 
   253 
   261     // These tables correspond to the symbol spaces defined in the
   254     // These tables correspond to the symbol spaces defined in the
   264     // their values are nodes corresponding to the given name's decl.
   257     // their values are nodes corresponding to the given name's decl.
   265     // By asking the node for its ownerDocument and looking in
   258     // By asking the node for its ownerDocument and looking in
   266     // XSDocumentInfoRegistry we can easily get the corresponding
   259     // XSDocumentInfoRegistry we can easily get the corresponding
   267     // XSDocumentInfo object.
   260     // XSDocumentInfo object.
   268     private boolean registryEmpty = true;
   261     private boolean registryEmpty = true;
   269     private Map<String, Element> fUnparsedAttributeRegistry = new HashMap();
   262     private Map<String, Element> fUnparsedAttributeRegistry = new HashMap<>();
   270     private Map<String, Element> fUnparsedAttributeGroupRegistry =  new HashMap();
   263     private Map<String, Element> fUnparsedAttributeGroupRegistry =  new HashMap<>();
   271     private Map<String, Element> fUnparsedElementRegistry =  new HashMap();
   264     private Map<String, Element> fUnparsedElementRegistry =  new HashMap<>();
   272     private Map<String, Element> fUnparsedGroupRegistry =  new HashMap();
   265     private Map<String, Element> fUnparsedGroupRegistry =  new HashMap<>();
   273     private Map<String, Element> fUnparsedIdentityConstraintRegistry =  new HashMap();
   266     private Map<String, Element> fUnparsedIdentityConstraintRegistry =  new HashMap<>();
   274     private Map<String, Element> fUnparsedNotationRegistry =  new HashMap();
   267     private Map<String, Element> fUnparsedNotationRegistry =  new HashMap<>();
   275     private Map<String, Element> fUnparsedTypeRegistry =  new HashMap();
   268     private Map<String, Element> fUnparsedTypeRegistry =  new HashMap<>();
   276     // Compensation for the above maps to locate XSDocumentInfo,
   269     // Compensation for the above maps to locate XSDocumentInfo,
   277     // Since we may take Schema Element directly, so can not get the
   270     // Since we may take Schema Element directly, so can not get the
   278     // corresponding XSDocumentInfo object just using above maps.
   271     // corresponding XSDocumentInfo object just using above maps.
   279     private Map<String, XSDocumentInfo> fUnparsedAttributeRegistrySub =  new HashMap();
   272     private Map<String, XSDocumentInfo> fUnparsedAttributeRegistrySub =  new HashMap<>();
   280     private Map<String, XSDocumentInfo> fUnparsedAttributeGroupRegistrySub =  new HashMap();
   273     private Map<String, XSDocumentInfo> fUnparsedAttributeGroupRegistrySub =  new HashMap<>();
   281     private Map<String, XSDocumentInfo> fUnparsedElementRegistrySub =  new HashMap();
   274     private Map<String, XSDocumentInfo> fUnparsedElementRegistrySub =  new HashMap<>();
   282     private Map<String, XSDocumentInfo> fUnparsedGroupRegistrySub =  new HashMap();
   275     private Map<String, XSDocumentInfo> fUnparsedGroupRegistrySub =  new HashMap<>();
   283     private Map<String, XSDocumentInfo> fUnparsedIdentityConstraintRegistrySub =  new HashMap();
   276     private Map<String, XSDocumentInfo> fUnparsedIdentityConstraintRegistrySub =  new HashMap<>();
   284     private Map<String, XSDocumentInfo> fUnparsedNotationRegistrySub =  new HashMap();
   277     private Map<String, XSDocumentInfo> fUnparsedNotationRegistrySub =  new HashMap<>();
   285     private Map<String, XSDocumentInfo> fUnparsedTypeRegistrySub =  new HashMap();
   278     private Map<String, XSDocumentInfo> fUnparsedTypeRegistrySub =  new HashMap<>();
   286 
   279 
   287     // Stores XSDocumentInfo (keyed by component name), to check for duplicate
   280     // Stores XSDocumentInfo (keyed by component name), to check for duplicate
   288     // components declared within the same xsd document
   281     // components declared within the same xsd document
   289     private Map fUnparsedRegistriesExt[] = new HashMap[] {
   282     @SuppressWarnings("unchecked")
       
   283     private Map<String, XSDocumentInfo> fUnparsedRegistriesExt[] = new HashMap[] {
   290         null,
   284         null,
   291         null, // ATTRIBUTE_TYPE
   285         null, // ATTRIBUTE_TYPE
   292         null, // ATTRIBUTEGROUP_TYPE
   286         null, // ATTRIBUTEGROUP_TYPE
   293         null, // ELEMENT_TYPE
   287         null, // ELEMENT_TYPE
   294         null, // GROUP_TYPE
   288         null, // GROUP_TYPE
   298     };
   292     };
   299 
   293 
   300     // this map is keyed on by XSDocumentInfo objects.  Its values
   294     // this map is keyed on by XSDocumentInfo objects.  Its values
   301     // are Vectors containing the XSDocumentInfo objects <include>d,
   295     // are Vectors containing the XSDocumentInfo objects <include>d,
   302     // <import>ed or <redefine>d by the key XSDocumentInfo.
   296     // <import>ed or <redefine>d by the key XSDocumentInfo.
   303     private Map<XSDocumentInfo, Vector> fDependencyMap = new HashMap();
   297     private Map<XSDocumentInfo, Vector<XSDocumentInfo>> fDependencyMap = new HashMap<>();
   304 
   298 
   305     // this map is keyed on by a target namespace.  Its values
   299     // this map is keyed on by a target namespace.  Its values
   306     // are Vectors containing namespaces imported by schema documents
   300     // are Vectors containing namespaces imported by schema documents
   307     // with the key target namespace.
   301     // with the key target namespace.
   308     // if an imprted schema has absent namespace, the value "null" is stored.
   302     // if an imported schema has absent namespace, the value "null" is stored.
   309     private Map<String, Vector> fImportMap = new HashMap();
   303     private Map<String, Vector> fImportMap = new HashMap<> ();
       
   304 
   310     // all namespaces that imports other namespaces
   305     // all namespaces that imports other namespaces
   311     // if the importing schema has absent namespace, empty string is stored.
   306     // if the importing schema has absent namespace, empty string is stored.
   312     // (because the key of a map can't be null.)
   307     // (because the key of a map can't be null.)
   313     private Vector fAllTNSs = new Vector();
   308     private Vector<String> fAllTNSs = new Vector<>();
       
   309 
   314     // stores instance document mappings between namespaces and schema hints
   310     // stores instance document mappings between namespaces and schema hints
   315     private Map<String, XMLSchemaLoader.LocationArray> fLocationPairs = null;
   311     private Map<String, XMLSchemaLoader.LocationArray> fLocationPairs = null;
   316 
   312 
   317     // Records which nodes are hidden when the input is a DOMInputSource.
   313     // Records which nodes are hidden when the input is a DOMInputSource.
   318     Map<Node, String> fHiddenNodes = null;
   314     Map<Node, String> fHiddenNodes = null;
   331          * REVISIT: Casting until DOM Level 3 interfaces are available. -- mrglavas
   327          * REVISIT: Casting until DOM Level 3 interfaces are available. -- mrglavas
   332          */
   328          */
   333         if(ele.getOwnerDocument() instanceof com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM){
   329         if(ele.getOwnerDocument() instanceof com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM){
   334             documentURI = ((com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM) ele.getOwnerDocument()).getDocumentURI();
   330             documentURI = ((com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM) ele.getOwnerDocument()).getDocumentURI();
   335         }
   331         }
   336         return documentURI != null ? documentURI : (String) fDoc2SystemId.get(ele);
   332         return documentURI != null ? documentURI : fDoc2SystemId.get(ele);
   337     }
   333     }
   338 
   334 
   339     // This vector stores strings which are combinations of the
   335     // This vector stores strings which are combinations of the
   340     // publicId and systemId of the inputSource corresponding to a
   336     // publicId and systemId of the inputSource corresponding to a
   341     // schema document.  This combination is used so that the user's
   337     // schema document.  This combination is used so that the user's
   342     // EntityResolver can provide a consistent way of identifying a
   338     // EntityResolver can provide a consistent way of identifying a
   343     // schema document that is included in multiple other schemas.
   339     // schema document that is included in multiple other schemas.
   344     private Map fTraversed = new HashMap();
   340     private Map<XSDKey, Element> fTraversed = new HashMap<>();
   345 
   341 
   346     // this map contains a mapping from Schema Element to its systemId
   342     // this map contains a mapping from Schema Element to its systemId
   347     // this is useful to resolve a uri relative to the referring document
   343     // this is useful to resolve a uri relative to the referring document
   348     private Map fDoc2SystemId = new HashMap();
   344     private Map<Element, String> fDoc2SystemId = new HashMap<>();
   349 
   345 
   350     // the primary XSDocumentInfo we were called to parse
   346     // the primary XSDocumentInfo we were called to parse
   351     private XSDocumentInfo fRoot = null;
   347     private XSDocumentInfo fRoot = null;
   352 
   348 
   353     // This map's job is to act as a link between the Schema Element and its
   349     // This map's job is to act as a link between the Schema Element and its
   385     // handle tolerate duplicates feature
   381     // handle tolerate duplicates feature
   386     boolean fTolerateDuplicates = false;
   382     boolean fTolerateDuplicates = false;
   387 
   383 
   388     // the XMLErrorReporter
   384     // the XMLErrorReporter
   389     private XMLErrorReporter fErrorReporter;
   385     private XMLErrorReporter fErrorReporter;
   390     private XMLEntityResolver fEntityResolver;
   386 
       
   387     // the XMLErrorHandler
       
   388     private XMLErrorHandler fErrorHandler;
       
   389 
       
   390     // the Locale
       
   391     private Locale fLocale;
       
   392 
       
   393     // the XMLEntityManager
       
   394     private XMLEntityResolver fEntityManager;
   391 
   395 
   392     // the XSAttributeChecker
   396     // the XSAttributeChecker
   393     private XSAttributeChecker fAttributeChecker;
   397     private XSAttributeChecker fAttributeChecker;
   394 
   398 
   395     // the symbol table
   399     // the symbol table
   401     // the Grammar description
   405     // the Grammar description
   402     private XSDDescription fSchemaGrammarDescription;
   406     private XSDDescription fSchemaGrammarDescription;
   403 
   407 
   404     // the Grammar Pool
   408     // the Grammar Pool
   405     private XMLGrammarPool fGrammarPool;
   409     private XMLGrammarPool fGrammarPool;
       
   410 
       
   411     // the security property manager
       
   412     private XMLSecurityPropertyManager fSecurityPropertyMgr = null;
   406 
   413 
   407     //************ Traversers **********
   414     //************ Traversers **********
   408     XSDAttributeGroupTraverser fAttributeGroupTraverser;
   415     XSDAttributeGroupTraverser fAttributeGroupTraverser;
   409     XSDAttributeTraverser fAttributeTraverser;
   416     XSDAttributeTraverser fAttributeTraverser;
   410     XSDComplexTypeTraverser fComplexTypeTraverser;
   417     XSDComplexTypeTraverser fComplexTypeTraverser;
   636 
   643 
   637         // seventh phase:  store imported grammars
   644         // seventh phase:  store imported grammars
   638         // for all grammars with <import>s
   645         // for all grammars with <import>s
   639         for (int i = fAllTNSs.size() - 1; i >= 0; i--) {
   646         for (int i = fAllTNSs.size() - 1; i >= 0; i--) {
   640             // get its target namespace
   647             // get its target namespace
   641             String tns = (String)fAllTNSs.elementAt(i);
   648             String tns = fAllTNSs.elementAt(i);
   642             // get all namespaces it imports
   649             // get all namespaces it imports
   643             Vector ins = (Vector)fImportMap.get(tns);
   650             Vector ins = (Vector)fImportMap.get(tns);
   644             // get the grammar
   651             // get the grammar
   645             SchemaGrammar sg = fGrammarBucket.getGrammar(emptyString2Null(tns));
   652             SchemaGrammar sg = fGrammarBucket.getGrammar(emptyString2Null(tns));
   646             if (sg == null)
   653             if (sg == null)
   694         fAnnotationValidator = new XML11Configuration();
   701         fAnnotationValidator = new XML11Configuration();
   695         fGrammarBucketAdapter = new XSAnnotationGrammarPool();
   702         fGrammarBucketAdapter = new XSAnnotationGrammarPool();
   696         fAnnotationValidator.setFeature(VALIDATION, true);
   703         fAnnotationValidator.setFeature(VALIDATION, true);
   697         fAnnotationValidator.setFeature(XMLSCHEMA_VALIDATION, true);
   704         fAnnotationValidator.setFeature(XMLSCHEMA_VALIDATION, true);
   698         fAnnotationValidator.setProperty(XMLGRAMMAR_POOL, fGrammarBucketAdapter);
   705         fAnnotationValidator.setProperty(XMLGRAMMAR_POOL, fGrammarBucketAdapter);
       
   706         /** set security manager and XML Security Property Manager **/
       
   707         fAnnotationValidator.setProperty(SECURITY_MANAGER, (fSecurityManager != null) ? fSecurityManager : new XMLSecurityManager(true));
       
   708         fAnnotationValidator.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
   699         /** Set error handler. **/
   709         /** Set error handler. **/
   700         XMLErrorHandler errorHandler = fErrorReporter.getErrorHandler();
   710         fAnnotationValidator.setProperty(ERROR_HANDLER, (fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler());
   701         fAnnotationValidator.setProperty(ERROR_HANDLER, (errorHandler != null) ? errorHandler : new DefaultErrorHandler());
       
   702         /** Set locale. **/
   711         /** Set locale. **/
   703         Locale locale = fErrorReporter.getLocale();
   712         fAnnotationValidator.setProperty(LOCALE, fLocale);
   704         fAnnotationValidator.setProperty(LOCALE, locale);
       
   705     }
   713     }
   706 
   714 
   707     /**
   715     /**
   708      * Pull the grammar out of the bucket simply using
   716      * Pull the grammar out of the bucket simply using
   709      * its TNS as a key
   717      * its TNS as a key
   878             fGrammarBucket.putGrammar(sg);
   886             fGrammarBucket.putGrammar(sg);
   879         }
   887         }
   880 
   888 
   881         // store the document and its location
   889         // store the document and its location
   882         // REVISIT: don't expose the DOM tree
   890         // REVISIT: don't expose the DOM tree
   883         sg.addDocument(null, (String)fDoc2SystemId.get(currSchemaInfo.fSchemaElement));
   891         sg.addDocument(null, fDoc2SystemId.get(currSchemaInfo.fSchemaElement));
   884 
   892 
   885         fDoc2XSDocumentMap.put(schemaRoot, currSchemaInfo);
   893         fDoc2XSDocumentMap.put(schemaRoot, currSchemaInfo);
   886         Vector dependencies = new Vector();
   894         Vector<XSDocumentInfo> dependencies = new Vector<>();
   887         Element rootNode = schemaRoot;
   895         Element rootNode = schemaRoot;
   888 
   896 
   889         Element newSchemaRoot = null;
   897         Element newSchemaRoot = null;
   890         for (Element child = DOMUtil.getFirstChildElement(rootNode);
   898         for (Element child = DOMUtil.getFirstChildElement(rootNode);
   891         child != null;
   899         child != null;
  1332                     }
  1340                     }
  1333                 }
  1341                 }
  1334             } // end for
  1342             } // end for
  1335 
  1343 
  1336             // now we're done with this one!
  1344             // now we're done with this one!
  1337                 DOMUtil.setHidden(currDoc, fHiddenNodes);
  1345             DOMUtil.setHidden(currDoc, fHiddenNodes);
  1338             // now add the schemas this guy depends on
  1346             // now add the schemas this guy depends on
  1339             Vector currSchemaDepends = (Vector)fDependencyMap.get(currSchemaDoc);
  1347             Vector<XSDocumentInfo> currSchemaDepends = fDependencyMap.get(currSchemaDoc);
  1340             for (int i = 0; i < currSchemaDepends.size(); i++) {
  1348             for (int i = 0; i < currSchemaDepends.size(); i++) {
  1341                 schemasToProcess.push(currSchemaDepends.elementAt(i));
  1349                 schemasToProcess.push(currSchemaDepends.elementAt(i));
  1342             }
  1350             }
  1343         } // while
  1351         } // while
  1344 
  1352 
  1464             // now we're done with this one!
  1472             // now we're done with this one!
  1465             currSchemaDoc.returnSchemaAttrs();
  1473             currSchemaDoc.returnSchemaAttrs();
  1466             DOMUtil.setHidden(currDoc, fHiddenNodes);
  1474             DOMUtil.setHidden(currDoc, fHiddenNodes);
  1467 
  1475 
  1468             // now add the schemas this guy depends on
  1476             // now add the schemas this guy depends on
  1469             Vector currSchemaDepends = (Vector)fDependencyMap.get(currSchemaDoc);
  1477             Vector<XSDocumentInfo> currSchemaDepends = fDependencyMap.get(currSchemaDoc);
  1470             for (int i = 0; i < currSchemaDepends.size(); i++) {
  1478             for (int i = 0; i < currSchemaDepends.size(); i++) {
  1471                 schemasToProcess.push(currSchemaDepends.elementAt(i));
  1479                 schemasToProcess.push(currSchemaDepends.elementAt(i));
  1472             }
  1480             }
  1473         } // while
  1481         } // while
  1474     } // end traverseSchemas
  1482     } // end traverseSchemas
  1913 
  1921 
  1914         return retObj;
  1922         return retObj;
  1915     }
  1923     }
  1916 
  1924 
  1917     public String schemaDocument2SystemId(XSDocumentInfo schemaDoc) {
  1925     public String schemaDocument2SystemId(XSDocumentInfo schemaDoc) {
  1918         return (String)fDoc2SystemId.get(schemaDoc.fSchemaElement);
  1926         return fDoc2SystemId.get(schemaDoc.fSchemaElement);
  1919     }
  1927     }
  1920 
  1928 
  1921     // This method determines whether there is a group
  1929     // This method determines whether there is a group
  1922     // (attributeGroup) which the given one has redefined by
  1930     // (attributeGroup) which the given one has redefined by
  1923     // restriction.  If so, it returns it; else it returns null.
  1931     // restriction.  If so, it returns it; else it returns null.
  2042     private Element resolveSchema(XSDDescription desc, boolean mustResolve,
  2050     private Element resolveSchema(XSDDescription desc, boolean mustResolve,
  2043                                   Element referElement, boolean usePairs) {
  2051                                   Element referElement, boolean usePairs) {
  2044         XMLInputSource schemaSource = null;
  2052         XMLInputSource schemaSource = null;
  2045         try {
  2053         try {
  2046             Map<String, XMLSchemaLoader.LocationArray> pairs = usePairs ? fLocationPairs : Collections.emptyMap();
  2054             Map<String, XMLSchemaLoader.LocationArray> pairs = usePairs ? fLocationPairs : Collections.emptyMap();
  2047             schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityResolver);
  2055             schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityManager);
  2048         }
  2056         }
  2049         catch (IOException ex) {
  2057         catch (IOException ex) {
  2050             if (mustResolve) {
  2058             if (mustResolve) {
  2051                 reportSchemaError("schema_reference.4",
  2059                 reportSchemaError("schema_reference.4",
  2052                         new Object[]{desc.getLocationHints()[0]},
  2060                         new Object[]{desc.getLocationHints()[0]},
  2095             Element referElement, boolean usePairs) {
  2103             Element referElement, boolean usePairs) {
  2096 
  2104 
  2097         XMLInputSource schemaSource = null;
  2105         XMLInputSource schemaSource = null;
  2098         try {
  2106         try {
  2099             Map<String, XMLSchemaLoader.LocationArray> pairs = usePairs ? fLocationPairs : Collections.emptyMap();
  2107             Map<String, XMLSchemaLoader.LocationArray> pairs = usePairs ? fLocationPairs : Collections.emptyMap();
  2100             schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityResolver);
  2108             schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityManager);
  2101         }
  2109         }
  2102         catch (IOException ex) {
  2110         catch (IOException ex) {
  2103             if (mustResolve) {
  2111             if (mustResolve) {
  2104                 reportSchemaError("schema_reference.4",
  2112                 reportSchemaError("schema_reference.4",
  2105                         new Object[]{desc.getLocationHints()[0]},
  2113                         new Object[]{desc.getLocationHints()[0]},
  2150                 XSDKey key = null;
  2158                 XSDKey key = null;
  2151                 String schemaId = null;
  2159                 String schemaId = null;
  2152                 if (referType != XSDDescription.CONTEXT_PREPARSE){
  2160                 if (referType != XSDDescription.CONTEXT_PREPARSE){
  2153                     schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(), schemaSource.getBaseSystemId(), false);
  2161                     schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(), schemaSource.getBaseSystemId(), false);
  2154                     key = new XSDKey(schemaId, referType, schemaNamespace);
  2162                     key = new XSDKey(schemaId, referType, schemaNamespace);
  2155                     if((schemaElement = (Element)fTraversed.get(key)) != null) {
  2163                     if((schemaElement = fTraversed.get(key)) != null) {
  2156                         fLastSchemaWasDuplicate = true;
  2164                         fLastSchemaWasDuplicate = true;
  2157                         return schemaElement;
  2165                         return schemaElement;
  2158                     }
  2166                     }
  2159                     if (referType == XSDDescription.CONTEXT_IMPORT || referType == XSDDescription.CONTEXT_INCLUDE
  2167                     if (referType == XSDDescription.CONTEXT_IMPORT || referType == XSDDescription.CONTEXT_INCLUDE
  2160                             || referType == XSDDescription.CONTEXT_REDEFINE) {
  2168                             || referType == XSDDescription.CONTEXT_REDEFINE) {
  2209                 XSDKey key = null;
  2217                 XSDKey key = null;
  2210                 String schemaId = null;
  2218                 String schemaId = null;
  2211                 if (referType != XSDDescription.CONTEXT_PREPARSE) {
  2219                 if (referType != XSDDescription.CONTEXT_PREPARSE) {
  2212                     schemaId = XMLEntityManager.expandSystemId(inputSource.getSystemId(), schemaSource.getBaseSystemId(), false);
  2220                     schemaId = XMLEntityManager.expandSystemId(inputSource.getSystemId(), schemaSource.getBaseSystemId(), false);
  2213                     key = new XSDKey(schemaId, referType, schemaNamespace);
  2221                     key = new XSDKey(schemaId, referType, schemaNamespace);
  2214                     if ((schemaElement = (Element) fTraversed.get(key)) != null) {
  2222                     if ((schemaElement = fTraversed.get(key)) != null) {
  2215                         fLastSchemaWasDuplicate = true;
  2223                         fLastSchemaWasDuplicate = true;
  2216                         return schemaElement;
  2224                         return schemaElement;
  2217                     }
  2225                     }
  2218                 }
  2226                 }
  2219 
  2227 
  2236                     try {
  2244                     try {
  2237                         parser.setFeature(NAMESPACE_PREFIXES, true);
  2245                         parser.setFeature(NAMESPACE_PREFIXES, true);
  2238                         namespacePrefixes = true;
  2246                         namespacePrefixes = true;
  2239                         // If this is a Xerces SAX parser set the security manager if there is one
  2247                         // If this is a Xerces SAX parser set the security manager if there is one
  2240                         if (parser instanceof SAXParser) {
  2248                         if (parser instanceof SAXParser) {
  2241                             Object securityManager = fSchemaParser.getProperty(SECURITY_MANAGER);
  2249                             if (fSecurityManager != null) {
  2242                             if (securityManager != null) {
  2250                                 parser.setProperty(SECURITY_MANAGER, fSecurityManager);
  2243                                 parser.setProperty(SECURITY_MANAGER, securityManager);
       
  2244                             }
  2251                             }
  2245                         }
  2252                         }
  2246                     }
  2253                     }
  2247                     catch (SAXException se) {}
  2254                     catch (SAXException se) {}
  2248 
  2255 
  2345                             isDocument = (parent.getNodeType() == Node.DOCUMENT_NODE);
  2352                             isDocument = (parent.getNodeType() == Node.DOCUMENT_NODE);
  2346                         }
  2353                         }
  2347                     }
  2354                     }
  2348                     if (isDocument) {
  2355                     if (isDocument) {
  2349                         key = new XSDKey(schemaId, referType, schemaNamespace);
  2356                         key = new XSDKey(schemaId, referType, schemaNamespace);
  2350                         if ((schemaElement = (Element) fTraversed.get(key)) != null) {
  2357                         if ((schemaElement = fTraversed.get(key)) != null) {
  2351                             fLastSchemaWasDuplicate = true;
  2358                             fLastSchemaWasDuplicate = true;
  2352                             return schemaElement;
  2359                             return schemaElement;
  2353                         }
  2360                         }
  2354                     }
  2361                     }
  2355                 }
  2362                 }
  2400                         isDocument = eventReader.peek().isStartDocument();
  2407                         isDocument = eventReader.peek().isStartDocument();
  2401                     }
  2408                     }
  2402                 }
  2409                 }
  2403                 if (isDocument) {
  2410                 if (isDocument) {
  2404                     key = new XSDKey(schemaId, referType, schemaNamespace);
  2411                     key = new XSDKey(schemaId, referType, schemaNamespace);
  2405                     if ((schemaElement = (Element) fTraversed.get(key)) != null) {
  2412                     if ((schemaElement = fTraversed.get(key)) != null) {
  2406                         fLastSchemaWasDuplicate = true;
  2413                         fLastSchemaWasDuplicate = true;
  2407                         return schemaElement;
  2414                         return schemaElement;
  2408                     }
  2415                     }
  2409                 }
  2416                 }
  2410             }
  2417             }
  3500     public void reset(XMLComponentManager componentManager) {
  3507     public void reset(XMLComponentManager componentManager) {
  3501 
  3508 
  3502         // set symbol table
  3509         // set symbol table
  3503         fSymbolTable = (SymbolTable) componentManager.getProperty(SYMBOL_TABLE);
  3510         fSymbolTable = (SymbolTable) componentManager.getProperty(SYMBOL_TABLE);
  3504 
  3511 
  3505         fSecureProcessing = null;
  3512         // set security manager
  3506         if( componentManager!=null ) {
  3513         fSecurityManager = (XMLSecurityManager) componentManager.getProperty(SECURITY_MANAGER, null);
  3507             fSecureProcessing = (XMLSecurityManager) componentManager.getProperty(SECURE_PROCESSING, null);
  3514 
  3508         }
  3515         //set entity manager
       
  3516         fEntityManager = (XMLEntityResolver) componentManager.getProperty(ENTITY_MANAGER);
  3509 
  3517 
  3510         //set entity resolver
  3518         //set entity resolver
  3511         fEntityResolver = (XMLEntityResolver) componentManager.getProperty(ENTITY_MANAGER);
       
  3512         XMLEntityResolver er = (XMLEntityResolver)componentManager.getProperty(ENTITY_RESOLVER);
  3519         XMLEntityResolver er = (XMLEntityResolver)componentManager.getProperty(ENTITY_RESOLVER);
  3513         if (er != null)
  3520         if (er != null)
  3514             fSchemaParser.setEntityResolver(er);
  3521             fSchemaParser.setEntityResolver(er);
  3515 
  3522 
  3516         // set error reporter
  3523         // set error reporter
  3517         fErrorReporter =
  3524         fErrorReporter = (XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER);
  3518             (XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER);
  3525         fErrorHandler = fErrorReporter.getErrorHandler();
  3519         try {
  3526         fLocale = fErrorReporter.getLocale();
  3520             XMLErrorHandler currErrorHandler = fErrorReporter.getErrorHandler();
       
  3521             // Setting a parser property can be much more expensive
       
  3522             // than checking its value.  Don't set the ERROR_HANDLER
       
  3523             // or LOCALE properties unless they've actually changed.
       
  3524             if (currErrorHandler != fSchemaParser.getProperty(ERROR_HANDLER)) {
       
  3525                 fSchemaParser.setProperty(ERROR_HANDLER, (currErrorHandler != null) ? currErrorHandler : new DefaultErrorHandler());
       
  3526                 if (fAnnotationValidator != null) {
       
  3527                     fAnnotationValidator.setProperty(ERROR_HANDLER, (currErrorHandler != null) ? currErrorHandler : new DefaultErrorHandler());
       
  3528                 }
       
  3529             }
       
  3530             Locale currentLocale = fErrorReporter.getLocale();
       
  3531             if (currentLocale != fSchemaParser.getProperty(LOCALE)) {
       
  3532                 fSchemaParser.setProperty(LOCALE, currentLocale);
       
  3533                 if (fAnnotationValidator != null) {
       
  3534                     fAnnotationValidator.setProperty(LOCALE, currentLocale);
       
  3535                 }
       
  3536             }
       
  3537         }
       
  3538         catch (XMLConfigurationException e) {}
       
  3539 
  3527 
  3540         fValidateAnnotations = componentManager.getFeature(VALIDATE_ANNOTATIONS, false);
  3528         fValidateAnnotations = componentManager.getFeature(VALIDATE_ANNOTATIONS, false);
  3541         fHonourAllSchemaLocations = componentManager.getFeature(HONOUR_ALL_SCHEMALOCATIONS, false);
  3529         fHonourAllSchemaLocations = componentManager.getFeature(HONOUR_ALL_SCHEMALOCATIONS, false);
  3542         fNamespaceGrowth = componentManager.getFeature(NAMESPACE_GROWTH, false);
  3530         fNamespaceGrowth = componentManager.getFeature(NAMESPACE_GROWTH, false);
  3543         fTolerateDuplicates = componentManager.getFeature(TOLERATE_DUPLICATES, false);
  3531         fTolerateDuplicates = componentManager.getFeature(TOLERATE_DUPLICATES, false);
  3544 
  3532 
  3545         try {
  3533         try {
  3546             fSchemaParser.setFeature(
  3534             // Setting a parser property can be much more expensive
  3547                     CONTINUE_AFTER_FATAL_ERROR,
  3535             // than checking its value.  Don't set the ERROR_HANDLER
  3548                     fErrorReporter.getFeature(CONTINUE_AFTER_FATAL_ERROR));
  3536             // or LOCALE properties unless they've actually changed.
  3549         } catch (XMLConfigurationException e) {
  3537             if (fErrorHandler != fSchemaParser.getProperty(ERROR_HANDLER)) {
  3550         }
  3538                 fSchemaParser.setProperty(ERROR_HANDLER, (fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler());
       
  3539                 if (fAnnotationValidator != null) {
       
  3540                     fAnnotationValidator.setProperty(ERROR_HANDLER, (fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler());
       
  3541                 }
       
  3542             }
       
  3543             if (fLocale != fSchemaParser.getProperty(LOCALE)) {
       
  3544                 fSchemaParser.setProperty(LOCALE, fLocale);
       
  3545                 if (fAnnotationValidator != null) {
       
  3546                     fAnnotationValidator.setProperty(LOCALE, fLocale);
       
  3547                 }
       
  3548             }
       
  3549         }
       
  3550         catch (XMLConfigurationException e) {}
       
  3551 
       
  3552         try {
       
  3553             fSchemaParser.setFeature(CONTINUE_AFTER_FATAL_ERROR, fErrorReporter.getFeature(CONTINUE_AFTER_FATAL_ERROR));
       
  3554         } catch (XMLConfigurationException e) {}
  3551 
  3555 
  3552         try {
  3556         try {
  3553             if (componentManager.getFeature(ALLOW_JAVA_ENCODINGS, false)) {
  3557             if (componentManager.getFeature(ALLOW_JAVA_ENCODINGS, false)) {
  3554                 fSchemaParser.setFeature(ALLOW_JAVA_ENCODINGS, true);
  3558                 fSchemaParser.setFeature(ALLOW_JAVA_ENCODINGS, true);
  3555             }
  3559             }
  3556         } catch (XMLConfigurationException e) {
  3560         } catch (XMLConfigurationException e) {}
  3557         }
  3561 
  3558         try {
  3562         try {
  3559             if (componentManager.getFeature(STANDARD_URI_CONFORMANT_FEATURE, false)) {
  3563             if (componentManager.getFeature(STANDARD_URI_CONFORMANT_FEATURE, false)) {
  3560                 fSchemaParser.setFeature(STANDARD_URI_CONFORMANT_FEATURE, true);
  3564                 fSchemaParser.setFeature(STANDARD_URI_CONFORMANT_FEATURE, true);
  3561             }
  3565             }
  3562         } catch (XMLConfigurationException e) {
  3566         } catch (XMLConfigurationException e) {}
  3563         }
       
  3564 
  3567 
  3565         try {
  3568         try {
  3566             fGrammarPool =
  3569             fGrammarPool = (XMLGrammarPool) componentManager.getProperty(XMLGRAMMAR_POOL);
  3567                 (XMLGrammarPool) componentManager.getProperty(XMLGRAMMAR_POOL);
       
  3568         } catch (XMLConfigurationException e) {
  3570         } catch (XMLConfigurationException e) {
  3569             fGrammarPool = null;
  3571             fGrammarPool = null;
  3570         }
  3572         }
       
  3573 
  3571         // security features
  3574         // security features
  3572         try {
  3575         try {
  3573             if (componentManager.getFeature(DISALLOW_DOCTYPE, false)) {
  3576             if (componentManager.getFeature(DISALLOW_DOCTYPE, false)) {
  3574                 fSchemaParser.setFeature(DISALLOW_DOCTYPE, true);
  3577                 fSchemaParser.setFeature(DISALLOW_DOCTYPE, true);
  3575             }
  3578             }
  3576         } catch (XMLConfigurationException e) {
  3579         } catch (XMLConfigurationException e) {}
  3577         }
  3580 
  3578         try {
  3581         try {
  3579             Object security = componentManager.getProperty(SECURITY_MANAGER, null);
  3582             if (fSecurityManager != null) {
  3580             if (security != null){
  3583                 fSchemaParser.setProperty(SECURITY_MANAGER, fSecurityManager);
  3581                 fSchemaParser.setProperty(SECURITY_MANAGER, security);
  3584             }
  3582             }
  3585         } catch (XMLConfigurationException e) {}
  3583         } catch (XMLConfigurationException e) {
  3586 
  3584         }
  3587         fSecurityPropertyMgr = (XMLSecurityPropertyManager) componentManager.getProperty(XML_SECURITY_PROPERTY_MANAGER);
  3585 
  3588 
  3586         XMLSecurityPropertyManager securityPropertyMgr = (XMLSecurityPropertyManager)
       
  3587                 componentManager.getProperty(XML_SECURITY_PROPERTY_MANAGER);
       
  3588         //Passing on the setting to the parser
  3589         //Passing on the setting to the parser
  3589         fSchemaParser.setProperty(XML_SECURITY_PROPERTY_MANAGER, securityPropertyMgr);
  3590         fSchemaParser.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
  3590 
  3591 
  3591         fAccessExternalDTD = securityPropertyMgr.getValue(
  3592         fAccessExternalDTD = fSecurityPropertyMgr.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD);
  3592                 XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD);
  3593         fAccessExternalSchema = fSecurityPropertyMgr.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA);
  3593 
       
  3594         fAccessExternalSchema = securityPropertyMgr.getValue(
       
  3595                 XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA);
       
  3596 
  3594 
  3597     } // reset(XMLComponentManager)
  3595     } // reset(XMLComponentManager)
  3598 
  3596 
  3599 
  3597 
  3600     /**
  3598     /**
  4049          Logic here is unnecessary after schema WG's recent decision to allow
  4047          Logic here is unnecessary after schema WG's recent decision to allow
  4050          schema components from one document to refer to components of any other,
  4048          schema components from one document to refer to components of any other,
  4051          so long as there's some include/import/redefine path amongst them.
  4049          so long as there's some include/import/redefine path amongst them.
  4052          If they rver reverse this decision the code's right here though...  - neilg
  4050          If they rver reverse this decision the code's right here though...  - neilg
  4053          // now look in fDependencyMap to see if this is reachable
  4051          // now look in fDependencyMap to see if this is reachable
  4054           if(((Vector)fDependencyMap.get(currSchema)).contains(declDocInfo)) {
  4052           if((fDependencyMap.get(currSchema)).contains(declDocInfo)) {
  4055           return declDocInfo;
  4053           return declDocInfo;
  4056           }
  4054           }
  4057           // obviously the requesting doc didn't include, redefine or
  4055           // obviously the requesting doc didn't include, redefine or
  4058            // import the one containing decl...
  4056            // import the one containing decl...
  4059             return null;
  4057             return null;
  4070 
  4068 
  4071     private void setSchemasVisible(XSDocumentInfo startSchema) {
  4069     private void setSchemasVisible(XSDocumentInfo startSchema) {
  4072         if (DOMUtil.isHidden(startSchema.fSchemaElement, fHiddenNodes)) {
  4070         if (DOMUtil.isHidden(startSchema.fSchemaElement, fHiddenNodes)) {
  4073             // make it visible
  4071             // make it visible
  4074             DOMUtil.setVisible(startSchema.fSchemaElement, fHiddenNodes);
  4072             DOMUtil.setVisible(startSchema.fSchemaElement, fHiddenNodes);
  4075             Vector dependingSchemas = (Vector)fDependencyMap.get(startSchema);
  4073             Vector<XSDocumentInfo> dependingSchemas = fDependencyMap.get(startSchema);
  4076             for (int i = 0; i < dependingSchemas.size(); i++) {
  4074             for (int i = 0; i < dependingSchemas.size(); i++) {
  4077                 setSchemasVisible((XSDocumentInfo)dependingSchemas.elementAt(i));
  4075                 setSchemasVisible(dependingSchemas.elementAt(i));
  4078             }
  4076             }
  4079         }
  4077         }
  4080         // if it's visible already than so must be its children
  4078         // if it's visible already than so must be its children
  4081     } // setSchemasVisible(XSDocumentInfo): void
  4079     } // setSchemasVisible(XSDocumentInfo): void
  4082 
  4080 
  4105             return false;
  4103             return false;
  4106         if (e instanceof ElementImpl) {
  4104         if (e instanceof ElementImpl) {
  4107             ElementImpl ele = (ElementImpl)e;
  4105             ElementImpl ele = (ElementImpl)e;
  4108             // get system id from document object
  4106             // get system id from document object
  4109             Document doc = ele.getOwnerDocument();
  4107             Document doc = ele.getOwnerDocument();
  4110             String sid = (String)fDoc2SystemId.get(DOMUtil.getRoot(doc));
  4108             String sid = fDoc2SystemId.get(DOMUtil.getRoot(doc));
  4111             // line/column numbers are stored in the element node
  4109             // line/column numbers are stored in the element node
  4112             int line = ele.getLineNumber();
  4110             int line = ele.getLineNumber();
  4113             int column = ele.getColumnNumber();
  4111             int column = ele.getColumnNumber();
  4114             l.setValues(sid, sid, line, column, ele.getCharacterOffset());
  4112             l.setValues(sid, sid, line, column, ele.getCharacterOffset());
  4115             return true;
  4113             return true;