Search in sources :

Example 6 with NamespaceHandler

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;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Bundle(org.osgi.framework.Bundle) NamespaceHandler(org.apache.aries.blueprint.NamespaceHandler) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 7 with NamespaceHandler

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);
    }
}
Also used : HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) Properties(java.util.Properties) BeanFactory(org.springframework.beans.factory.BeanFactory) NamespaceHandler(org.apache.aries.blueprint.NamespaceHandler) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with NamespaceHandler

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;
}
Also used : SimpleNamespaceHandlerSet(org.apache.aries.blueprint.container.SimpleNamespaceHandlerSet) Namespaces(org.apache.aries.blueprint.Namespaces) NamespaceHandler(org.apache.aries.blueprint.NamespaceHandler) IOException(java.io.IOException)

Example 9 with NamespaceHandler

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);
}
Also used : NamespaceHandler(org.apache.aries.blueprint.NamespaceHandler)

Example 10 with NamespaceHandler

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;
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) NamespaceHandler(org.apache.aries.blueprint.NamespaceHandler) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

NamespaceHandler (org.apache.aries.blueprint.NamespaceHandler)20 URI (java.net.URI)6 IOException (java.io.IOException)4 Bundle (org.osgi.framework.Bundle)4 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)3 SAXException (org.xml.sax.SAXException)3 InputStream (java.io.InputStream)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 W3C_XML_SCHEMA_NS_URI (javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)2 XML_NS_URI (javax.xml.XMLConstants.XML_NS_URI)2 ParserContext (org.apache.aries.blueprint.ParserContext)2 SimpleNamespaceHandlerSet (org.apache.aries.blueprint.container.SimpleNamespaceHandlerSet)2