You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2012/05/01 10:15:16 UTC
svn commit: r1332565 -
/tuscany/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
Author: antelder
Date: Tue May 1 08:15:15 2012
New Revision: 1332565
URL: http://svn.apache.org/viewvc?rev=1332565&view=rev
Log:
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
Modified:
tuscany/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
Modified: tuscany/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java?rev=1332565&r1=1332564&r2=1332565&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java Tue May 1 08:15:15 2012
@@ -374,6 +374,7 @@ public class XSDModelResolver implements
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
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
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
}
}
}
+ 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();
+ }
+ }
}
}