From faa4500506113c301c163a740d2217e1c6b93f72 Mon Sep 17 00:00:00 2001 From: antelder Date: Tue, 1 May 2012 08:15:15 +0000 Subject: TUSCANY-4041: Apply patch from Brian Sullivan to fix XSDModelResolver fails to resolve schema where location attribute is incorrect specified but schema may be available via artifact resolution git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1332565 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/sca/xsd/xml/XSDModelResolver.java | 59 +++++++++++++--------- 1 file changed, 36 insertions(+), 23 deletions(-) (limited to 'sca-java-2.x/trunk/modules/xsd') diff --git a/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java b/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java index 535bc1cd44..244df9f51b 100644 --- a/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java +++ b/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java @@ -374,6 +374,7 @@ public class XSDModelResolver implements ModelResolver { unresolved.setNamespace(targetNamespace); for (Import import_ : this.contribution.getImports()) { + URL resolvedURL; if (import_ instanceof NamespaceImport) { NamespaceImport namespaceImport = (NamespaceImport)import_; if (namespaceImport.getNamespace().equals(targetNamespace)) { @@ -381,7 +382,8 @@ public class XSDModelResolver implements ModelResolver { resolved = namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved, context); if (!resolved.isUnresolved()) { - return XMLDocumentHelper.getInputSource(resolved.getLocation().toURL()); + resolvedURL = resolved.getLocation().toURL(); + return xmlDocumentHelperGetInputSource(resolvedURL); } } } else if (import_ instanceof DefaultImport) { @@ -389,16 +391,8 @@ public class XSDModelResolver implements ModelResolver { resolved = import_.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved, context); if (!resolved.isUnresolved()) { - final XSDefinition finalres = resolved; - try { - return (InputSource)AccessController.doPrivileged( new PrivilegedExceptionAction() { - public InputSource run() throws IOException { - return XMLDocumentHelper.getInputSource(finalres.getLocation().toURL()); - } - }); - } catch (PrivilegedActionException e) { - throw (IOException) e.getException(); - } + resolvedURL = resolved.getLocation().toURL(); + return xmlDocumentHelperGetInputSource(resolvedURL); } } } @@ -436,27 +430,46 @@ public class XSDModelResolver implements ModelResolver { } } } + return xmlDocumentHelperGetInputSource(url); + + } catch (IOException e) { + // If we are not able to resolve the imports using location, then + // try resolving them using the namespace. try { - final URL finalurl = url; - return (InputSource)AccessController.doPrivileged( new PrivilegedExceptionAction() { - public InputSource run() throws IOException { - return XMLDocumentHelper.getInputSource(finalurl); + for (Artifact artifact : contribution.getArtifacts()) { + if (artifact.getModel() instanceof XSDefinitionImpl) { + String artifactNamespace = ((XSDefinitionImpl)artifact.getModel()).getNamespace(); + if (targetNamespace.equals(artifactNamespace)) { + final URL artifactLocation = ((XSDefinitionImpl)artifact.getModel()).getLocation().toURL(); + return xmlDocumentHelperGetInputSource(artifactLocation); + } } - }); - } catch (PrivilegedActionException e) { - throw (IOException) e.getException(); + } + // add another default return statement + return new InputSource(schemaLocation); + } catch (IOException ioe) { + // Invalid URI; return a default InputSource so that the + // XmlSchema code will produce a useful diagnostic + return new InputSource(schemaLocation); } - - } catch (IOException e) { - // Invalid URI; return a default InputSource so that the - // XmlSchema code will produce a useful diagnostic - return new InputSource(schemaLocation); } catch (URISyntaxException e) { // Invalid URI; return a default InputSource so that the // XmlSchema code will produce a useful diagnostic return new InputSource(schemaLocation); } } + + private InputSource xmlDocumentHelperGetInputSource(final URL url) throws IOException { + try { + return (InputSource)AccessController.doPrivileged( new PrivilegedExceptionAction() { + public InputSource run() throws IOException { + return XMLDocumentHelper.getInputSource(url); + } + }); + } catch (PrivilegedActionException pae) { + throw (IOException) pae.getException(); + } + } } } -- cgit v1.2.3