src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSDHandler.java
changeset 47359 e1a6c0168741
parent 47312 d4f959806fe9
child 47477 115ed64c7822
equal deleted inserted replaced
47358:d07d5f7cab35 47359:e1a6c0168741
     1 /*
     1 /*
     2  * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * @LastModified: Sep 2017
     3  * @LastModified: Oct 2017
     4  */
     4  */
     5 /*
     5 /*
     6  * Licensed to the Apache Software Foundation (ASF) under one or more
     6  * Licensed to the Apache Software Foundation (ASF) under one or more
     7  * contributor license agreements.  See the NOTICE file distributed with
     7  * contributor license agreements.  See the NOTICE file distributed with
     8  * this work for additional information regarding copyright ownership.
     8  * this work for additional information regarding copyright ownership.
    95 import java.io.IOException;
    95 import java.io.IOException;
    96 import java.io.StringReader;
    96 import java.io.StringReader;
    97 import java.util.ArrayList;
    97 import java.util.ArrayList;
    98 import java.util.Collections;
    98 import java.util.Collections;
    99 import java.util.HashMap;
    99 import java.util.HashMap;
       
   100 import java.util.List;
   100 import java.util.Locale;
   101 import java.util.Locale;
   101 import java.util.Map;
   102 import java.util.Map;
   102 import java.util.Stack;
   103 import java.util.Stack;
   103 import java.util.Vector;
       
   104 import javax.xml.XMLConstants;
   104 import javax.xml.XMLConstants;
   105 import javax.xml.catalog.CatalogFeatures;
   105 import javax.xml.catalog.CatalogFeatures;
   106 import javax.xml.stream.XMLEventReader;
   106 import javax.xml.stream.XMLEventReader;
   107 import javax.xml.stream.XMLStreamException;
   107 import javax.xml.stream.XMLStreamException;
   108 import javax.xml.stream.XMLStreamReader;
   108 import javax.xml.stream.XMLStreamReader;
   281     private Map<String, XSDocumentInfo> fUnparsedNotationRegistrySub =  new HashMap<>();
   281     private Map<String, XSDocumentInfo> fUnparsedNotationRegistrySub =  new HashMap<>();
   282     private Map<String, XSDocumentInfo> fUnparsedTypeRegistrySub =  new HashMap<>();
   282     private Map<String, XSDocumentInfo> fUnparsedTypeRegistrySub =  new HashMap<>();
   283 
   283 
   284     // Stores XSDocumentInfo (keyed by component name), to check for duplicate
   284     // Stores XSDocumentInfo (keyed by component name), to check for duplicate
   285     // components declared within the same xsd document
   285     // components declared within the same xsd document
   286     @SuppressWarnings("unchecked")
   286     @SuppressWarnings({"rawtypes", "unchecked"})
   287     private Map<String, XSDocumentInfo> fUnparsedRegistriesExt[] = new HashMap[] {
   287     private Map<String, XSDocumentInfo> fUnparsedRegistriesExt[] = new HashMap[] {
   288         null,
   288         null,
   289         null, // ATTRIBUTE_TYPE
   289         null, // ATTRIBUTE_TYPE
   290         null, // ATTRIBUTEGROUP_TYPE
   290         null, // ATTRIBUTEGROUP_TYPE
   291         null, // ELEMENT_TYPE
   291         null, // ELEMENT_TYPE
   296     };
   296     };
   297 
   297 
   298     // this map is keyed on by XSDocumentInfo objects.  Its values
   298     // this map is keyed on by XSDocumentInfo objects.  Its values
   299     // are Vectors containing the XSDocumentInfo objects <include>d,
   299     // are Vectors containing the XSDocumentInfo objects <include>d,
   300     // <import>ed or <redefine>d by the key XSDocumentInfo.
   300     // <import>ed or <redefine>d by the key XSDocumentInfo.
   301     private Map<XSDocumentInfo, Vector<XSDocumentInfo>> fDependencyMap = new HashMap<>();
   301     private Map<XSDocumentInfo, List<XSDocumentInfo>> fDependencyMap = new HashMap<>();
   302 
   302 
   303     // this map is keyed on by a target namespace.  Its values
   303     // this map is keyed on by a target namespace.  Its values
   304     // are Vectors containing namespaces imported by schema documents
   304     // are Vectors containing namespaces imported by schema documents
   305     // with the key target namespace.
   305     // with the key target namespace.
   306     // if an imported schema has absent namespace, the value "null" is stored.
   306     // if an imported schema has absent namespace, the value "null" is stored.
   307     private Map<String, Vector> fImportMap = new HashMap<> ();
   307     private Map<String, List<String>> fImportMap = new HashMap<> ();
   308 
   308 
   309     // all namespaces that imports other namespaces
   309     // all namespaces that imports other namespaces
   310     // if the importing schema has absent namespace, empty string is stored.
   310     // if the importing schema has absent namespace, empty string is stored.
   311     // (because the key of a map can't be null.)
   311     // (because the key of a map can't be null.)
   312     private Vector<String> fAllTNSs = new Vector<>();
   312     private List<String> fAllTNSs = new ArrayList<>();
   313 
   313 
   314     // stores instance document mappings between namespaces and schema hints
   314     // stores instance document mappings between namespaces and schema hints
   315     private Map<String, XMLSchemaLoader.LocationArray> fLocationPairs = null;
   315     private Map<String, XMLSchemaLoader.LocationArray> fLocationPairs = null;
   316 
   316 
   317     // Records which nodes are hidden when the input is a DOMInputSource.
   317     // Records which nodes are hidden when the input is a DOMInputSource.
   354     // XSDocumentInfo object.
   354     // XSDocumentInfo object.
   355     private Map<Element, XSDocumentInfo> fDoc2XSDocumentMap = new HashMap<>();
   355     private Map<Element, XSDocumentInfo> fDoc2XSDocumentMap = new HashMap<>();
   356 
   356 
   357     // map between <redefine> elements and the XSDocumentInfo
   357     // map between <redefine> elements and the XSDocumentInfo
   358     // objects that correspond to the documents being redefined.
   358     // objects that correspond to the documents being redefined.
   359     private Map fRedefine2XSDMap = null;
   359     private Map<Element, XSDocumentInfo> fRedefine2XSDMap = null;
   360 
   360 
   361     // map between <redefine> elements and the namespace support
   361     // map between <redefine> elements and the namespace support
   362     private Map fRedefine2NSSupport = null;
   362     private Map<Element, SchemaNamespaceSupport> fRedefine2NSSupport = null;
   363 
   363 
   364     // these objects store a mapping between the names of redefining
   364     // these objects store a mapping between the names of redefining
   365     // groups/attributeGroups and the groups/AttributeGroups which
   365     // groups/attributeGroups and the groups/AttributeGroups which
   366     // they redefine by restriction (implicitly).  It is up to the
   366     // they redefine by restriction (implicitly).  It is up to the
   367     // Group and AttributeGroup traversers to check these restrictions for
   367     // Group and AttributeGroup traversers to check these restrictions for
   368     // validity.
   368     // validity.
   369     private Map fRedefinedRestrictedAttributeGroupRegistry = new HashMap();
   369     private final Map<String, String> fRedefinedRestrictedAttributeGroupRegistry = new HashMap<>();
   370     private Map fRedefinedRestrictedGroupRegistry = new HashMap();
   370     private final Map<String, String> fRedefinedRestrictedGroupRegistry = new HashMap<>();
   371 
   371 
   372     // a variable storing whether the last schema document
   372     // a variable storing whether the last schema document
   373     // processed (by getSchema) was a duplicate.
   373     // processed (by getSchema) was a duplicate.
   374     private boolean fLastSchemaWasDuplicate;
   374     private boolean fLastSchemaWasDuplicate;
   375 
   375 
   637 
   637 
   638         // second phase:  fill global registries.
   638         // second phase:  fill global registries.
   639         buildGlobalNameRegistries();
   639         buildGlobalNameRegistries();
   640 
   640 
   641         // third phase:  call traversers
   641         // third phase:  call traversers
   642         ArrayList annotationInfo = fValidateAnnotations ? new ArrayList() : null;
   642         List<Object> annotationInfo = fValidateAnnotations ? new ArrayList<>() : null;
   643         traverseSchemas(annotationInfo);
   643         traverseSchemas(annotationInfo);
   644 
   644 
   645         // fourth phase: handle local element decls
   645         // fourth phase: handle local element decls
   646         traverseLocalElements();
   646         traverseLocalElements();
   647 
   647 
   654 
   654 
   655         // seventh phase:  store imported grammars
   655         // seventh phase:  store imported grammars
   656         // for all grammars with <import>s
   656         // for all grammars with <import>s
   657         for (int i = fAllTNSs.size() - 1; i >= 0; i--) {
   657         for (int i = fAllTNSs.size() - 1; i >= 0; i--) {
   658             // get its target namespace
   658             // get its target namespace
   659             String tns = fAllTNSs.elementAt(i);
   659             String tns = fAllTNSs.get(i);
   660             // get all namespaces it imports
   660             // get all namespaces it imports
   661             Vector ins = (Vector)fImportMap.get(tns);
   661             List<String> ins = fImportMap.get(tns);
       
   662             List<SchemaGrammar> grammars = new ArrayList<>();
   662             // get the grammar
   663             // get the grammar
   663             SchemaGrammar sg = fGrammarBucket.getGrammar(emptyString2Null(tns));
   664             SchemaGrammar sg = fGrammarBucket.getGrammar(emptyString2Null(tns));
   664             if (sg == null)
   665             if (sg == null)
   665                 continue;
   666                 continue;
   666             SchemaGrammar isg;
   667             SchemaGrammar isg;
   667             // for imported namespace
   668             // for imported namespace
   668             int count = 0;
   669             int count = 0;
   669             for (int j = 0; j < ins.size(); j++) {
   670             for (int j = 0; j < ins.size(); j++) {
   670                 // get imported grammar
   671                 // get imported grammar
   671                 isg = fGrammarBucket.getGrammar((String)ins.elementAt(j));
   672                 isg = fGrammarBucket.getGrammar(ins.get(j));
   672                 // reuse the same vector
   673                 // reuse the same vector
   673                 if (isg != null)
   674                 if (isg != null) {
   674                     ins.setElementAt(isg, count++);
   675                     grammars.add(isg);
   675             }
   676                 }
   676             ins.setSize(count);
   677             }
   677             // set the imported grammars
   678             // set the imported grammars
   678             sg.setImportedGrammars(ins);
   679             sg.setImportedGrammars(grammars);
   679         }
   680         }
   680 
   681 
   681         /** validate annotations **/
   682         /** validate annotations **/
   682         if (fValidateAnnotations && annotationInfo.size() > 0) {
   683         if (fValidateAnnotations && annotationInfo.size() > 0) {
   683             validateAnnotations(annotationInfo);
   684             validateAnnotations(annotationInfo);
   685 
   686 
   686         // and return.
   687         // and return.
   687         return fGrammarBucket.getGrammar(fRoot.fTargetNamespace);
   688         return fGrammarBucket.getGrammar(fRoot.fTargetNamespace);
   688     } // end parseSchema
   689     } // end parseSchema
   689 
   690 
   690     private void validateAnnotations(ArrayList annotationInfo) {
   691     private void validateAnnotations(List<Object> annotationInfo) {
   691         if (fAnnotationValidator == null) {
   692         if (fAnnotationValidator == null) {
   692             createAnnotationValidator();
   693             createAnnotationValidator();
   693         }
   694         }
   694         final int size = annotationInfo.size();
   695         final int size = annotationInfo.size();
   695         final XMLInputSource src = new XMLInputSource(null, null, null, false);
   696         final XMLInputSource src = new XMLInputSource(null, null, null, false);
   907         // store the document and its location
   908         // store the document and its location
   908         // REVISIT: don't expose the DOM tree
   909         // REVISIT: don't expose the DOM tree
   909         sg.addDocument(null, fDoc2SystemId.get(currSchemaInfo.fSchemaElement));
   910         sg.addDocument(null, fDoc2SystemId.get(currSchemaInfo.fSchemaElement));
   910 
   911 
   911         fDoc2XSDocumentMap.put(schemaRoot, currSchemaInfo);
   912         fDoc2XSDocumentMap.put(schemaRoot, currSchemaInfo);
   912         Vector<XSDocumentInfo> dependencies = new Vector<>();
   913         List<XSDocumentInfo> dependencies = new ArrayList<>();
   913         Element rootNode = schemaRoot;
   914         Element rootNode = schemaRoot;
   914 
   915 
   915         Element newSchemaRoot = null;
   916         Element newSchemaRoot = null;
   916         for (Element child = DOMUtil.getFirstChildElement(rootNode);
   917         for (Element child = DOMUtil.getFirstChildElement(rootNode);
   917         child != null;
   918         child != null;
   976                 }
   977                 }
   977                 // also record the fact that one namespace imports another one
   978                 // also record the fact that one namespace imports another one
   978                 // convert null to ""
   979                 // convert null to ""
   979                 String tns = null2EmptyString(currSchemaInfo.fTargetNamespace);
   980                 String tns = null2EmptyString(currSchemaInfo.fTargetNamespace);
   980                 // get all namespaces imported by this one
   981                 // get all namespaces imported by this one
   981                 Vector ins = (Vector)fImportMap.get(tns);
   982                List<String> ins = fImportMap.get(tns);
   982                 // if no namespace was imported, create new Vector
   983                 // if no namespace was imported, create new ArrayList<>
   983                 if (ins == null) {
   984                 if (ins == null) {
   984                     // record that this one imports other(s)
   985                     // record that this one imports other(s)
   985                     fAllTNSs.addElement(tns);
   986                     fAllTNSs.add(tns);
   986                     ins = new Vector();
   987                     ins = new ArrayList<>();
   987                     fImportMap.put(tns, ins);
   988                     fImportMap.put(tns, ins);
   988                     ins.addElement(schemaNamespace);
   989                     ins.add(schemaNamespace);
   989                 }
   990                 }
   990                 else if (!ins.contains(schemaNamespace)){
   991                 else if (!ins.contains(schemaNamespace)){
   991                     ins.addElement(schemaNamespace);
   992                     ins.add(schemaNamespace);
   992                 }
   993                 }
   993 
   994 
   994                 fSchemaGrammarDescription.reset();
   995                 fSchemaGrammarDescription.reset();
   995                 fSchemaGrammarDescription.setContextType(XSDDescription.CONTEXT_IMPORT);
   996                 fSchemaGrammarDescription.setContextType(XSDDescription.CONTEXT_IMPORT);
   996                 fSchemaGrammarDescription.setBaseSystemId(doc2SystemId(schemaRoot));
   997                 fSchemaGrammarDescription.setBaseSystemId(doc2SystemId(schemaRoot));
  1035                 // yet).
  1036                 // yet).
  1036                 Object[] includeAttrs = fAttributeChecker.checkAttributes(child, true, currSchemaInfo);
  1037                 Object[] includeAttrs = fAttributeChecker.checkAttributes(child, true, currSchemaInfo);
  1037                 schemaHint = (String)includeAttrs[XSAttributeChecker.ATTIDX_SCHEMALOCATION];
  1038                 schemaHint = (String)includeAttrs[XSAttributeChecker.ATTIDX_SCHEMALOCATION];
  1038                 // store the namespace decls of the redefine element
  1039                 // store the namespace decls of the redefine element
  1039                 if (localName.equals(SchemaSymbols.ELT_REDEFINE)) {
  1040                 if (localName.equals(SchemaSymbols.ELT_REDEFINE)) {
  1040                     if (fRedefine2NSSupport == null) fRedefine2NSSupport = new HashMap();
  1041                     if (fRedefine2NSSupport == null) fRedefine2NSSupport = new HashMap<>();
  1041                     fRedefine2NSSupport.put(child, new SchemaNamespaceSupport(currSchemaInfo.fNamespaceSupport));
  1042                     fRedefine2NSSupport.put(child, new SchemaNamespaceSupport(currSchemaInfo.fNamespaceSupport));
  1042                 }
  1043                 }
  1043 
  1044 
  1044                 // check annotations.  Must do this here to avoid having to
  1045                 // check annotations.  Must do this here to avoid having to
  1045                 // re-parse attributes later
  1046                 // re-parse attributes later
  1050                         if (includeComponentType.equals(SchemaSymbols.ELT_ANNOTATION)) {
  1051                         if (includeComponentType.equals(SchemaSymbols.ELT_ANNOTATION)) {
  1051                             // promoting annotations to parent component
  1052                             // promoting annotations to parent component
  1052                             sg.addAnnotation(
  1053                             sg.addAnnotation(
  1053                                     fElementTraverser.traverseAnnotationDecl(includeChild, includeAttrs, true, currSchemaInfo));
  1054                                     fElementTraverser.traverseAnnotationDecl(includeChild, includeAttrs, true, currSchemaInfo));
  1054                         } else {
  1055                         } else {
  1055                             reportSchemaError("s4s-elt-must-match.1", new Object [] {localName, "annotation?", includeComponentType}, child);
  1056                             reportSchemaError("s4s-elt-must-match.1",
       
  1057                                     new Object [] {localName, "annotation?", includeComponentType}, child);
  1056                         }
  1058                         }
  1057                         if(DOMUtil.getNextSiblingElement(includeChild) != null) {
  1059                         if(DOMUtil.getNextSiblingElement(includeChild) != null) {
  1058                             reportSchemaError("s4s-elt-must-match.1", new Object [] {localName, "annotation?", DOMUtil.getLocalName(DOMUtil.getNextSiblingElement(includeChild))}, child);
  1060                             reportSchemaError("s4s-elt-must-match.1",
       
  1061                                     new Object [] {localName, "annotation?",
       
  1062                                         DOMUtil.getLocalName(DOMUtil.getNextSiblingElement(includeChild))}, child);
  1059                         }
  1063                         }
  1060                     }
  1064                     }
  1061                     else {
  1065                     else {
  1062                         String text = DOMUtil.getSyntheticAnnotation(child);
  1066                         String text = DOMUtil.getSyntheticAnnotation(child);
  1063                         if (text != null) {
  1067                         if (text != null) {
  1146 
  1150 
  1147             if (localName.equals(SchemaSymbols.ELT_REDEFINE) &&
  1151             if (localName.equals(SchemaSymbols.ELT_REDEFINE) &&
  1148                     newSchemaInfo != null) {
  1152                     newSchemaInfo != null) {
  1149                 // must record which schema we're redefining so that we can
  1153                 // must record which schema we're redefining so that we can
  1150                 // rename the right things later!
  1154                 // rename the right things later!
  1151                 if (fRedefine2XSDMap == null) fRedefine2XSDMap = new HashMap();
  1155                 if (fRedefine2XSDMap == null) fRedefine2XSDMap = new HashMap<>();
  1152                 fRedefine2XSDMap.put(child, newSchemaInfo);
  1156                 fRedefine2XSDMap.put(child, newSchemaInfo);
  1153             }
  1157             }
  1154             if (newSchemaRoot != null) {
  1158             if (newSchemaRoot != null) {
  1155                 if (newSchemaInfo != null)
  1159                 if (newSchemaInfo != null)
  1156                     dependencies.addElement(newSchemaInfo);
  1160                     dependencies.add(newSchemaInfo);
  1157                 newSchemaRoot = null;
  1161                 newSchemaRoot = null;
  1158             }
  1162             }
  1159         }
  1163         }
  1160 
  1164 
  1161         fDependencyMap.put(currSchemaInfo, dependencies);
  1165         fDependencyMap.put(currSchemaInfo, dependencies);
  1187      * grammar, check to see if the grammar bucket has a newer version.
  1191      * grammar, check to see if the grammar bucket has a newer version.
  1188      * If a new instance is found, we update the import list with the
  1192      * If a new instance is found, we update the import list with the
  1189      * newer version.
  1193      * newer version.
  1190      */
  1194      */
  1191     private void updateImportListFor(SchemaGrammar grammar) {
  1195     private void updateImportListFor(SchemaGrammar grammar) {
  1192         Vector importedGrammars = grammar.getImportedGrammars();
  1196        List<SchemaGrammar> importedGrammars = grammar.getImportedGrammars();
  1193         if (importedGrammars != null) {
  1197         if (importedGrammars != null) {
  1194             for (int i=0; i<importedGrammars.size(); i++) {
  1198             for (int i=0; i<importedGrammars.size(); i++) {
  1195                 SchemaGrammar isg1 = (SchemaGrammar) importedGrammars.elementAt(i);
  1199                 SchemaGrammar isg1 = importedGrammars.get(i);
  1196                 SchemaGrammar isg2 = fGrammarBucket.getGrammar(isg1.getTargetNamespace());
  1200                 SchemaGrammar isg2 = fGrammarBucket.getGrammar(isg1.getTargetNamespace());
  1197                 if (isg2 != null && isg1 != isg2) {
  1201                 if (isg2 != null && isg1 != isg2) {
  1198                     importedGrammars.set(i, isg2);
  1202                     importedGrammars.set(i, isg2);
  1199                 }
  1203                 }
  1200             }
  1204             }
  1213     private void updateImportListWith(SchemaGrammar newGrammar) {
  1217     private void updateImportListWith(SchemaGrammar newGrammar) {
  1214         SchemaGrammar[] schemaGrammars = fGrammarBucket.getGrammars();
  1218         SchemaGrammar[] schemaGrammars = fGrammarBucket.getGrammars();
  1215         for (int i = 0; i < schemaGrammars.length; ++i) {
  1219         for (int i = 0; i < schemaGrammars.length; ++i) {
  1216             SchemaGrammar sg = schemaGrammars[i];
  1220             SchemaGrammar sg = schemaGrammars[i];
  1217             if (sg != newGrammar) {
  1221             if (sg != newGrammar) {
  1218                 Vector importedGrammars = sg.getImportedGrammars();
  1222                 List<SchemaGrammar> importedGrammars = sg.getImportedGrammars();
  1219                 if (importedGrammars != null) {
  1223                 if (importedGrammars != null) {
  1220                     for (int j=0; j<importedGrammars.size(); j++) {
  1224                     for (int j=0; j<importedGrammars.size(); j++) {
  1221                         SchemaGrammar isg = (SchemaGrammar) importedGrammars.elementAt(j);
  1225                         SchemaGrammar isg = importedGrammars.get(j);
  1222                         if (null2EmptyString(isg.getTargetNamespace()).equals(null2EmptyString(newGrammar.getTargetNamespace()))) {
  1226                         if (null2EmptyString(isg.getTargetNamespace()).equals(
       
  1227                                 null2EmptyString(newGrammar.getTargetNamespace()))) {
  1223                             if (isg != newGrammar) {
  1228                             if (isg != newGrammar) {
  1224                                 importedGrammars.set(j, newGrammar);
  1229                                 importedGrammars.set(j, newGrammar);
  1225                             }
  1230                             }
  1226                             break;
  1231                             break;
  1227                         }
  1232                         }
  1247         // set its Document node to hidden so that we don't try to traverse
  1252         // set its Document node to hidden so that we don't try to traverse
  1248         // it again; then we look to its Dependency map entry.  We keep a
  1253         // it again; then we look to its Dependency map entry.  We keep a
  1249         // stack of schemas that we haven't yet finished processing; this
  1254         // stack of schemas that we haven't yet finished processing; this
  1250         // is a depth-first traversal.
  1255         // is a depth-first traversal.
  1251 
  1256 
  1252         Stack schemasToProcess = new Stack();
  1257         Stack<XSDocumentInfo> schemasToProcess = new Stack<>();
  1253         schemasToProcess.push(fRoot);
  1258         schemasToProcess.push(fRoot);
  1254 
  1259 
  1255         while (!schemasToProcess.empty()) {
  1260         while (!schemasToProcess.empty()) {
  1256             XSDocumentInfo currSchemaDoc =
  1261             XSDocumentInfo currSchemaDoc = schemasToProcess.pop();
  1257                 (XSDocumentInfo)schemasToProcess.pop();
       
  1258             Element currDoc = currSchemaDoc.fSchemaElement;
  1262             Element currDoc = currSchemaDoc.fSchemaElement;
  1259             if(DOMUtil.isHidden(currDoc, fHiddenNodes)){
  1263             if(DOMUtil.isHidden(currDoc, fHiddenNodes)){
  1260                 // must have processed this already!
  1264                 // must have processed this already!
  1261                 continue;
  1265                 continue;
  1262             }
  1266             }
  1363             } // end for
  1367             } // end for
  1364 
  1368 
  1365             // now we're done with this one!
  1369             // now we're done with this one!
  1366             DOMUtil.setHidden(currDoc, fHiddenNodes);
  1370             DOMUtil.setHidden(currDoc, fHiddenNodes);
  1367             // now add the schemas this guy depends on
  1371             // now add the schemas this guy depends on
  1368             Vector<XSDocumentInfo> currSchemaDepends = fDependencyMap.get(currSchemaDoc);
  1372             List<XSDocumentInfo> currSchemaDepends = fDependencyMap.get(currSchemaDoc);
  1369             for (int i = 0; i < currSchemaDepends.size(); i++) {
  1373             for (XSDocumentInfo currSchemaDepend : currSchemaDepends) {
  1370                 schemasToProcess.push(currSchemaDepends.elementAt(i));
  1374                 schemasToProcess.push(currSchemaDepend);
  1371             }
  1375             }
  1372         } // while
  1376         } // while
  1373 
  1377 
  1374     } // end buildGlobalNameRegistries
  1378     } // end buildGlobalNameRegistries
  1375 
  1379 
  1382     // appropriate traverser to traverse it.  Once all global decls in
  1386     // appropriate traverser to traverse it.  Once all global decls in
  1383     // an XSDocumentInfo object have been traversed, it marks that object
  1387     // an XSDocumentInfo object have been traversed, it marks that object
  1384     // as traversed (or hidden) in order to avoid infinite loops.  It completes
  1388     // as traversed (or hidden) in order to avoid infinite loops.  It completes
  1385     // when it has visited all XSDocumentInfo objects in the
  1389     // when it has visited all XSDocumentInfo objects in the
  1386     // DependencyMap and marked them as traversed.
  1390     // DependencyMap and marked them as traversed.
  1387     protected void traverseSchemas(ArrayList annotationInfo) {
  1391     protected void traverseSchemas(List<Object> annotationInfo) {
  1388         // the process here is very similar to that in
  1392         // the process here is very similar to that in
  1389         // buildGlobalRegistries, except we can't set our schemas as
  1393         // buildGlobalRegistries, except we can't set our schemas as
  1390         // hidden for a second time; so make them all visible again
  1394         // hidden for a second time; so make them all visible again
  1391         // first!
  1395         // first!
  1392         setSchemasVisible(fRoot);
  1396         setSchemasVisible(fRoot);
  1393         Stack schemasToProcess = new Stack();
  1397         Stack<XSDocumentInfo> schemasToProcess = new Stack<>();
  1394         schemasToProcess.push(fRoot);
  1398         schemasToProcess.push(fRoot);
  1395         while (!schemasToProcess.empty()) {
  1399         while (!schemasToProcess.empty()) {
  1396             XSDocumentInfo currSchemaDoc =
  1400             XSDocumentInfo currSchemaDoc = schemasToProcess.pop();
  1397                 (XSDocumentInfo)schemasToProcess.pop();
       
  1398             Element currDoc = currSchemaDoc.fSchemaElement;
  1401             Element currDoc = currSchemaDoc.fSchemaElement;
  1399 
  1402 
  1400             SchemaGrammar currSG = fGrammarBucket.getGrammar(currSchemaDoc.fTargetNamespace);
  1403             SchemaGrammar currSG = fGrammarBucket.getGrammar(currSchemaDoc.fTargetNamespace);
  1401 
  1404 
  1402             if(DOMUtil.isHidden(currDoc, fHiddenNodes)) {
  1405             if(DOMUtil.isHidden(currDoc, fHiddenNodes)) {
  1413                 DOMUtil.setHidden(globalComp, fHiddenNodes);
  1416                 DOMUtil.setHidden(globalComp, fHiddenNodes);
  1414                 String componentType = DOMUtil.getLocalName(globalComp);
  1417                 String componentType = DOMUtil.getLocalName(globalComp);
  1415                 // includes and imports will not show up here!
  1418                 // includes and imports will not show up here!
  1416                 if (DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_REDEFINE)) {
  1419                 if (DOMUtil.getLocalName(globalComp).equals(SchemaSymbols.ELT_REDEFINE)) {
  1417                     // use the namespace decls for the redefine, instead of for the parent <schema>
  1420                     // use the namespace decls for the redefine, instead of for the parent <schema>
  1418                     currSchemaDoc.backupNSSupport((fRedefine2NSSupport!=null)?(SchemaNamespaceSupport)fRedefine2NSSupport.get(globalComp):null);
  1421                     currSchemaDoc.backupNSSupport((fRedefine2NSSupport!=null) ?
       
  1422                             fRedefine2NSSupport.get(globalComp) : null);
  1419                     for (Element redefinedComp = DOMUtil.getFirstVisibleChildElement(globalComp, fHiddenNodes);
  1423                     for (Element redefinedComp = DOMUtil.getFirstVisibleChildElement(globalComp, fHiddenNodes);
  1420                     redefinedComp != null;
  1424                     redefinedComp != null;
  1421                     redefinedComp = DOMUtil.getNextVisibleSiblingElement(redefinedComp, fHiddenNodes)) {
  1425                     redefinedComp = DOMUtil.getNextVisibleSiblingElement(redefinedComp, fHiddenNodes)) {
  1422                         String redefinedComponentType = DOMUtil.getLocalName(redefinedComp);
  1426                         String redefinedComponentType = DOMUtil.getLocalName(redefinedComp);
  1423                         DOMUtil.setHidden(redefinedComp, fHiddenNodes);
  1427                         DOMUtil.setHidden(redefinedComp, fHiddenNodes);
  1493             // now we're done with this one!
  1497             // now we're done with this one!
  1494             currSchemaDoc.returnSchemaAttrs();
  1498             currSchemaDoc.returnSchemaAttrs();
  1495             DOMUtil.setHidden(currDoc, fHiddenNodes);
  1499             DOMUtil.setHidden(currDoc, fHiddenNodes);
  1496 
  1500 
  1497             // now add the schemas this guy depends on
  1501             // now add the schemas this guy depends on
  1498             Vector<XSDocumentInfo> currSchemaDepends = fDependencyMap.get(currSchemaDoc);
  1502             List<XSDocumentInfo> currSchemaDepends = fDependencyMap.get(currSchemaDoc);
  1499             for (int i = 0; i < currSchemaDepends.size(); i++) {
  1503             for (XSDocumentInfo currSchemaDepend : currSchemaDepends) {
  1500                 schemasToProcess.push(currSchemaDepends.elementAt(i));
  1504                 schemasToProcess.push(currSchemaDepend);
  1501             }
  1505             }
  1502         } // while
  1506         } // while
  1503     } // end traverseSchemas
  1507     } // end traverseSchemas
  1504 
  1508 
  1505     // store whether we have reported an error about that no grammar
  1509     // store whether we have reported an error about that no grammar
  1506     // is found for the given namespace uri
  1510     // is found for the given namespace uri
  1507     private Vector fReportedTNS = null;
  1511     private List<String> fReportedTNS = null;
  1508     // check whether we need to report an error against the given uri.
  1512     // check whether we need to report an error against the given uri.
  1509     // if we have reported an error, then we don't need to report again;
  1513     // if we have reported an error, then we don't need to report again;
  1510     // otherwise we reported the error, and remember this fact.
  1514     // otherwise we reported the error, and remember this fact.
  1511     private final boolean needReportTNSError(String uri) {
  1515     private final boolean needReportTNSError(String uri) {
  1512         if (fReportedTNS == null)
  1516         if (fReportedTNS == null)
  1513             fReportedTNS = new Vector();
  1517             fReportedTNS = new ArrayList<>();
  1514         else if (fReportedTNS.contains(uri))
  1518         else if (fReportedTNS.contains(uri))
  1515             return false;
  1519             return false;
  1516         fReportedTNS.addElement(uri);
  1520         fReportedTNS.add(uri);
  1517         return true;
  1521         return true;
  1518     }
  1522     }
  1519 
  1523 
  1520     private static final String[] COMP_TYPE = {
  1524     private static final String[] COMP_TYPE = {
  1521             null,               // index 0
  1525             null,               // index 0
  1890         }
  1894         }
  1891 
  1895 
  1892         return retObj;
  1896         return retObj;
  1893     }
  1897     }
  1894 
  1898 
  1895     protected Object traverseGlobalDecl(int declType, Element decl, XSDocumentInfo schemaDoc, SchemaGrammar grammar) {
  1899     protected Object traverseGlobalDecl(int declType, Element decl,
       
  1900             XSDocumentInfo schemaDoc, SchemaGrammar grammar) {
  1896         Object retObj = null;
  1901         Object retObj = null;
  1897 
  1902 
  1898         DOMUtil.setHidden(decl, fHiddenNodes);
  1903         DOMUtil.setHidden(decl, fHiddenNodes);
  1899         SchemaNamespaceSupport nsSupport = null;
  1904         SchemaNamespaceSupport nsSupport = null;
  1900         // if the parent is <redefine> use the namespace delcs for it.
  1905         // if the parent is <redefine> use the namespace delcs for it.
  1901         Element parent = DOMUtil.getParent(decl);
  1906         Element parent = DOMUtil.getParent(decl);
  1902         if (DOMUtil.getLocalName(parent).equals(SchemaSymbols.ELT_REDEFINE))
  1907         if (DOMUtil.getLocalName(parent).equals(SchemaSymbols.ELT_REDEFINE))
  1903             nsSupport = (fRedefine2NSSupport!=null)?(SchemaNamespaceSupport)fRedefine2NSSupport.get(parent):null;
  1908             nsSupport = (fRedefine2NSSupport!=null) ? fRedefine2NSSupport.get(parent) : null;
  1904         // back up the current SchemaNamespaceSupport, because we need to provide
  1909         // back up the current SchemaNamespaceSupport, because we need to provide
  1905         // a fresh one to the traverseGlobal methods.
  1910         // a fresh one to the traverseGlobal methods.
  1906         schemaDoc.backupNSSupport(nsSupport);
  1911         schemaDoc.backupNSSupport(nsSupport);
  1907 
  1912 
  1908         // traverse the referenced global component
  1913         // traverse the referenced global component
  1960         String realName = name.uri != null?name.uri+","+name.localpart:
  1965         String realName = name.uri != null?name.uri+","+name.localpart:
  1961             ","+name.localpart;
  1966             ","+name.localpart;
  1962         String nameToFind = null;
  1967         String nameToFind = null;
  1963         switch (type) {
  1968         switch (type) {
  1964         case ATTRIBUTEGROUP_TYPE:
  1969         case ATTRIBUTEGROUP_TYPE:
  1965             nameToFind = (String)fRedefinedRestrictedAttributeGroupRegistry.get(realName);
  1970             nameToFind = fRedefinedRestrictedAttributeGroupRegistry.get(realName);
  1966             break;
  1971             break;
  1967         case GROUP_TYPE:
  1972         case GROUP_TYPE:
  1968             nameToFind = (String)fRedefinedRestrictedGroupRegistry.get(realName);
  1973             nameToFind = fRedefinedRestrictedGroupRegistry.get(realName);
  1969             break;
  1974             break;
  1970         default:
  1975         default:
  1971             return null;
  1976             return null;
  1972         }
  1977         }
  1973         if (nameToFind == null) return null;
  1978         if (nameToFind == null) return null;
  2011         }
  2016         }
  2012     } // end resolveKeyRefs
  2017     } // end resolveKeyRefs
  2013 
  2018 
  2014     // an accessor method.  Just makes sure callers
  2019     // an accessor method.  Just makes sure callers
  2015     // who want the Identity constraint registry vaguely know what they're about.
  2020     // who want the Identity constraint registry vaguely know what they're about.
  2016     protected Map getIDRegistry() {
  2021     protected Map<String, Element> getIDRegistry() {
  2017         return fUnparsedIdentityConstraintRegistry;
  2022         return fUnparsedIdentityConstraintRegistry;
  2018     }
  2023     }
  2019     // an accessor method.
  2024     // an accessor method.
  2020     protected Map getIDRegistry_sub() {
  2025     protected Map<String, XSDocumentInfo> getIDRegistry_sub() {
  2021         return fUnparsedIdentityConstraintRegistrySub;
  2026         return fUnparsedIdentityConstraintRegistrySub;
  2022     }
  2027     }
  2023 
  2028 
  2024 
  2029 
  2025 
  2030 
  2533 
  2538 
  2534         SchemaGrammar[] grammars = schemaSource.getGrammars();
  2539         SchemaGrammar[] grammars = schemaSource.getGrammars();
  2535         short referType = desc.getContextType();
  2540         short referType = desc.getContextType();
  2536 
  2541 
  2537         if (grammars != null && grammars.length > 0) {
  2542         if (grammars != null && grammars.length > 0) {
  2538             Vector expandedGrammars = expandGrammars(grammars);
  2543            List<SchemaGrammar> expandedGrammars = expandGrammars(grammars);
  2539             // check for existing grammars in our bucket
  2544             // check for existing grammars in our bucket
  2540             // and if there exist any, and namespace growth is
  2545             // and if there exist any, and namespace growth is
  2541             // not enabled - we do nothing
  2546             // not enabled - we do nothing
  2542             if (fNamespaceGrowth || !existingGrammars(expandedGrammars)) {
  2547             if (fNamespaceGrowth || !existingGrammars(expandedGrammars)) {
  2543                 addGrammars(expandedGrammars);
  2548                 addGrammars(expandedGrammars);
  2547             }
  2552             }
  2548         }
  2553         }
  2549         else {
  2554         else {
  2550             XSObject[] components = schemaSource.getComponents();
  2555             XSObject[] components = schemaSource.getComponents();
  2551             if (components != null && components.length > 0) {
  2556             if (components != null && components.length > 0) {
  2552                 Map<String, Vector> importDependencies = new HashMap();
  2557                 Map<String, List<String>> importDependencies = new HashMap<>();
  2553                 Vector expandedComponents = expandComponents(components, importDependencies);
  2558                 List<XSObject> expandedComponents = expandComponents(components, importDependencies);
  2554                 if (fNamespaceGrowth || canAddComponents(expandedComponents)) {
  2559                 if (fNamespaceGrowth || canAddComponents(expandedComponents)) {
  2555                     addGlobalComponents(expandedComponents, importDependencies);
  2560                     addGlobalComponents(expandedComponents, importDependencies);
  2556                     if (referType == XSDDescription.CONTEXT_PREPARSE) {
  2561                     if (referType == XSDDescription.CONTEXT_PREPARSE) {
  2557                         desc.setTargetNamespace(components[0].getNamespace());
  2562                         desc.setTargetNamespace(components[0].getNamespace());
  2558                     }
  2563                     }
  2560             }
  2565             }
  2561         }
  2566         }
  2562         return null;
  2567         return null;
  2563     } // getSchemaDocument(String, XSInputSource, boolean, short, Element): Element
  2568     } // getSchemaDocument(String, XSInputSource, boolean, short, Element): Element
  2564 
  2569 
  2565     private Vector expandGrammars(SchemaGrammar[] grammars) {
  2570     private List<SchemaGrammar> expandGrammars(SchemaGrammar[] grammars) {
  2566         Vector currGrammars = new Vector();
  2571         List<SchemaGrammar> currGrammars = new ArrayList<>();
  2567 
  2572 
  2568         for (int i=0; i<grammars.length; i++) {
  2573         for (int i=0; i<grammars.length; i++) {
  2569             if (!currGrammars.contains(grammars[i])) {
  2574             if (!currGrammars.contains(grammars[i])) {
  2570                 currGrammars.add(grammars[i]);
  2575                 currGrammars.add(grammars[i]);
  2571             }
  2576             }
  2572         }
  2577         }
  2573 
  2578 
  2574         // for all (recursively) imported grammars
  2579         // for all (recursively) imported grammars
  2575         SchemaGrammar sg1, sg2;
  2580         SchemaGrammar sg1, sg2;
  2576         Vector gs;
  2581         List<SchemaGrammar> gs;
  2577         for (int i = 0; i < currGrammars.size(); i++) {
  2582         for (int i = 0; i < currGrammars.size(); i++) {
  2578             // get the grammar
  2583             // get the grammar
  2579             sg1 = (SchemaGrammar)currGrammars.elementAt(i);
  2584             sg1 = (SchemaGrammar)currGrammars.get(i);
  2580             // we need to add grammars imported by sg1 too
  2585             // we need to add grammars imported by sg1 too
  2581             gs = sg1.getImportedGrammars();
  2586             gs = sg1.getImportedGrammars();
  2582             // for all grammars imported by sg2, but not in the vector
  2587             // for all grammars imported by sg2, but not in the vector
  2583             // we add them to the vector
  2588             // we add them to the vector
  2584             if (gs == null) {
  2589             if (gs == null) {
  2585                 continue;
  2590                 continue;
  2586             }
  2591             }
  2587 
  2592 
  2588             for (int j = gs.size() - 1; j >= 0; j--) {
  2593             for (int j = gs.size() - 1; j >= 0; j--) {
  2589                 sg2 = (SchemaGrammar)gs.elementAt(j);
  2594                 sg2 = (SchemaGrammar)gs.get(j);
  2590                 if (!currGrammars.contains(sg2)) {
  2595                 if (!currGrammars.contains(sg2)) {
  2591                     currGrammars.addElement(sg2);
  2596                     currGrammars.add(sg2);
  2592                 }
  2597                 }
  2593             }
  2598             }
  2594         }
  2599         }
  2595 
  2600 
  2596         return currGrammars;
  2601         return currGrammars;
  2597     }
  2602     }
  2598 
  2603 
  2599     private boolean existingGrammars(Vector grammars) {
  2604     private boolean existingGrammars(List<SchemaGrammar> grammars) {
  2600         int length = grammars.size();
  2605         int length = grammars.size();
  2601         final XSDDescription desc = new XSDDescription();
  2606         final XSDDescription desc = new XSDDescription();
  2602 
  2607 
  2603         for (int i=0; i < length; i++) {
  2608         for (int i=0; i < length; i++) {
  2604             final SchemaGrammar sg1 = (SchemaGrammar)grammars.elementAt(i);
  2609             final SchemaGrammar sg1 = (SchemaGrammar)grammars.get(i);
  2605             desc.setNamespace(sg1.getTargetNamespace());
  2610             desc.setNamespace(sg1.getTargetNamespace());
  2606 
  2611 
  2607             final SchemaGrammar sg2 = findGrammar(desc, false);
  2612             final SchemaGrammar sg2 = findGrammar(desc, false);
  2608             if (sg2 != null) {
  2613             if (sg2 != null) {
  2609                 return true;
  2614                 return true;
  2611         }
  2616         }
  2612 
  2617 
  2613         return false;
  2618         return false;
  2614     }
  2619     }
  2615 
  2620 
  2616     private boolean canAddComponents(Vector components) {
  2621     private boolean canAddComponents(List<XSObject> components) {
  2617         final int size = components.size();
  2622         final int size = components.size();
  2618         final XSDDescription desc = new XSDDescription();
  2623         final XSDDescription desc = new XSDDescription();
  2619         for (int i=0; i<size; i++) {
  2624         for (int i=0; i<size; i++) {
  2620             XSObject component = (XSObject) components.elementAt(i);
  2625             XSObject component = (XSObject) components.get(i);
  2621             if (!canAddComponent(component, desc)) {
  2626             if (!canAddComponent(component, desc)) {
  2622                 return false;
  2627                 return false;
  2623             }
  2628             }
  2624         }
  2629         }
  2625         return true;
  2630         return true;
  2676             return true;
  2681             return true;
  2677         }
  2682         }
  2678         return false;
  2683         return false;
  2679     }
  2684     }
  2680 
  2685 
  2681     private void addGrammars(Vector grammars) {
  2686     private void addGrammars(List<SchemaGrammar> grammars) {
  2682         int length = grammars.size();
  2687         int length = grammars.size();
  2683         XSDDescription desc = new XSDDescription();
  2688         XSDDescription desc = new XSDDescription();
  2684 
  2689 
  2685         for (int i=0; i < length; i++) {
  2690         for (int i=0; i < length; i++) {
  2686             final SchemaGrammar sg1 = (SchemaGrammar)grammars.elementAt(i);
  2691             final SchemaGrammar sg1 = grammars.get(i);
  2687             desc.setNamespace(sg1.getTargetNamespace());
  2692             desc.setNamespace(sg1.getTargetNamespace());
  2688 
  2693 
  2689             final SchemaGrammar sg2 = findGrammar(desc, fNamespaceGrowth);
  2694             final SchemaGrammar sg2 = findGrammar(desc, fNamespaceGrowth);
  2690             if (sg1 != sg2) {
  2695             if (sg1 != sg2) {
  2691                 addGrammarComponents(sg1, sg2);
  2696                 addGrammarComponents(sg1, sg2);
  2735                 dstGrammar.addDocument(null, loc);
  2740                 dstGrammar.addDocument(null, loc);
  2736             }
  2741             }
  2737         }
  2742         }
  2738     }
  2743     }
  2739 
  2744 
       
  2745     @SuppressWarnings("unchecked")
  2740     private void addNewImportedGrammars(SchemaGrammar srcGrammar, SchemaGrammar dstGrammar) {
  2746     private void addNewImportedGrammars(SchemaGrammar srcGrammar, SchemaGrammar dstGrammar) {
  2741         final Vector igs1 = srcGrammar.getImportedGrammars();
  2747         final ArrayList<SchemaGrammar> igs1 = (ArrayList<SchemaGrammar>)srcGrammar.getImportedGrammars();
  2742         if (igs1 != null) {
  2748         if (igs1 != null) {
  2743             Vector igs2 = dstGrammar.getImportedGrammars();
  2749            ArrayList<SchemaGrammar> igs2 = (ArrayList<SchemaGrammar>)dstGrammar.getImportedGrammars();
  2744 
  2750 
  2745             if (igs2 == null) {
  2751             if (igs2 == null) {
  2746                 igs2 = ((Vector) igs1.clone());
  2752                 igs2 = (ArrayList<SchemaGrammar>)igs1.clone();
  2747                 dstGrammar.setImportedGrammars(igs2);
  2753                 dstGrammar.setImportedGrammars(igs2);
  2748             }
  2754             }
  2749             else {
  2755             else {
  2750                 updateImportList(igs1, igs2);
  2756                 updateImportList(igs1, igs2);
  2751             }
  2757             }
  2752         }
  2758         }
  2753     }
  2759     }
  2754 
  2760 
  2755     private void updateImportList(Vector importedSrc, Vector importedDst)
  2761     private void updateImportList(List<SchemaGrammar> importedSrc, List<SchemaGrammar> importedDst)
  2756     {
  2762     {
  2757         final int size = importedSrc.size();
  2763         final int size = importedSrc.size();
  2758 
  2764 
  2759         for (int i=0; i<size; i++) {
  2765         for (int i=0; i<size; i++) {
  2760             final SchemaGrammar sg = (SchemaGrammar) importedSrc.elementAt(i);
  2766             final SchemaGrammar sg = (SchemaGrammar) importedSrc.get(i);
  2761             if (!containedImportedGrammar(importedDst, sg)) {
  2767             if (!containedImportedGrammar(importedDst, sg)) {
  2762                 importedDst.add(sg);
  2768                 importedDst.add(sg);
  2763             }
  2769             }
  2764         }
  2770         }
  2765     }
  2771     }
  3000             else if (dstDecl != srcDecl) {
  3006             else if (dstDecl != srcDecl) {
  3001             }
  3007             }
  3002         }
  3008         }
  3003     }
  3009     }
  3004 
  3010 
  3005     private Vector expandComponents(XSObject[] components, Map<String, Vector> dependencies) {
  3011     private List<XSObject> expandComponents(XSObject[] components, Map<String, List<String>> dependencies) {
  3006         Vector newComponents = new Vector();
  3012         List<XSObject> newComponents = new ArrayList<>();
  3007 
  3013 
  3008         for (int i=0; i<components.length; i++) {
  3014         for (int i=0; i<components.length; i++) {
  3009             if (!newComponents.contains(components[i])) {
  3015             if (!newComponents.contains(components[i])) {
  3010                 newComponents.add(components[i]);
  3016                 newComponents.add(components[i]);
  3011             }
  3017             }
  3012         }
  3018         }
  3013 
  3019 
  3014         for (int i=0; i<newComponents.size(); i++) {
  3020         for (int i=0; i<newComponents.size(); i++) {
  3015             final XSObject component = (XSObject) newComponents.elementAt(i);
  3021             final XSObject component = newComponents.get(i);
  3016             expandRelatedComponents(component, newComponents, dependencies);
  3022             expandRelatedComponents(component, newComponents, dependencies);
  3017         }
  3023         }
  3018 
  3024 
  3019         return newComponents;
  3025         return newComponents;
  3020     }
  3026     }
  3021 
  3027 
  3022     private void expandRelatedComponents(XSObject component, Vector componentList, Map<String, Vector> dependencies) {
  3028     private void expandRelatedComponents(XSObject component,List<XSObject>componentList, Map<String, List<String>> dependencies) {
  3023         short componentType = component.getType();
  3029         short componentType = component.getType();
  3024         switch (componentType) {
  3030         switch (componentType) {
  3025         case XSConstants.TYPE_DEFINITION :
  3031         case XSConstants.TYPE_DEFINITION :
  3026             expandRelatedTypeComponents((XSTypeDefinition) component, componentList, component.getNamespace(), dependencies);
  3032             expandRelatedTypeComponents((XSTypeDefinition) component, componentList, component.getNamespace(), dependencies);
  3027             break;
  3033             break;
  3042         default :
  3048         default :
  3043             break;
  3049             break;
  3044         }
  3050         }
  3045     }
  3051     }
  3046 
  3052 
  3047     private void expandRelatedAttributeComponents(XSAttributeDeclaration decl, Vector componentList, String namespace, Map<String, Vector> dependencies) {
  3053     private void expandRelatedAttributeComponents(XSAttributeDeclaration decl, List<XSObject> componentList, String namespace, Map<String, List<String>> dependencies) {
  3048         addRelatedType(decl.getTypeDefinition(), componentList, namespace, dependencies);
  3054         addRelatedType(decl.getTypeDefinition(), componentList, namespace, dependencies);
  3049 
  3055 
  3050         /*final XSComplexTypeDefinition enclosingType = decl.getEnclosingCTDefinition();
  3056         /*final XSComplexTypeDefinition enclosingType = decl.getEnclosingCTDefinition();
  3051         if (enclosingType != null) {
  3057         if (enclosingType != null) {
  3052             addRelatedType(enclosingType, componentList, namespace, dependencies);
  3058             addRelatedType(enclosingType, componentList, namespace, dependencies);
  3053         }*/
  3059         }*/
  3054     }
  3060     }
  3055 
  3061 
  3056     private void expandRelatedElementComponents(XSElementDeclaration decl, Vector componentList, String namespace, Map<String, Vector> dependencies) {
  3062     private void expandRelatedElementComponents(XSElementDeclaration decl, List<XSObject> componentList, String namespace, Map<String, List<String>> dependencies) {
  3057         addRelatedType(decl.getTypeDefinition(), componentList, namespace, dependencies);
  3063         addRelatedType(decl.getTypeDefinition(), componentList, namespace, dependencies);
  3058 
  3064 
  3059         /*final XSTypeDefinition enclosingType = decl.getEnclosingCTDefinition();
  3065         /*final XSTypeDefinition enclosingType = decl.getEnclosingCTDefinition();
  3060         if (enclosingType != null) {
  3066         if (enclosingType != null) {
  3061             addRelatedType(enclosingType, componentList, namespace, dependencies);
  3067             addRelatedType(enclosingType, componentList, namespace, dependencies);
  3065         if (subElemDecl != null) {
  3071         if (subElemDecl != null) {
  3066             addRelatedElement(subElemDecl, componentList, namespace, dependencies);
  3072             addRelatedElement(subElemDecl, componentList, namespace, dependencies);
  3067         }
  3073         }
  3068     }
  3074     }
  3069 
  3075 
  3070     private void expandRelatedTypeComponents(XSTypeDefinition type, Vector componentList, String namespace, Map<String, Vector> dependencies) {
  3076     private void expandRelatedTypeComponents(XSTypeDefinition type, List<XSObject> componentList, String namespace, Map<String, List<String>> dependencies) {
  3071         if (type instanceof XSComplexTypeDecl) {
  3077         if (type instanceof XSComplexTypeDecl) {
  3072             expandRelatedComplexTypeComponents((XSComplexTypeDecl) type, componentList, namespace, dependencies);
  3078             expandRelatedComplexTypeComponents((XSComplexTypeDecl) type, componentList, namespace, dependencies);
  3073         }
  3079         }
  3074         else if (type instanceof XSSimpleTypeDecl) {
  3080         else if (type instanceof XSSimpleTypeDecl) {
  3075             expandRelatedSimpleTypeComponents((XSSimpleTypeDefinition) type, componentList, namespace, dependencies);
  3081             expandRelatedSimpleTypeComponents((XSSimpleTypeDefinition) type, componentList, namespace, dependencies);
  3076         }
  3082         }
  3077     }
  3083     }
  3078 
  3084 
  3079     private void expandRelatedModelGroupDefinitionComponents(XSModelGroupDefinition modelGroupDef, Vector componentList,
  3085     private void expandRelatedModelGroupDefinitionComponents(XSModelGroupDefinition modelGroupDef, List<XSObject>componentList,
  3080             String namespace, Map<String, Vector> dependencies) {
  3086             String namespace, Map<String, List<String>> dependencies) {
  3081         expandRelatedModelGroupComponents(modelGroupDef.getModelGroup(), componentList, namespace, dependencies);
  3087         expandRelatedModelGroupComponents(modelGroupDef.getModelGroup(), componentList, namespace, dependencies);
  3082     }
  3088     }
  3083 
  3089 
  3084     private void expandRelatedAttributeGroupComponents(XSAttributeGroupDefinition attrGroup, Vector componentList
  3090     private void expandRelatedAttributeGroupComponents(XSAttributeGroupDefinition attrGroup, List<XSObject> componentList
  3085             , String namespace, Map<String, Vector> dependencies) {
  3091             , String namespace, Map<String, List<String>> dependencies) {
  3086         expandRelatedAttributeUsesComponents(attrGroup.getAttributeUses(), componentList, namespace, dependencies);
  3092         expandRelatedAttributeUsesComponents(attrGroup.getAttributeUses(), componentList, namespace, dependencies);
  3087     }
  3093     }
  3088 
  3094 
  3089     private void expandRelatedComplexTypeComponents(XSComplexTypeDecl type, Vector componentList, String namespace, Map<String, Vector> dependencies) {
  3095     private void expandRelatedComplexTypeComponents(XSComplexTypeDecl type, List<XSObject> componentList, String namespace, Map<String, List<String>> dependencies) {
  3090         addRelatedType(type.getBaseType(), componentList, namespace, dependencies);
  3096         addRelatedType(type.getBaseType(), componentList, namespace, dependencies);
  3091         expandRelatedAttributeUsesComponents(type.getAttributeUses(), componentList, namespace, dependencies);
  3097         expandRelatedAttributeUsesComponents(type.getAttributeUses(), componentList, namespace, dependencies);
  3092         final XSParticle particle = type.getParticle();
  3098         final XSParticle particle = type.getParticle();
  3093         if (particle != null) {
  3099         if (particle != null) {
  3094             expandRelatedParticleComponents(particle, componentList, namespace, dependencies);
  3100             expandRelatedParticleComponents(particle, componentList, namespace, dependencies);
  3095         }
  3101         }
  3096     }
  3102     }
  3097 
  3103 
  3098     private void expandRelatedSimpleTypeComponents(XSSimpleTypeDefinition type, Vector componentList, String namespace, Map<String, Vector> dependencies) {
  3104     private void expandRelatedSimpleTypeComponents(XSSimpleTypeDefinition type, List<XSObject> componentList, String namespace, Map<String, List<String>> dependencies) {
  3099         final XSTypeDefinition baseType = type.getBaseType();
  3105         final XSTypeDefinition baseType = type.getBaseType();
  3100         if (baseType != null) {
  3106         if (baseType != null) {
  3101             addRelatedType(baseType, componentList, namespace, dependencies);
  3107             addRelatedType(baseType, componentList, namespace, dependencies);
  3102         }
  3108         }
  3103 
  3109 
  3117                 addRelatedType((XSTypeDefinition)memberTypes.item(i), componentList, namespace, dependencies);
  3123                 addRelatedType((XSTypeDefinition)memberTypes.item(i), componentList, namespace, dependencies);
  3118             }
  3124             }
  3119         }
  3125         }
  3120     }
  3126     }
  3121 
  3127 
  3122     private void expandRelatedAttributeUsesComponents(XSObjectList attrUses, Vector componentList,
  3128     private void expandRelatedAttributeUsesComponents(XSObjectList attrUses, List<XSObject> componentList,
  3123             String namespace, Map<String, Vector> dependencies) {
  3129             String namespace, Map<String, List<String>> dependencies) {
  3124         final int attrUseSize = (attrUses == null) ? 0 : attrUses.size();
  3130         final int attrUseSize = (attrUses == null) ? 0 : attrUses.size();
  3125         for (int i=0; i<attrUseSize; i++) {
  3131         for (int i=0; i<attrUseSize; i++) {
  3126             expandRelatedAttributeUseComponents((XSAttributeUse)attrUses.item(i), componentList, namespace, dependencies);
  3132             expandRelatedAttributeUseComponents((XSAttributeUse)attrUses.item(i), componentList, namespace, dependencies);
  3127         }
  3133         }
  3128     }
  3134     }
  3129 
  3135 
  3130     private void expandRelatedAttributeUseComponents(XSAttributeUse component, Vector componentList,
  3136     private void expandRelatedAttributeUseComponents(XSAttributeUse component, List<XSObject> componentList,
  3131             String namespace, Map<String, Vector> dependencies) {
  3137             String namespace, Map<String, List<String>> dependencies) {
  3132         addRelatedAttribute(component.getAttrDeclaration(), componentList, namespace, dependencies);
  3138         addRelatedAttribute(component.getAttrDeclaration(), componentList, namespace, dependencies);
  3133     }
  3139     }
  3134 
  3140 
  3135     private void expandRelatedParticleComponents(XSParticle component, Vector componentList,
  3141     private void expandRelatedParticleComponents(XSParticle component, List<XSObject> componentList,
  3136             String namespace, Map<String, Vector> dependencies) {
  3142             String namespace, Map<String, List<String>> dependencies) {
  3137         XSTerm term = component.getTerm();
  3143         XSTerm term = component.getTerm();
  3138         switch (term.getType()) {
  3144         switch (term.getType()) {
  3139         case XSConstants.ELEMENT_DECLARATION :
  3145         case XSConstants.ELEMENT_DECLARATION :
  3140             addRelatedElement((XSElementDeclaration) term, componentList, namespace, dependencies);
  3146             addRelatedElement((XSElementDeclaration) term, componentList, namespace, dependencies);
  3141             break;
  3147             break;
  3145         default:
  3151         default:
  3146             break;
  3152             break;
  3147         }
  3153         }
  3148     }
  3154     }
  3149 
  3155 
  3150     private void expandRelatedModelGroupComponents(XSModelGroup modelGroup, Vector componentList,
  3156     private void expandRelatedModelGroupComponents(XSModelGroup modelGroup, List<XSObject> componentList,
  3151             String namespace, Map<String, Vector> dependencies) {
  3157             String namespace, Map<String, List<String>> dependencies) {
  3152         XSObjectList particles = modelGroup.getParticles();
  3158         XSObjectList particles = modelGroup.getParticles();
  3153         final int length = (particles == null) ? 0 : particles.getLength();
  3159         final int length = (particles == null) ? 0 : particles.getLength();
  3154         for (int i=0; i<length; i++) {
  3160         for (int i=0; i<length; i++) {
  3155             expandRelatedParticleComponents((XSParticle)particles.item(i), componentList, namespace, dependencies);
  3161             expandRelatedParticleComponents((XSParticle)particles.item(i), componentList, namespace, dependencies);
  3156         }
  3162         }
  3157     }
  3163     }
  3158 
  3164 
  3159     private void addRelatedType(XSTypeDefinition type, Vector componentList, String namespace, Map<String, Vector> dependencies) {
  3165     private void addRelatedType(XSTypeDefinition type, List<XSObject> componentList, String namespace, Map<String, List<String>> dependencies) {
  3160         if (!type.getAnonymous()) {
  3166         if (!type.getAnonymous()) {
  3161             if (!type.getNamespace().equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)) { //REVISIT - do we use == instead
  3167             if (!type.getNamespace().equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)) { //REVISIT - do we use == instead
  3162                 if (!componentList.contains(type)) {
  3168                 if (!componentList.contains(type)) {
  3163                     final Vector importedNamespaces = findDependentNamespaces(namespace, dependencies);
  3169                     final List<String> importedNamespaces = findDependentNamespaces(namespace, dependencies);
  3164                     addNamespaceDependency(namespace, type.getNamespace(), importedNamespaces);
  3170                     addNamespaceDependency(namespace, type.getNamespace(), importedNamespaces);
  3165                     componentList.add(type);
  3171                     componentList.add(type);
  3166                 }
  3172                 }
  3167             }
  3173             }
  3168         }
  3174         }
  3169         else {
  3175         else {
  3170             expandRelatedTypeComponents(type, componentList, namespace, dependencies);
  3176             expandRelatedTypeComponents(type, componentList, namespace, dependencies);
  3171         }
  3177         }
  3172     }
  3178     }
  3173 
  3179 
  3174     private void addRelatedElement(XSElementDeclaration decl, Vector componentList, String namespace, Map<String, Vector> dependencies) {
  3180     private void addRelatedElement(XSElementDeclaration decl, List<XSObject> componentList, String namespace, Map<String, List<String>> dependencies) {
  3175         if (decl.getScope() == XSConstants.SCOPE_GLOBAL) {
  3181         if (decl.getScope() == XSConstants.SCOPE_GLOBAL) {
  3176             if (!componentList.contains(decl)) {
  3182             if (!componentList.contains(decl)) {
  3177                 Vector importedNamespaces = findDependentNamespaces(namespace, dependencies);
  3183                List<String> importedNamespaces = findDependentNamespaces(namespace, dependencies);
  3178                 addNamespaceDependency(namespace, decl.getNamespace(), importedNamespaces);
  3184                 addNamespaceDependency(namespace, decl.getNamespace(), importedNamespaces);
  3179                 componentList.add(decl);
  3185                 componentList.add(decl);
  3180             }
  3186             }
  3181         }
  3187         }
  3182         else {
  3188         else {
  3183             expandRelatedElementComponents(decl, componentList, namespace, dependencies);
  3189             expandRelatedElementComponents(decl, componentList, namespace, dependencies);
  3184         }
  3190         }
  3185     }
  3191     }
  3186 
  3192 
  3187     private void addRelatedAttribute(XSAttributeDeclaration decl, Vector componentList, String namespace, Map<String, Vector> dependencies) {
  3193     private void addRelatedAttribute(XSAttributeDeclaration decl, List<XSObject> componentList, String namespace, Map<String, List<String>> dependencies) {
  3188         if (decl.getScope() == XSConstants.SCOPE_GLOBAL) {
  3194         if (decl.getScope() == XSConstants.SCOPE_GLOBAL) {
  3189             if (!componentList.contains(decl)) {
  3195             if (!componentList.contains(decl)) {
  3190                 Vector importedNamespaces = findDependentNamespaces(namespace, dependencies);
  3196                 List<String> importedNamespaces = findDependentNamespaces(namespace, dependencies);
  3191                 addNamespaceDependency(namespace, decl.getNamespace(), importedNamespaces);
  3197                 addNamespaceDependency(namespace, decl.getNamespace(), importedNamespaces);
  3192                 componentList.add(decl);
  3198                 componentList.add(decl);
  3193             }
  3199             }
  3194         }
  3200         }
  3195         else {
  3201         else {
  3196             expandRelatedAttributeComponents(decl, componentList, namespace, dependencies);
  3202             expandRelatedAttributeComponents(decl, componentList, namespace, dependencies);
  3197         }
  3203         }
  3198     }
  3204     }
  3199 
  3205 
  3200     private void addGlobalComponents(Vector components, Map<String, Vector> importDependencies) {
  3206     private void addGlobalComponents(List<XSObject> components, Map<String, List<String>> importDependencies) {
  3201         final XSDDescription desc = new XSDDescription();
  3207         final XSDDescription desc = new XSDDescription();
  3202         final int size = components.size();
  3208         final int size = components.size();
  3203 
  3209 
  3204         for (int i=0; i<size; i++) {
  3210         for (int i=0; i<size; i++) {
  3205             addGlobalComponent((XSObject) components.elementAt(i), desc);
  3211             addGlobalComponent(components.get(i), desc);
  3206         }
  3212         }
  3207         updateImportDependencies(importDependencies);
  3213         updateImportDependencies(importDependencies);
  3208     }
  3214     }
  3209 
  3215 
  3210     private void addGlobalComponent(XSObject component, XSDDescription desc) {
  3216     private void addGlobalComponent(XSObject component, XSDDescription desc) {
  3284         default :
  3290         default :
  3285             break;
  3291             break;
  3286         }
  3292         }
  3287     }
  3293     }
  3288 
  3294 
  3289     private void updateImportDependencies(Map<String, Vector> table) {
  3295     private void updateImportDependencies(Map<String, List<String>> table) {
  3290         if (table == null) return;
  3296         if (table == null) return;
  3291         String namespace;
  3297         String namespace;
  3292         Vector importList;
  3298         List<String> importList;
  3293 
  3299 
  3294         for(Map.Entry<String, Vector> entry : table.entrySet()){
  3300         for(Map.Entry<String, List<String>> entry : table.entrySet()){
  3295             namespace = entry.getKey();
  3301             namespace = entry.getKey();
  3296             importList = entry.getValue();
  3302             importList = entry.getValue();
  3297             if (importList.size() > 0) {
  3303             if (importList.size() > 0) {
  3298                 expandImportList(namespace, importList);
  3304                 expandImportList(namespace, importList);
  3299             }
  3305             }
  3300         }
  3306         }
  3301     }
  3307     }
  3302 
  3308 
  3303     private void expandImportList(String namespace, Vector namespaceList) {
  3309     private void expandImportList(String namespace, List<String> namespaceList) {
  3304         SchemaGrammar sg = fGrammarBucket.getGrammar(namespace);
  3310         SchemaGrammar sg = fGrammarBucket.getGrammar(namespace);
  3305         // shouldn't be null
  3311         // shouldn't be null
  3306         if (sg != null) {
  3312         if (sg != null) {
  3307             Vector isgs = sg.getImportedGrammars();
  3313             List<SchemaGrammar> isgs = sg.getImportedGrammars();
  3308             if (isgs == null) {
  3314             if (isgs == null) {
  3309                 isgs = new Vector();
  3315                 isgs = new ArrayList<>();
  3310                 addImportList(sg, isgs, namespaceList);
  3316                 addImportList(sg, isgs, namespaceList);
  3311                 sg.setImportedGrammars(isgs);
  3317                 sg.setImportedGrammars(isgs);
  3312             }
  3318             }
  3313             else {
  3319             else {
  3314                 updateImportList(sg, isgs, namespaceList);
  3320                 updateImportList(sg, isgs, namespaceList);
  3315             }
  3321             }
  3316         }
  3322         }
  3317     }
  3323     }
  3318 
  3324 
  3319     private void addImportList(SchemaGrammar sg, Vector importedGrammars, Vector namespaceList) {
  3325     private void addImportList(SchemaGrammar sg, List<SchemaGrammar> importedGrammars, List<String> namespaceList) {
  3320         final int size = namespaceList.size();
  3326         final int size = namespaceList.size();
  3321         SchemaGrammar isg;
  3327         SchemaGrammar isg;
  3322 
  3328 
  3323         for (int i=0; i<size; i++) {
  3329         for (int i=0; i<size; i++) {
  3324             isg = fGrammarBucket.getGrammar((String)namespaceList.elementAt(i));
  3330             isg = fGrammarBucket.getGrammar(namespaceList.get(i));
  3325             if (isg != null) {
  3331             if (isg != null) {
  3326                 importedGrammars.add(isg);
  3332                 importedGrammars.add(isg);
  3327             }
  3333             }
  3328             else {
  3334             else {
  3329                 //REVIST: report an error message
  3335                 //REVIST: report an error message
  3330             }
  3336             }
  3331         }
  3337         }
  3332     }
  3338     }
  3333 
  3339 
  3334     private void updateImportList(SchemaGrammar sg, Vector importedGrammars, Vector namespaceList) {
  3340     private void updateImportList(SchemaGrammar sg, List<SchemaGrammar> importedGrammars,
       
  3341             List<String> namespaceList) {
  3335         final int size = namespaceList.size();
  3342         final int size = namespaceList.size();
  3336         SchemaGrammar isg;
  3343         SchemaGrammar isg;
  3337 
  3344 
  3338         for (int i=0; i<size; i++) {
  3345         for (int i=0; i<size; i++) {
  3339             isg = fGrammarBucket.getGrammar((String)namespaceList.elementAt(i));
  3346             isg = fGrammarBucket.getGrammar(namespaceList.get(i));
  3340             if (isg != null) {
  3347             if (isg != null) {
  3341                 if (!containedImportedGrammar(importedGrammars, isg)) {
  3348                 if (!containedImportedGrammar(importedGrammars, isg)) {
  3342                     importedGrammars.add(isg);
  3349                     importedGrammars.add(isg);
  3343                 }
  3350                 }
  3344             }
  3351             }
  3346                 //REVIST: report an error message
  3353                 //REVIST: report an error message
  3347             }
  3354             }
  3348         }
  3355         }
  3349     }
  3356     }
  3350 
  3357 
  3351     private boolean containedImportedGrammar(Vector importedGrammar, SchemaGrammar grammar) {
  3358     private boolean containedImportedGrammar(List<SchemaGrammar> importedGrammar, SchemaGrammar grammar) {
  3352         final int size = importedGrammar.size();
  3359         final int size = importedGrammar.size();
  3353         SchemaGrammar sg;
  3360         SchemaGrammar sg;
  3354 
  3361 
  3355         for (int i=0; i<size; i++) {
  3362         for (int i=0; i<size; i++) {
  3356             sg = (SchemaGrammar) importedGrammar.elementAt(i);
  3363             sg = (SchemaGrammar) importedGrammar.get(i);
  3357             if (null2EmptyString(sg.getTargetNamespace()).equals(null2EmptyString(grammar.getTargetNamespace()))) {
  3364             if (null2EmptyString(sg.getTargetNamespace()).equals(null2EmptyString(grammar.getTargetNamespace()))) {
  3358                 return true;
  3365                 return true;
  3359             }
  3366             }
  3360         }
  3367         }
  3361         return false;
  3368         return false;
  3375         }
  3382         }
  3376 
  3383 
  3377         return sg;
  3384         return sg;
  3378     }
  3385     }
  3379 
  3386 
  3380     private Vector findDependentNamespaces(String namespace, Map table) {
  3387     private List<String> findDependentNamespaces(String namespace,
       
  3388             Map<String, List<String>> table) {
  3381         final String ns = null2EmptyString(namespace);
  3389         final String ns = null2EmptyString(namespace);
  3382         Vector namespaceList = (Vector) getFromMap(table, ns);
  3390         List<String> namespaceList = getFromMap(table, ns);
  3383 
  3391 
  3384         if (namespaceList == null) {
  3392         if (namespaceList == null) {
  3385             namespaceList = new Vector();
  3393             namespaceList = new ArrayList<>();
  3386             table.put(ns, namespaceList);
  3394             table.put(ns, namespaceList);
  3387         }
  3395         }
  3388 
  3396 
  3389         return namespaceList;
  3397         return namespaceList;
  3390     }
  3398     }
  3391 
  3399 
  3392     private void addNamespaceDependency(String namespace1, String namespace2, Vector list) {
  3400     private void addNamespaceDependency(String namespace1, String namespace2, List<String> list) {
  3393         final String ns1 = null2EmptyString(namespace1);
  3401         final String ns1 = null2EmptyString(namespace1);
  3394         final String ns2 = null2EmptyString(namespace2);
  3402         final String ns2 = null2EmptyString(namespace2);
  3395         if (!ns1.equals(ns2)) {
  3403         if (!ns1.equals(ns2)) {
  3396             if (!list.contains(ns2)) {
  3404             if (!list.contains(ns2)) {
  3397                 list.add(ns2);
  3405                 list.add(ns2);
  3462 
  3470 
  3463         fDependencyMap.clear();
  3471         fDependencyMap.clear();
  3464         fDoc2XSDocumentMap.clear();
  3472         fDoc2XSDocumentMap.clear();
  3465         if (fRedefine2XSDMap != null) fRedefine2XSDMap.clear();
  3473         if (fRedefine2XSDMap != null) fRedefine2XSDMap.clear();
  3466         if (fRedefine2NSSupport != null) fRedefine2NSSupport.clear();
  3474         if (fRedefine2NSSupport != null) fRedefine2NSSupport.clear();
  3467         fAllTNSs.removeAllElements();
  3475         fAllTNSs.clear();
  3468         fImportMap.clear();
  3476         fImportMap.clear();
  3469         fRoot = null;
  3477         fRoot = null;
  3470 
  3478 
  3471         // clear local element stack
  3479         // clear local element stack
  3472         for (int i = 0; i < fLocalElemStackPos; i++) {
  3480         for (int i = 0; i < fLocalElemStackPos; i++) {
  3763             XSDocumentInfo redefinedSchema = null;
  3771             XSDocumentInfo redefinedSchema = null;
  3764             // case where we've collided with a redefining element
  3772             // case where we've collided with a redefining element
  3765             // (the parent of the colliding element is a redefine)
  3773             // (the parent of the colliding element is a redefine)
  3766             boolean collidedWithRedefine = true;
  3774             boolean collidedWithRedefine = true;
  3767             if ((DOMUtil.getLocalName((elemParent = DOMUtil.getParent(collidingElem))).equals(SchemaSymbols.ELT_REDEFINE))) {
  3775             if ((DOMUtil.getLocalName((elemParent = DOMUtil.getParent(collidingElem))).equals(SchemaSymbols.ELT_REDEFINE))) {
  3768                 redefinedSchema = (fRedefine2XSDMap != null)?(XSDocumentInfo) (fRedefine2XSDMap.get(elemParent)): null;
  3776                 redefinedSchema = (fRedefine2XSDMap != null)? fRedefine2XSDMap.get(elemParent) : null;
  3769                 // case where we're a redefining element.
  3777                 // case where we're a redefining element.
  3770             }
  3778             }
  3771             else if ((DOMUtil.getLocalName(DOMUtil.getParent(currComp)).equals(SchemaSymbols.ELT_REDEFINE))) {
  3779             else if ((DOMUtil.getLocalName(DOMUtil.getParent(currComp)).equals(SchemaSymbols.ELT_REDEFINE))) {
  3772                 redefinedSchema = collidingElemSchema;
  3780                 redefinedSchema = collidingElemSchema;
  3773                 collidedWithRedefine = false;
  3781                 collidedWithRedefine = false;
  3826         }
  3834         }
  3827 
  3835 
  3828         // store the lastest current document info
  3836         // store the lastest current document info
  3829         if (fTolerateDuplicates) {
  3837         if (fTolerateDuplicates) {
  3830             if (fUnparsedRegistriesExt[declType] == null)
  3838             if (fUnparsedRegistriesExt[declType] == null)
  3831                 fUnparsedRegistriesExt[declType] = new HashMap();
  3839                 fUnparsedRegistriesExt[declType] = new HashMap<>();
  3832             fUnparsedRegistriesExt[declType].put(qName, currSchema);
  3840             fUnparsedRegistriesExt[declType].put(qName, currSchema);
  3833         }
  3841         }
  3834 
  3842 
  3835     } // checkForDuplicateNames(String, Map, Element, XSDocumentInfo):void
  3843     } // checkForDuplicateNames(String, Map, Element, XSDocumentInfo):void
  3836 
  3844 
  4118 
  4126 
  4119     private void setSchemasVisible(XSDocumentInfo startSchema) {
  4127     private void setSchemasVisible(XSDocumentInfo startSchema) {
  4120         if (DOMUtil.isHidden(startSchema.fSchemaElement, fHiddenNodes)) {
  4128         if (DOMUtil.isHidden(startSchema.fSchemaElement, fHiddenNodes)) {
  4121             // make it visible
  4129             // make it visible
  4122             DOMUtil.setVisible(startSchema.fSchemaElement, fHiddenNodes);
  4130             DOMUtil.setVisible(startSchema.fSchemaElement, fHiddenNodes);
  4123             Vector<XSDocumentInfo> dependingSchemas = fDependencyMap.get(startSchema);
  4131             List<XSDocumentInfo> dependingSchemas = fDependencyMap.get(startSchema);
  4124             for (int i = 0; i < dependingSchemas.size(); i++) {
  4132             for (int i = 0; i < dependingSchemas.size(); i++) {
  4125                 setSchemasVisible(dependingSchemas.elementAt(i));
  4133                 setSchemasVisible(dependingSchemas.get(i));
  4126             }
  4134             }
  4127         }
  4135         }
  4128         // if it's visible already than so must be its children
  4136         // if it's visible already than so must be its children
  4129     } // setSchemasVisible(XSDocumentInfo): void
  4137     } // setSchemasVisible(XSDocumentInfo): void
  4130 
  4138 
  4173     private XSDocumentInfo getDocInfoFromMap(Map<String, XSDocumentInfo> registry, String declKey) {
  4181     private XSDocumentInfo getDocInfoFromMap(Map<String, XSDocumentInfo> registry, String declKey) {
  4174         if (registry == null) return null;
  4182         if (registry == null) return null;
  4175         return registry.get(declKey);
  4183         return registry.get(declKey);
  4176     }
  4184     }
  4177 
  4185 
  4178     private Object getFromMap(Map registry, String key) {
  4186     private List<String> getFromMap(Map<String, List<String>> registry, String key) {
  4179         if (registry == null) return null;
  4187         if (registry == null) return null;
  4180         return registry.get(key);
  4188         return registry.get(key);
  4181     }
  4189     }
  4182 
  4190 
  4183     void reportSchemaFatalError(String key, Object[] args, Element ele) {
  4191     void reportSchemaFatalError(String key, Object[] args, Element ele) {