use of org.apache.aries.blueprint.NamespaceHandler in project aries by apache.
the class NamespaceHandlerRegistryImpl method addingService.
public Object addingService(ServiceReference reference) {
LOGGER.debug("Adding NamespaceHandler " + reference.toString());
NamespaceHandler handler = (NamespaceHandler) bundleContext.getService(reference);
if (handler != null) {
try {
Map<String, Object> props = new HashMap<String, Object>();
for (String name : reference.getPropertyKeys()) {
props.put(name, reference.getProperty(name));
}
registerHandler(handler, props);
} catch (Exception e) {
LOGGER.warn("Error registering NamespaceHandler", e);
}
} else {
Bundle bundle = reference.getBundle();
// so do nothing in that case
if (bundle != null) {
LOGGER.warn("Error resolving NamespaceHandler, null Service obtained from tracked ServiceReference {} for bundle {}/{}", reference.toString(), reference.getBundle().getSymbolicName(), reference.getBundle().getVersion());
}
}
return handler;
}
use of org.apache.aries.blueprint.NamespaceHandler in project aries by apache.
the class SpringExtension method start.
@Override
public void start() throws Exception {
Map<String, NamespaceHandler> handlers = new HashMap<String, NamespaceHandler>();
Properties props = loadSpringHandlers();
Properties schemas = loadSpringSchemas();
for (String key : props.stringPropertyNames()) {
String clazzName = props.getProperty(key);
org.springframework.beans.factory.xml.NamespaceHandler springHandler = (org.springframework.beans.factory.xml.NamespaceHandler) bundle.loadClass(clazzName).newInstance();
NamespaceHandler wrapper = new BlueprintNamespaceHandler(bundle, schemas, springHandler);
handlers.put(key, wrapper);
}
if (bundle == FrameworkUtil.getBundle(BeanFactory.class)) {
org.springframework.beans.factory.xml.NamespaceHandler springHandler = new BeansNamespaceHandler();
NamespaceHandler wrapper = new BlueprintNamespaceHandler(bundle, schemas, springHandler);
handlers.put(BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI, wrapper);
}
for (Map.Entry<String, NamespaceHandler> entry : handlers.entrySet()) {
Hashtable<String, String> svcProps = new Hashtable<String, String>();
svcProps.put("osgi.service.blueprint.namespace", entry.getKey());
ServiceRegistration<NamespaceHandler> reg = bundle.getBundleContext().registerService(NamespaceHandler.class, entry.getValue(), svcProps);
registrations.add(reg);
}
}
use of org.apache.aries.blueprint.NamespaceHandler in project aries by apache.
the class BlueprintContextListener method getNamespaceHandlerSetFromClassNames.
protected NamespaceHandlerSet getNamespaceHandlerSetFromClassNames(ServletContext servletContext, ClassLoader tccl, List<String> handlerClassNames) {
SimpleNamespaceHandlerSet nsSet = new SimpleNamespaceHandlerSet();
for (String name : handlerClassNames) {
String trimmedName = name.trim();
Object instance = null;
try {
instance = tccl.loadClass(trimmedName).newInstance();
} catch (Exception ex) {
throw new RuntimeException("Failed to load NamespaceHandler: " + trimmedName, ex);
}
if (!(instance instanceof NamespaceHandler)) {
throw new RuntimeException("Invalid NamespaceHandler: " + trimmedName);
}
NamespaceHandler nsHandler = (NamespaceHandler) instance;
Namespaces namespaces = nsHandler.getClass().getAnnotation(Namespaces.class);
if (namespaces != null) {
for (String ns : namespaces.value()) {
nsSet.addNamespace(URI.create(ns), nsHandler.getSchemaLocation(ns), nsHandler);
}
}
}
return nsSet;
}
use of org.apache.aries.blueprint.NamespaceHandler in project aries by apache.
the class Parser method decorateCustomNode.
private ComponentMetadata decorateCustomNode(Node node, ComponentMetadata enclosingComponent) {
NamespaceHandler handler = getNamespaceHandler(node);
ParserContextImpl context = new ParserContextImpl(this, registry, enclosingComponent, node);
return handler.decorate(node, enclosingComponent, context);
}
use of org.apache.aries.blueprint.NamespaceHandler in project opennms by OpenNMS.
the class BlueprintNamespaceShellCommand method doExecute.
@Override
protected Object doExecute() throws Exception {
final Collection<ServiceReference<NamespaceHandler>> services = this.bundleContext.getServiceReferences(NamespaceHandler.class, null);
for (final ServiceReference<NamespaceHandler> sr : services) {
final Bundle bundle = sr.getBundle();
final Object rawNamespaces = sr.getProperty("osgi.service.blueprint.namespace");
final ArrayList<String> namespaces = new ArrayList<String>();
if (rawNamespaces instanceof String) {
namespaces.add((String) rawNamespaces);
} else if (rawNamespaces instanceof Object[]) {
for (final Object namespace : (Object[]) rawNamespaces) {
namespaces.add(namespace.toString());
}
} else if (rawNamespaces instanceof String[]) {
for (final String namespace : (String[]) rawNamespaces) {
namespaces.add(namespace);
}
} else {
System.err.println("Hmm, not sure how to interpret: " + rawNamespaces);
}
System.out.println(bundle.toString());
for (final Object namespace : namespaces) {
System.out.println(" " + namespace);
}
System.out.println();
}
return null;
}
Aggregations