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 |
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); |
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)); |
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 } |
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 |
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; |
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 } |
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); |
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; |