}
}
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);
if (list != null && definition.getDocument() != null) {
// Set the document for the inline schema
int index = list.indexOf(definition);
if (index != -1) {
list.get(index).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()) {
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 import resolver
resolved =
namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved);
if (!resolved.isUnresolved()) {
return modelClass.cast(resolved);
}
}
}
}