diff options
Diffstat (limited to 'bundles')
10 files changed, 329 insertions, 269 deletions
diff --git a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/analyzer/CandidateInfo.java b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/analyzer/CandidateInfo.java index 553cbee39..6fe828d9c 100644 --- a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/analyzer/CandidateInfo.java +++ b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/analyzer/CandidateInfo.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.wst.wsi.internal.core.analyzer; +import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -575,35 +576,38 @@ public class CandidateInfo { HashSet importSet = new HashSet(); - - Map importMap = rootDef.getImports(); - Iterator i = importMap.values().iterator(); - - while (i.hasNext()) - { - List nextImportList = (List) (i.next()); - Iterator listIt = nextImportList.iterator(); - while (listIt.hasNext()) + importSet = getAllImports(new ArrayList(), rootDef); + return (importSet); + } + + private HashSet getAllImports(List alreadyProcessedDefinitions, Definition rootDef) + { + HashSet importSet = new HashSet(); + if ((rootDef != null) && (!alreadyProcessedDefinitions.contains(rootDef))) + { + alreadyProcessedDefinitions.add(rootDef); + Map importMap = rootDef.getImports(); + Iterator i = importMap.values().iterator(); + + while (i.hasNext()) { - Import nextImport = (Import) listIt.next(); - if (nextImport != null) + List nextImportList = (List) (i.next()); + Iterator listIt = nextImportList.iterator(); + while (listIt.hasNext()) { - // its a wsdl document - importSet.add(nextImport); - if (nextImport.getDefinition() != null) + Import nextImport = (Import) listIt.next(); + if (nextImport != null) { - HashSet subTreeImports = getAllImports(nextImport.getDefinition()); - Iterator subIt = subTreeImports.iterator(); - while (subIt.hasNext()) - { - importSet.add((Import) (subIt.next())); - } + importSet.add(nextImport); + Definition def = nextImport.getDefinition(); + HashSet nestedImports = getAllImports(alreadyProcessedDefinitions, def); + for (Iterator j = nestedImports.iterator(); j.hasNext();) + importSet.add(j.next()); } } } } - - return (importSet); + return importSet; } /** diff --git a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/log/LogBuilder.java b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/log/LogBuilder.java index 1c106a2d7..500da92d8 100644 --- a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/log/LogBuilder.java +++ b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/log/LogBuilder.java @@ -20,7 +20,6 @@ import java.util.List; import org.eclipse.core.resources.IFile; import org.eclipse.wst.wsi.internal.core.ToolInfo; import org.eclipse.wst.wsi.internal.core.WSIConstants; -import org.eclipse.wst.wsi.internal.core.WSIException; import org.eclipse.wst.wsi.internal.core.common.AddStyleSheet; import org.eclipse.wst.wsi.internal.core.common.impl.AddStyleSheetImpl; import org.eclipse.wst.wsi.internal.core.document.DocumentFactory; diff --git a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2011.java b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2011.java index b13fbf6a0..f31e0541a 100644 --- a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2011.java +++ b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2011.java @@ -15,6 +15,7 @@ import java.io.InputStreamReader; import java.io.Reader; import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator; import java.util.List; @@ -103,7 +104,7 @@ public class BP2011 extends AssertionProcess implements WSITag ExtensibilityElement el = (ExtensibilityElement) it.next(); if (el instanceof UnknownExtensibilityElement) searchForSchema(((UnknownExtensibilityElement) el).getElement(), - definition.getDocumentBaseURI()); + definition.getDocumentBaseURI(), new ArrayList()); } } @@ -120,27 +121,30 @@ public class BP2011 extends AssertionProcess implements WSITag /* Search xsd schema or xsd import from node. If node is xsd import it's loading schema. * @param n - UnknownExtencibilityElement */ - private void searchForSchema(Node n, String context) + private void searchForSchema(Node n, String context, List processedSchemas) { - while (n != null) + if ((n!= null) && (!processedSchemas.contains(n))) { - // searches for xsd:import element - if (Node.ELEMENT_NODE == n.getNodeType()) + while (n != null) { - // if xsd:schema element is found -> process schema - if (XMLUtils.equals(n, ELEM_XSD_SCHEMA)) - processSchema(n, context); - else - // if xsd:import element is found -> load schema and process schema - // FIXED: if xsd:import is found and parent element is xsd:schema - if (XMLUtils.equals(n, ELEM_XSD_IMPORT) - && XMLUtils.equals(n.getParentNode(), ELEM_XSD_SCHEMA)) - loadSchema(n, context); + // searches for xsd:import element + if (Node.ELEMENT_NODE == n.getNodeType()) + { + // if xsd:schema element is found -> process schema + if (XMLUtils.equals(n, ELEM_XSD_SCHEMA)) + processSchema(n, context, processedSchemas); else - // else iterate element recursively - searchForSchema(n.getFirstChild(), context); + // if xsd:import element is found -> load schema and process schema + // FIXED: if xsd:import is found and parent element is xsd:schema + if (XMLUtils.equals(n, ELEM_XSD_IMPORT) + && XMLUtils.equals(n.getParentNode(), ELEM_XSD_SCHEMA)) + loadSchema(n, context, processedSchemas); + else + // else iterate element recursively + searchForSchema(n.getFirstChild(), context, processedSchemas); + } + n = n.getNextSibling(); } - n = n.getNextSibling(); } } @@ -148,7 +152,7 @@ public class BP2011 extends AssertionProcess implements WSITag * It loads xsd schema and then check the version 1.0 and looking for xsd:schema element for next process. * @param importNode xsd schema */ - private void loadSchema(Node importNode, String context) + private void loadSchema(Node importNode, String context, List processedSchemas) { Element im = (Element) importNode; Attr schemaLocation = XMLUtils.getAttribute(im, ATTR_XSD_SCHEMALOCATION); @@ -170,7 +174,7 @@ public class BP2011 extends AssertionProcess implements WSITag if (XMLUtils.equals(schema.getDocumentElement(), ELEM_XSD_SCHEMA)) { processSchema(schema.getDocumentElement(), - XMLUtils.createURLString(schemaLocation.getValue(), context)); + XMLUtils.createURLString(schemaLocation.getValue(), context), processedSchemas); } result = AssertionResult.RESULT_PASSED; } @@ -326,16 +330,20 @@ public class BP2011 extends AssertionProcess implements WSITag * It's loking for xsd import and load it if find. * @param schema xsd schema */ - private void processSchema(Node schema, String context) + private void processSchema(Node schema, String context, List processedSchemas) { - Node n = schema.getFirstChild(); - while (n != null) - { - if (Node.ELEMENT_NODE == n.getNodeType() - && XMLUtils.equals(n, ELEM_XSD_IMPORT)) - loadSchema(n, context); + if ((schema != null) && (!processedSchemas.contains(schema))) + { + processedSchemas.add(schema); + Node n = schema.getFirstChild(); + while (n != null) + { + if (Node.ELEMENT_NODE == n.getNodeType() + && XMLUtils.equals(n, ELEM_XSD_IMPORT)) + loadSchema(n, context, processedSchemas); - n = n.getNextSibling(); - } + n = n.getNextSibling(); + } + } } }
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2101.java b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2101.java index f9a73efee..9d5a77d3e 100644 --- a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2101.java +++ b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2101.java @@ -20,8 +20,6 @@ import org.eclipse.wst.wsi.internal.core.profile.validator.EntryContext; import org.eclipse.wst.wsi.internal.core.profile.validator.impl.AssertionProcessVisitor; import org.eclipse.wst.wsi.internal.core.report.AssertionResult; import org.eclipse.wst.wsi.internal.core.util.ErrorList; -import org.eclipse.wst.wsi.internal.core.util.TestUtils; -import org.eclipse.wst.wsi.internal.core.util.Utils; import org.eclipse.wst.wsi.internal.core.wsdl.traversal.WSDLTraversal; import org.eclipse.wst.wsi.internal.core.wsdl.traversal.WSDLTraversalContext; @@ -54,7 +52,8 @@ public class BP2101 extends AssertionProcessVisitor implements WSITag public void visit(Import im, Object parent, WSDLTraversalContext ctx) { importFound = true; - + try + { // by the way : WSDL4J throws Exception if imported WSDL is not resolved // but documentation says that im.getDefinition() will be equal to null if (im.getDefinition() == null) @@ -63,24 +62,15 @@ public class BP2101 extends AssertionProcessVisitor implements WSITag + ":" + im.getLocationURI() + "\nImport element does not reference a WSDL definition."); - else - try - { - // try to parse WSDL according to the WSDL schema - validator.parseXMLDocumentURL( - im.getLocationURI(), - ((Definition)parent).getDocumentBaseURI(), - TestUtils.getWSDLSchemaLocation()); - } - catch (Throwable t) - { - errors.add( - im.getNamespaceURI() - + ":" - + im.getLocationURI() - + "\n" - + Utils.getExceptionDetails(t)); - } + } + catch (Exception e) + { + errors.add( + im.getNamespaceURI() + + ":" + + im.getLocationURI() + + "\nImport element does not reference a WSDL definition."); + } } public AssertionResult validate( diff --git a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2102.java b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2102.java index d272b9d75..f959b41be 100644 --- a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2102.java +++ b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2102.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.wst.wsi.internal.core.profile.validator.impl.wsdl; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -84,7 +85,7 @@ public class BP2102 extends AssertionProcess implements WSITag if (el instanceof UnknownExtensibilityElement && el.getElementType().equals(ELEM_XSD_SCHEMA)) testNode(((UnknownExtensibilityElement) el).getElement(), - definition.getDocumentBaseURI()); + definition.getDocumentBaseURI(), new ArrayList()); if (result.equals(AssertionResult.RESULT_FAILED)) { @@ -118,86 +119,92 @@ public class BP2102 extends AssertionProcess implements WSITag * definition (e.g. WSDL). * @param n - Unknown extensibility element */ - private void testNode(Node n, String context) + private void testNode(Node n, String context, List processedSchemas) { - while (n != null) - { - // searches for xsd:import element - if (Node.ELEMENT_NODE == n.getNodeType()) + if ((n != null) && (!processedSchemas.contains(n))) + { + if (XMLUtils.equals(n.getParentNode(), ELEM_XSD_SCHEMA)) + processedSchemas.add(n); + + while (n != null) { - if (XMLUtils.equals(n, ELEM_XSD_IMPORT)) + // searches for xsd:import element + if (Node.ELEMENT_NODE == n.getNodeType()) { - importFound = true; - - Element im = (Element) n; - // Getting the schemaLocation and the namespace attributes - Attr schemaLocation = - XMLUtils.getAttribute(im, ATTR_XSD_SCHEMALOCATION); - Attr namespace = XMLUtils.getAttribute(im, ATTR_XSD_NAMESPACE); - // If there is only the namespace attribute of import element - if (schemaLocation == null && namespace != null) + if (XMLUtils.equals(n, ELEM_XSD_IMPORT)) { - // Getting all the inline schemas of the wsdl definition - Map schemasMap = validator.wsdlDocument.getSchemas(); - // If an inline schema imported is defined - if (schemasMap.keySet().contains(namespace.getValue())) + importFound = true; + + Element im = (Element) n; + // Getting the schemaLocation and the namespace attributes + Attr schemaLocation = + XMLUtils.getAttribute(im, ATTR_XSD_SCHEMALOCATION); + Attr namespace = XMLUtils.getAttribute(im, ATTR_XSD_NAMESPACE); + // If there is only the namespace attribute of import element + if (schemaLocation == null && namespace != null) { + // Getting all the inline schemas of the wsdl definition + Map schemasMap = validator.wsdlDocument.getSchemas(); // If an inline schema imported is defined - // (that means the schema is valid), - // continue with the next element - n = n.getNextSibling(); - continue; - } + if (schemasMap.keySet().contains(namespace.getValue())) + { + // If an inline schema imported is defined + // (that means the schema is valid), + // continue with the next element + n = n.getNextSibling(); + continue; + } - // no schemaLocation so try the namespace - schemaLocation = namespace; - } + // no schemaLocation so try the namespace + schemaLocation = namespace; + } - // try to parse imported XSD - if (schemaLocation != null && schemaLocation.getValue() != null) - { - try + // try to parse imported XSD + if (schemaLocation != null && schemaLocation.getValue() != null) { - // if any error or root element is not XSD schema -> error - // !! ATTENTION - // root XSD SCHEMA SCHEMA is not valid - //Document schema = XMLUtils.parseXMLDocumentURL(schemaLocation.getValue(), XSD_SCHEMALOCATION, context); - Document schema = - validator.parseXMLDocumentURL(schemaLocation.getValue(), context); - - // If the import is valid, then check its contents - if (XMLUtils - .equals(schema.getDocumentElement(), ELEM_XSD_SCHEMA)) + try { - // Check content of imported document - testNode(schema.getDocumentElement().getFirstChild(), - XMLUtils.createURLString(schemaLocation.getValue(), context)); + // if any error or root element is not XSD schema -> error + // !! ATTENTION + // root XSD SCHEMA SCHEMA is not valid + //Document schema = XMLUtils.parseXMLDocumentURL(schemaLocation.getValue(), XSD_SCHEMALOCATION, context); + Document schema = + validator.parseXMLDocumentURL(schemaLocation.getValue(), context); + + // If the import is valid, then check its contents + if (XMLUtils + .equals(schema.getDocumentElement(), ELEM_XSD_SCHEMA)) + { + // Check content of imported document + testNode(schema.getDocumentElement().getFirstChild(), + XMLUtils.createURLString(schemaLocation.getValue(), context), processedSchemas); + } + + else + { + throw new Exception(); + } } - - else + catch (Throwable t) { - throw new Exception(); + result = AssertionResult.RESULT_FAILED; + failureDetailMessage = schemaLocation.getValue(); + break; } } - catch (Throwable t) + else { - result = AssertionResult.RESULT_FAILED; - failureDetailMessage = schemaLocation.getValue(); + //result = AssertionResult.RESULT_FAILED; + result = AssertionResult.RESULT_NOT_APPLICABLE; + failureDetailMessage = + "schemaLocation == null and namespace == null"; break; } } - else - { - //result = AssertionResult.RESULT_FAILED; - result = AssertionResult.RESULT_NOT_APPLICABLE; - failureDetailMessage = - "schemaLocation == null and namespace == null"; - break; - } + testNode(n.getFirstChild(), context, processedSchemas); } - testNode(n.getFirstChild(), context); + n = n.getNextSibling(); } - n = n.getNextSibling(); } } }
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2202.java b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2202.java index 7bdc86db3..3eed0d137 100644 --- a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2202.java +++ b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/BP2202.java @@ -15,6 +15,7 @@ import java.io.InputStreamReader; import java.io.Reader; import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator; import java.util.List; @@ -102,7 +103,7 @@ public class BP2202 extends AssertionProcess implements WSITag if (el instanceof UnknownExtensibilityElement && el.getElementType().equals(ELEM_XSD_SCHEMA)) searchForSchema(((UnknownExtensibilityElement) el).getElement(), - definition.getDocumentBaseURI()); + definition.getDocumentBaseURI(), new ArrayList()); } } @@ -125,32 +126,35 @@ public class BP2202 extends AssertionProcess implements WSITag * Search xsd schema or xsd import from node. If node is xsd import it's loading schema. * @param n - node */ - private void searchForSchema(Node n, String context) + private void searchForSchema(Node n, String context, List processedSchemas) { - while (n != null) - { - // searches for xsd:import element - if (Node.ELEMENT_NODE == n.getNodeType()) + if ((n!= null) && (!processedSchemas.contains(n))) + { + while (n != null) { - // if xsd:schema element is found -> process schema - if (XMLUtils.equals(n, ELEM_XSD_SCHEMA)) - { - processSchema(n, context); - } - else + // searches for xsd:import element + if (Node.ELEMENT_NODE == n.getNodeType()) { - // if xsd:import element is found -> load schema and process schema - if (XMLUtils.equals(n, ELEM_XSD_IMPORT)) + // if xsd:schema element is found -> process schema + if (XMLUtils.equals(n, ELEM_XSD_SCHEMA)) { - importFound = true; - loadSchema(n, context); + processSchema(n, context, processedSchemas); } else - // else iterate element recursively - searchForSchema(n.getFirstChild(), context); + { + // if xsd:import element is found -> load schema and process schema + if (XMLUtils.equals(n, ELEM_XSD_IMPORT)) + { + importFound = true; + loadSchema(n, context, processedSchemas); + } + else + // else iterate element recursively + searchForSchema(n.getFirstChild(), context, processedSchemas); + } } + n = n.getNextSibling(); } - n = n.getNextSibling(); } } @@ -158,7 +162,7 @@ public class BP2202 extends AssertionProcess implements WSITag * It loads xsd schema and then check valid encoding and looking for xsd:schema element for next process. * @param importNode - xsd schema */ - private void loadSchema(Node importNode, String context) + private void loadSchema(Node importNode, String context, List processedSchemas) { Element im = (Element) importNode; Attr schemaLocation = XMLUtils.getAttribute(im, ATTR_XSD_SCHEMALOCATION); @@ -193,7 +197,7 @@ public class BP2202 extends AssertionProcess implements WSITag if (XMLUtils.equals(schema.getDocumentElement(), ELEM_XSD_SCHEMA)) { processSchema(schema.getDocumentElement(), - XMLUtils.createURLString(schemaLocation.getValue(), context)); + XMLUtils.createURLString(schemaLocation.getValue(), context), processedSchemas); } result = AssertionResult.RESULT_PASSED; } @@ -401,19 +405,23 @@ public class BP2202 extends AssertionProcess implements WSITag * @param schema - xsd schema * @param namespace - namespace of schema */ - private void processSchema(Node schema, String context) + private void processSchema(Node schema, String context, List processedSchemas) { - Node n = schema.getFirstChild(); - while (n != null) - { - if (Node.ELEMENT_NODE == n.getNodeType() - && XMLUtils.equals(n, ELEM_XSD_IMPORT)) + if ((schema != null) && (!processedSchemas.contains(schema))) + { + processedSchemas.add(schema); + Node n = schema.getFirstChild(); + while (n != null) { - importFound = true; - loadSchema(n, context); - } + if (Node.ELEMENT_NODE == n.getNodeType() + && XMLUtils.equals(n, ELEM_XSD_IMPORT)) + { + importFound = true; + loadSchema(n, context, processedSchemas); + } - n = n.getNextSibling(); + n = n.getNextSibling(); + } } } diff --git a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/WSDLValidatorImpl.java b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/WSDLValidatorImpl.java index 213fcf45a..c2303cf1e 100644 --- a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/WSDLValidatorImpl.java +++ b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/profile/validator/impl/wsdl/WSDLValidatorImpl.java @@ -12,6 +12,7 @@ package org.eclipse.wst.wsi.internal.core.profile.validator.impl.wsdl; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -1732,32 +1733,46 @@ public class WSDLValidatorImpl */ protected List getWSDLTargetNamespaceList(Definition definition) { - List list = new Vector(); + return getWSDLTargetNamespaceList(definition, new ArrayList()); + } - // Always add current document targetNamespace - if (definition.getTargetNamespace() != null) - list.add(definition.getTargetNamespace()); + /** + * Build list of WSDL targetNamespaces. + * @param definition a Definition object. + * @return list of WSDL targetNamespaces. + */ + protected List getWSDLTargetNamespaceList(Definition definition, List alreadyProcessedDefinitions) + { + List list = new ArrayList(); + if ((definition != null) && (!alreadyProcessedDefinitions.contains(definition))) + { + alreadyProcessedDefinitions.add(definition); + + // Always add current document targetNamespace + if (definition.getTargetNamespace() != null) + list.add(definition.getTargetNamespace()); - // Get list of imported WSDL documents - Map importMap = definition.getImports(); + // Get list of imported WSDL documents + Map importMap = definition.getImports(); - Import imp; + Import imp; - // Add each imports targetNamespace to the list - if (importMap != null && !importMap.isEmpty()) - { - Iterator values = importMap.values().iterator(); - List importList; - while (values.hasNext()) + // Add each imports targetNamespace to the list + if (importMap != null && !importMap.isEmpty()) { - importList = (List) values.next(); - Iterator imports = importList.iterator(); - while (imports.hasNext()) + Iterator values = importMap.values().iterator(); + List importList; + while (values.hasNext()) { - imp = (Import) imports.next(); - if (imp != null && imp.getDefinition() != null) - list.addAll(getWSDLTargetNamespaceList(imp.getDefinition())); + importList = (List) values.next(); + Iterator imports = importList.iterator(); + while (imports.hasNext()) + { + imp = (Import) imports.next(); + if (imp != null && imp.getDefinition() != null) + list.addAll(getWSDLTargetNamespaceList(imp.getDefinition(), alreadyProcessedDefinitions)); // list.add(imp.getDefinition().getTargetNamespace()); + } } } } diff --git a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/util/TypesRegistry.java b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/util/TypesRegistry.java index 6c12b28f9..6afdab95f 100644 --- a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/util/TypesRegistry.java +++ b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/util/TypesRegistry.java @@ -421,7 +421,7 @@ public final class TypesRegistry implements WSITag, WSDLVisitor { // if xsd:schema element is found -> process schema if (XMLUtils.equals(n, ELEM_XSD_SCHEMA)) - processSchema(n, context); + processSchema(n, context, new ArrayList()); } n = n.getNextSibling(); } @@ -433,7 +433,7 @@ public final class TypesRegistry implements WSITag, WSDLVisitor * @param importNode * @param context */ - private void loadSchema(Node importNode, String context) + private void loadSchema(Node importNode, String context, List processedSchemas) { Element im = (Element) importNode; Attr schemaLocation = XMLUtils.getAttribute(im, ATTR_XSD_SCHEMALOCATION); @@ -455,7 +455,7 @@ public final class TypesRegistry implements WSITag, WSDLVisitor if (XMLUtils.equals(schema.getDocumentElement(), ELEM_XSD_SCHEMA)) processSchema( schema.getDocumentElement(), - urlString); + urlString, processedSchemas); } } catch (Throwable t) @@ -471,66 +471,70 @@ public final class TypesRegistry implements WSITag, WSDLVisitor * @param schema * @param context */ - private void processSchema(Node schema, String context) - { - Attr a = XMLUtils.getAttribute((Element) schema, ATTR_XSD_TARGETNAMESPACE); - String targetNamespace = (a != null) ? a.getValue() : ""; - // iterate schema - Node n = schema.getFirstChild(); - // !! we suppose that xsd:import element is occured only within xsd:schema element - while (n != null) - { - if (Node.ELEMENT_NODE == n.getNodeType()) + private void processSchema(Node schema, String context, List processedSchemas) + { + if ((schema != null) && (!processedSchemas.contains(schema))) + { + processedSchemas.add(schema); + Attr a = XMLUtils.getAttribute((Element) schema, ATTR_XSD_TARGETNAMESPACE); + String targetNamespace = (a != null) ? a.getValue() : ""; + // iterate schema + Node n = schema.getFirstChild(); + // !! we suppose that xsd:import element is occured only within xsd:schema element + while (n != null) { - if (XMLUtils.equals(n, ELEM_XSD_ELEMENT)) + if (Node.ELEMENT_NODE == n.getNodeType()) { - Element el = (Element) n; - a = XMLUtils.getAttribute(el, ATTR_XSD_NAME); - QName element = - new QName(targetNamespace, (a != null) ? a.getValue() : ""); - - a = XMLUtils.getAttribute(el, ATTR_XSD_TYPE); - QName type = null; - if (a != null) + if (XMLUtils.equals(n, ELEM_XSD_ELEMENT)) { - String t = a.getValue(); - // if type contains ':', it means that it contains qname - int i = t.indexOf(':'); - if (i != -1) + Element el = (Element) n; + a = XMLUtils.getAttribute(el, ATTR_XSD_NAME); + QName element = + new QName(targetNamespace, (a != null) ? a.getValue() : ""); + + a = XMLUtils.getAttribute(el, ATTR_XSD_TYPE); + QName type = null; + if (a != null) { - String prefix = t.substring(0, i); - String nsURI = XMLUtils.findNamespaceURI(n, prefix); - type = new QName(nsURI, t.substring(i + 1)); + String t = a.getValue(); + // if type contains ':', it means that it contains qname + int i = t.indexOf(':'); + if (i != -1) + { + String prefix = t.substring(0, i); + String nsURI = XMLUtils.findNamespaceURI(n, prefix); + type = new QName(nsURI, t.substring(i + 1)); + } + else + type = new QName(targetNamespace, t); } else - type = new QName(targetNamespace, t); + { + // suppose that element directly contains type declaration + type = element; + checkType(n, type); + } + + element2Type.put(element, type); } - else + else if (XMLUtils.equals(n, ELEM_XSD_IMPORT)) + loadSchema(n, context, processedSchemas); + else if (XMLUtils.equals(n, ELEM_XSD_INCLUDE)) + loadSchema(n, context, processedSchemas); + else if (XMLUtils.equals(n, ELEM_XSD_COMPLEXTYPE)) { - // suppose that element directly contains type declaration - type = element; + Element el = (Element) n; + a = XMLUtils.getAttribute(el, ATTR_XSD_NAME); + QName type = + new QName(targetNamespace, (a != null) ? a.getValue() : ""); checkType(n, type); } - element2Type.put(element, type); - } - else if (XMLUtils.equals(n, ELEM_XSD_IMPORT)) - loadSchema(n, context); - else if (XMLUtils.equals(n, ELEM_XSD_INCLUDE)) - loadSchema(n, context); - else if (XMLUtils.equals(n, ELEM_XSD_COMPLEXTYPE)) - { - Element el = (Element) n; - a = XMLUtils.getAttribute(el, ATTR_XSD_NAME); - QName type = - new QName(targetNamespace, (a != null) ? a.getValue() : ""); - checkType(n, type); } + n = n.getNextSibling(); } - - n = n.getNextSibling(); - } + } } /** diff --git a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/util/WSDLUtil.java b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/util/WSDLUtil.java index 1adcf00b7..50de6c311 100644 --- a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/util/WSDLUtil.java +++ b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/util/WSDLUtil.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.wst.wsi.internal.core.util; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -80,7 +81,7 @@ public final class WSDLUtil { Iterator it2 = v.iterator(); while (it2.hasNext()) - expandDefinition(def, (Import) it2.next()); + expandDefinition(def, (Import) it2.next(), new ArrayList()); } } } @@ -91,45 +92,50 @@ public final class WSDLUtil * @param target WSDL definition. * @param im internal method. */ - static private void expandDefinition(Definition target, Import im) + static private void expandDefinition(Definition target, Import im, List processedDefinitions) { - if (im != null && im.getDefinition() != null) + if (im != null) { Definition d = im.getDefinition(); - if (d.getMessages() != null) + if ((d != null) && (!processedDefinitions.contains(d))) { - Iterator it = d.getMessages().values().iterator(); - while (it.hasNext()) - target.addMessage((Message) it.next()); - } - if (d.getPortTypes() != null) - { - Iterator it = d.getPortTypes().values().iterator(); - while (it.hasNext()) - target.addPortType((PortType) it.next()); - } - if (d.getBindings() != null) - { - Iterator it = d.getBindings().values().iterator(); - while (it.hasNext()) - target.addBinding((Binding) it.next()); - } - if (d.getServices() != null) - { - Iterator it = d.getServices().values().iterator(); - while (it.hasNext()) - target.addService((Service) it.next()); - } + processedDefinitions.add(d); - Iterator it = d.getImports().values().iterator(); - while (it.hasNext()) - { - List v = (List) it.next(); - if (v != null) + if (d.getMessages() != null) { - Iterator it2 = v.iterator(); - while (it2.hasNext()) - expandDefinition(target, (Import) it2.next()); + Iterator it = d.getMessages().values().iterator(); + while (it.hasNext()) + target.addMessage((Message) it.next()); + } + if (d.getPortTypes() != null) + { + Iterator it = d.getPortTypes().values().iterator(); + while (it.hasNext()) + target.addPortType((PortType) it.next()); + } + if (d.getBindings() != null) + { + Iterator it = d.getBindings().values().iterator(); + while (it.hasNext()) + target.addBinding((Binding) it.next()); + } + if (d.getServices() != null) + { + Iterator it = d.getServices().values().iterator(); + while (it.hasNext()) + target.addService((Service) it.next()); + } + + Iterator it = d.getImports().values().iterator(); + while (it.hasNext()) + { + List v = (List) it.next(); + if (v != null) + { + Iterator it2 = v.iterator(); + while (it2.hasNext()) + expandDefinition(target, (Import) it2.next(), processedDefinitions); + } } } } diff --git a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/wsdl/traversal/WSDLTraversal.java b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/wsdl/traversal/WSDLTraversal.java index 4a3569a77..1abc2b592 100644 --- a/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/wsdl/traversal/WSDLTraversal.java +++ b/bundles/org.eclipse.wst.wsi/src/org/eclipse/wst/wsi/internal/core/wsdl/traversal/WSDLTraversal.java @@ -9,7 +9,9 @@ * IBM - Initial API and implementation *******************************************************************************/ package org.eclipse.wst.wsi.internal.core.wsdl.traversal; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Vector; @@ -147,12 +149,14 @@ public class WSDLTraversal private boolean visitSOAPHeaderFault = false; private boolean visitSOAPOperation = false; + List alreadyTraversedDefinitions; /** * Default constructor. * @see java.lang.Object#Object() */ public WSDLTraversal() { + alreadyTraversedDefinitions = new ArrayList(); } /** @@ -1822,16 +1826,20 @@ public class WSDLTraversal Object parent, WSDLTraversalContext ctx) { + if ((objDefinition == null) || (this.alreadyTraversedDefinitions.contains(objDefinition))) + { + return; + } + this.alreadyTraversedDefinitions.add(objDefinition); ctx.resumeDefinitionProcessing(); ctx.setDefinition(objDefinition); + if (visitDefinition) { visitor.visit(objDefinition, parent, ctx); if (!ctx.processDefinition()) return; } - if (objDefinition == null) - return; if (traverseDefinition2Import && objDefinition.getImports() != null) { Iterator it = objDefinition.getImports().values().iterator(); @@ -2560,7 +2568,18 @@ public class WSDLTraversal return; } if (traverseImport2Definition) - traverse(objImport.getDefinition(), objImport, ctx); + { + try + { + Definition definition = objImport.getDefinition(); + if ((definition != null) && (!alreadyTraversedDefinitions.contains(definition))) + { + alreadyTraversedDefinitions.add(definition); + traverse(objImport.getDefinition(), objImport, ctx); + } + } + catch (Exception e){} + } } /** |