}
}
public <T> T resolveModel(Class<T> modelClass, T unresolved) {
XSDefinition definition = (XSDefinition)unresolved;
// Lookup a definition for the given namespace
String namespace = definition.getNamespace();
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);
}
XSDefinition resolved = null;
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);
}
// No definition found, delegate the resolution to the imports
for (Import import_ : this.contribution.getImports()) {
if (import_ instanceof NamespaceImport) {
NamespaceImport namespaceImport = (NamespaceImport)import_;
if (namespaceImport.getNamespace().equals(namespace)) {
// Delegate the resolution to the namespace import resolver
resolved =
namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved);
if (!resolved.isUnresolved()) {
return modelClass.cast(resolved);
}
}
} 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);
}
}
}
return modelClass.cast(unresolved);