You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ra...@apache.org on 2009/03/26 11:24:24 UTC
svn commit: r758583 -
/tuscany/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
Author: ramkumar
Date: Thu Mar 26 10:24:11 2009
New Revision: 758583
URL: http://svn.apache.org/viewvc?rev=758583&view=rev
Log:
Fixes for TUSCANY-2906
Modified:
tuscany/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
Modified: tuscany/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java?rev=758583&r1=758582&r2=758583&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java (original)
+++ tuscany/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java Thu Mar 26 10:24:11 2009
@@ -85,8 +85,27 @@
public <T> T resolveModel(Class<T> modelClass, T unresolved) {
XSDefinition definition = (XSDefinition)unresolved;
- // Lookup a definition for the given namespace
String namespace = definition.getNamespace();
+ XSDefinition resolved = null;
+
+ // Lookup for a definition using the non-sca mechanism
+ if (definition.getDocument() != null) {
+ try {
+ List<XSDefinition> list = new ArrayList<XSDefinition>();
+ list.add(definition);
+ map.put(namespace, list);
+ resolved = aggregate(list);
+ // no exception thrown, then its resolved.
+ if (resolved != null && !resolved.isUnresolved()) {
+ return modelClass.cast(resolved);
+ }
+ } catch (ContributionRuntimeException e) {
+ // do nothing, lookup using sca mechanism
+ }
+ }
+
+ // Lookup a definition for the given namespace within the
+ // current contribution.
List<XSDefinition> list = map.get(namespace);
XSDefinition modelXSD = null;
if (list != null && definition.getDocument() != null) {
@@ -96,17 +115,10 @@
modelXSD = list.get(index);
modelXSD.setDocument(definition.getDocument());
}
- }
- if (list == null && definition.getDocument() != null) {
- // Hit for the 1st time
- list = new ArrayList<XSDefinition>();
- list.add(definition);
- map.put(namespace, list);
- }
- XSDefinition resolved = null;
+ }
try {
resolved = aggregate(list);
- } catch (IOException e) {
+ } catch (ContributionRuntimeException e) {
throw new ContributionRuntimeException(e);
}
if (resolved != null && !resolved.isUnresolved()) {
@@ -147,7 +159,7 @@
return modelClass.cast(unresolved);
}
- private void loadOnDemand(XSDefinition definition) throws IOException {
+ private void loadOnDemand(XSDefinition definition) throws ContributionRuntimeException {
if (definition.getSchema() != null) {
return;
}
@@ -155,6 +167,14 @@
String uri = null;
if (definition.getLocation() != null) {
uri = definition.getLocation().toString();
+ }
+ for (XmlSchema d : schemaCollection.getXmlSchemas()) {
+ if (d.getSourceURI() != null && d.getSourceURI().equals(uri)) {
+ definition.setSchemaCollection(schemaCollection);
+ definition.setSchema(d);
+ definition.setUnresolved(false);
+ return;
+ }
}
XmlSchema schema = null;
try {
@@ -176,7 +196,12 @@
return;
}
// Read an XSD document
- InputSource xsd = XMLDocumentHelper.getInputSource(definition.getLocation().toURL());
+ InputSource xsd;
+ try {
+ xsd = XMLDocumentHelper.getInputSource(definition.getLocation().toURL());
+ } catch (IOException e) {
+ throw new ContributionRuntimeException(e);
+ }
for (XmlSchema d : schemaCollection.getXmlSchemas()) {
if (isSameNamespace(d.getTargetNamespace(), definition.getNamespace())) {
if (d.getSourceURI().equals(definition.getLocation().toString()))
@@ -214,7 +239,7 @@
* namespace
* @return The aggregated XmlSchema
*/
- private XSDefinition aggregate(List<XSDefinition> definitions) throws IOException {
+ private XSDefinition aggregate(List<XSDefinition> definitions) throws ContributionRuntimeException {
if (definitions == null || definitions.size() == 0) {
return null;
}