summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2012-05-01 08:15:15 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2012-05-01 08:15:15 +0000
commitfaa4500506113c301c163a740d2217e1c6b93f72 (patch)
treed451a7c71ca634a46c83e06f6157155619d2c781 /sca-java-2.x
parenteb12d84e82df29319ad394ed646990f68f180a60 (diff)
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
Diffstat (limited to 'sca-java-2.x')
-rw-r--r--sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java59
1 files changed, 36 insertions, 23 deletions
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<InputSource>() {
- 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<InputSource>() {
- 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<InputSource>() {
+ public InputSource run() throws IOException {
+ return XMLDocumentHelper.getInputSource(url);
+ }
+ });
+ } catch (PrivilegedActionException pae) {
+ throw (IOException) pae.getException();
+ }
+ }
}
}