in blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/namespace/NamespaceHandlerRegistryImpl.java [470:559]
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
// Compute id
String id;
String prevNamespace = baseURI != null ? namespaces.get(baseURI) : null;
if (namespaceURI != null && prevNamespace != null && namespaceURI.equals(prevNamespace)) {
// This is an include
id = getId(type, namespaceURI, publicId, systemId);
} else {
id = getId(type, namespaceURI, publicId, null);
}
// Check if it has already been loaded
if (loaded.containsKey(id)) {
return createLSInput(loaded.get(id), id, namespaceURI);
}
// Schema map
//-----------
// Use provided schema map to find the resource.
// If the schema map contains the namespaceURI, publicId or systemId,
// load the corresponding resource directly from the bundle.
String loc = null;
if (namespaceURI != null) {
loc = schemaMap.getProperty(namespaceURI);
}
if (loc == null && publicId != null) {
loc = schemaMap.getProperty(publicId);
}
if (loc == null && systemId != null) {
loc = schemaMap.getProperty(systemId);
}
if (loc != null) {
URL url = bundle.getResource(loc);
if (url != null) {
return createLSInput(url, id, namespaceURI);
}
}
// Relative uris
//---------------
// For relative uris, don't use the namespace handlers, but simply resolve the uri
// and use that one directly to load the resource.
String resolved = resolveIfRelative(systemId, baseURI);
if (resolved != null) {
URL url;
try {
url = new URL(resolved);
} catch (IOException e) {
throw new RuntimeException(e);
}
return createLSInput(url, id, namespaceURI);
}
// Only support xml schemas from now on
if (namespaceURI == null || !W3C_XML_SCHEMA_NS_URI.equals(type)) {
return null;
}
// We are now loading a schema, or schema part with
// * notNull(namespaceURI)
// * null(systemId) or absolute(systemId)
URI nsUri = URI.create(namespaceURI);
String rid = systemId != null ? systemId : namespaceURI;
NamespaceHandler h = getNamespaceHandler(nsUri);
// This is a resource from a known namespace
if (h != null) {
URL url = h.getSchemaLocation(rid);
if (isCorrectUrl(url)) {
return createLSInput(url, id, namespaceURI);
}
}
else {
// Ask known handlers if they have this schema
for (NamespaceHandler hd : handlers.values()) {
URL url = hd.getSchemaLocation(rid);
if (isCorrectUrl(url)) {
return createLSInput(url, id, namespaceURI);
}
}
// Find a compatible namespace handler
h = findCompatibleNamespaceHandler(nsUri);
if (h != null) {
URL url = h.getSchemaLocation(namespaceURI);
if (url == null) {
url = h.getSchemaLocation(rid);
}
if (isCorrectUrl(url)) {
LOGGER.warn("Dynamically adding namespace handler {} to {}/{}", nsUri, bundle.getSymbolicName(), bundle.getVersion());
return createLSInput(url, id, namespaceURI);
}
}
}
LOGGER.warn("Unable to find namespace handler for {}", namespaceURI);
return null;
}