}
}
public <T> T resolveModel(Class<T> modelClass, T unresolved) {
XSDefinition definition = (XSDefinition)unresolved;
String namespace = definition.getNamespace();
XSDefinition resolved = null;
// FIXME - We should not be using import resolvers for inline schema.
/* // Lookup a definition for the given namespace, from imports
List<String> locations = new ArrayList<String>();
// Collection of namespace imports with location
Map<String, NamespaceImport> locationMap = new HashMap<String, NamespaceImport>();
for (Import import_ : this.contribution.getImports()) {
if (import_ instanceof NamespaceImport) {
NamespaceImport namespaceImport = (NamespaceImport)import_;
if (namespaceImport.getNamespace().equals(namespace)) {
if (namespaceImport.getLocation() == null) {
// Delegate the resolution to the namespace import resolver
resolved =
namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved);
if (!resolved.isUnresolved()) {
return modelClass.cast(resolved);
}
} else {
// We might have multiple imports for the same namespace,
// need to search them in lexical order.
locations.add(namespaceImport.getLocation());
}
}
}
else if (import_ instanceof DefaultImport) {
// Delegate the resolution to the default import resolver
resolved =
import_.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved);
if (!resolved.isUnresolved()) {
return modelClass.cast(resolved);
}
}
}
// Search namespace imports with location in lexical order
Collections.sort(locations);
for (String location : locations) {
NamespaceImport namespaceImport = (NamespaceImport)locationMap.get(location);
// Delegate the resolution to the namespace import resolver
resolved =
namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved);
if (!resolved.isUnresolved()) {
return modelClass.cast(resolved);
}
} */
// Lookup a definition for the given namespace, within the contribution
List<XSDefinition> list = map.get(namespace);
XSDefinition modelXSD = null;
if (list != null && definition.getDocument() != null) {
// Set the document for the inline schema
int index = list.indexOf(definition);
if (index != -1) { // a matching (not identical) document was found
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);
}
try {
resolved = aggregate(list);
} catch (IOException e) {
throw new ContributionRuntimeException(e);
}
if (resolved != null && !resolved.isUnresolved()) {
if (definition.isUnresolved() && definition.getSchema() == null && modelXSD != null) {
// Update the unresolved model with schema information and mark it
// resolved. This information in the unresolved model is needed when
// this method is called by WSDLModelResolver.readInlineSchemas().
definition.setSchema(modelXSD.getSchema());
definition.setSchemaCollection(modelXSD.getSchemaCollection());
definition.setUnresolved(false);
}
return modelClass.cast(resolved);
}