{
final Namespaces namespaces = Namespaces.instance();
final String namespace = registry.isShared() ? Namespaces.DEFAULT : registry.getName();
// - first merge on the namespace registry descriptor (if needed)
final Merger merger = Merger.instance();
boolean requiresMerge = merger.requiresMerge(namespace);
if (requiresMerge)
{
registry =
(NamespaceRegistry)registryFactory.getObject(
merger.getMergedString(
ResourceUtils.getContents(resource),
namespace), resource);
}
// - add the resource root
registry.addResourceRoot(this.getNamespaceResourceRoot(resource));
// - only log the fact we've found the namespace registry, if we haven't done it yet
if (!this.registeredRegistries.contains(registryName))
{
AndroMDALogger.info("found namespace --> '" + registryName + "'");
this.registeredRegistries.add(registryName);
}
final NamespaceRegistry existingRegistry = namespaces.getRegistry(registryName);
if (existingRegistry != null)
{
// - if we already have an existing registry with the same name, copy
// over any resources.
registry.copy(existingRegistry);
}
// - add the registry to the namespaces instance
namespaces.addRegistry(registry);
final String[] components = registry.getRegisteredComponents();
final int componentNumber = components.length;
for (int componentCtr = 0; componentCtr < componentNumber; componentCtr++)
{
final String componentName = components[componentCtr];
final Component component = this.getComponent(componentName);
if (component == null)
{
throw new NamespaceComponentsException("'" + componentName +
"' is not a valid namespace component");
}
// - add any paths defined within the registry
component.addPaths(registry.getPaths(component.getName()));
if (!container.isRegisteredByNamespace(
registryName,
component.getType()))
{
AndroMDALogger.info(" + registering component '" + componentName + "'");
final XmlObjectFactory componentFactory = XmlObjectFactory.getInstance(component.getType());
final URL componentResource =
this.getNamespaceResource(
registry.getResourceRoots(),
component.getPaths());
if (componentResource == null)
{
throw new NamespaceComponentsException("'" + componentName +
"' is not a valid component within namespace '" + namespace + "' (the " +
componentName + "'s descriptor can not be found)");
}
NamespaceComponent namespaceComponent =
(NamespaceComponent)componentFactory.getObject(componentResource);
// - now perform a merge of the descriptor (if we require one)
if (requiresMerge)
{
namespaceComponent =
(NamespaceComponent)componentFactory.getObject(
merger.getMergedString(
ResourceUtils.getContents(componentResource),
namespace));
}
namespaceComponent.setNamespace(registryName);