Search in sources :

Example 1 with MutableCollectionMetadata

use of org.apache.aries.blueprint.mutable.MutableCollectionMetadata in project aries by apache.

the class CmNamespaceHandler method createList.

private static CollectionMetadata createList(ParserContext context, List<String> list) {
    MutableCollectionMetadata m = context.createMetadata(MutableCollectionMetadata.class);
    m.setCollectionClass(List.class);
    m.setValueType(String.class.getName());
    for (String v : list) {
        m.addValue(createValue(context, v, String.class.getName()));
    }
    return m;
}
Also used : MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata)

Example 2 with MutableCollectionMetadata

use of org.apache.aries.blueprint.mutable.MutableCollectionMetadata in project karaf by apache.

the class NamespaceHandler method createList.

private static CollectionMetadata createList(ParserContext context, List<String> list) {
    MutableCollectionMetadata m = context.createMetadata(MutableCollectionMetadata.class);
    m.setCollectionClass(List.class);
    m.setValueType(String.class.getName());
    for (String v : list) {
        m.addValue(createValue(context, v, String.class.getName()));
    }
    return m;
}
Also used : MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata)

Example 3 with MutableCollectionMetadata

use of org.apache.aries.blueprint.mutable.MutableCollectionMetadata in project karaf by apache.

the class NamespaceHandler method parseCompleters.

private Metadata parseCompleters(ParserContext context, ComponentMetadata enclosingComponent, Element element) {
    MutableCollectionMetadata collection = context.createMetadata(MutableCollectionMetadata.class);
    collection.setCollectionClass(List.class);
    NodeList children = element.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child instanceof Element) {
            Metadata metadata;
            if (nodeNameEquals(child, REF)) {
                metadata = context.parseElement(RefMetadata.class, context.getEnclosingComponent(), (Element) child);
            } else if (nodeNameEquals(child, NULL)) {
                metadata = context.parseElement(NullMetadata.class, context.getEnclosingComponent(), (Element) child);
            } else if (nodeNameEquals(child, BEAN)) {
                metadata = context.parseElement(BeanMetadata.class, enclosingComponent, (Element) child);
            } else {
                throw new IllegalStateException("Unexpected element " + child.getNodeName());
            }
            collection.addValue(metadata);
        }
    }
    return collection;
}
Also used : RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) MutableRefMetadata(org.apache.aries.blueprint.mutable.MutableRefMetadata) IdRefMetadata(org.osgi.service.blueprint.reflect.IdRefMetadata) MutableIdRefMetadata(org.apache.aries.blueprint.mutable.MutableIdRefMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) MutableRefMetadata(org.apache.aries.blueprint.mutable.MutableRefMetadata) IdRefMetadata(org.osgi.service.blueprint.reflect.IdRefMetadata) MutableIdRefMetadata(org.apache.aries.blueprint.mutable.MutableIdRefMetadata) MutableServiceMetadata(org.apache.aries.blueprint.mutable.MutableServiceMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) NullMetadata(org.osgi.service.blueprint.reflect.NullMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableValueMetadata(org.apache.aries.blueprint.mutable.MutableValueMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata)

Example 4 with MutableCollectionMetadata

use of org.apache.aries.blueprint.mutable.MutableCollectionMetadata in project aries by apache.

the class CmNamespaceHandler method parseManagedServiceFactory.

private ComponentMetadata parseManagedServiceFactory(ParserContext context, Element element) {
    String id = getId(context, element);
    MutableBeanMetadata factoryMetadata = context.createMetadata(MutableBeanMetadata.class);
    generateIdIfNeeded(context, factoryMetadata);
    factoryMetadata.addProperty("id", createValue(context, factoryMetadata.getId()));
    factoryMetadata.setScope(BeanMetadata.SCOPE_SINGLETON);
    factoryMetadata.setRuntimeClass(CmManagedServiceFactory.class);
    factoryMetadata.setInitMethod("init");
    factoryMetadata.setDestroyMethod("destroy");
    factoryMetadata.addArgument(createRef(context, "blueprintContainer"), null, 0);
    factoryMetadata.addProperty("factoryPid", createValue(context, element.getAttribute(FACTORY_PID_ATTRIBUTE)));
    String autoExport = element.hasAttribute(AUTO_EXPORT_ATTRIBUTE) ? element.getAttribute(AUTO_EXPORT_ATTRIBUTE) : AUTO_EXPORT_DEFAULT;
    if (AUTO_EXPORT_DISABLED.equals(autoExport)) {
        autoExport = Integer.toString(ServiceMetadata.AUTO_EXPORT_DISABLED);
    } else if (AUTO_EXPORT_INTERFACES.equals(autoExport)) {
        autoExport = Integer.toString(ServiceMetadata.AUTO_EXPORT_INTERFACES);
    } else if (AUTO_EXPORT_CLASS_HIERARCHY.equals(autoExport)) {
        autoExport = Integer.toString(ServiceMetadata.AUTO_EXPORT_CLASS_HIERARCHY);
    } else if (AUTO_EXPORT_ALL.equals(autoExport)) {
        autoExport = Integer.toString(ServiceMetadata.AUTO_EXPORT_ALL_CLASSES);
    } else {
        throw new ComponentDefinitionException("Illegal value (" + autoExport + ") for " + AUTO_EXPORT_ATTRIBUTE + " attribute");
    }
    factoryMetadata.addProperty("autoExport", createValue(context, autoExport));
    String ranking = element.hasAttribute(RANKING_ATTRIBUTE) ? element.getAttribute(RANKING_ATTRIBUTE) : RANKING_DEFAULT;
    factoryMetadata.addProperty("ranking", createValue(context, ranking));
    List<String> interfaces = null;
    if (element.hasAttribute(INTERFACE_ATTRIBUTE)) {
        interfaces = Collections.singletonList(element.getAttribute(INTERFACE_ATTRIBUTE));
        factoryMetadata.addProperty("interfaces", createList(context, interfaces));
    }
    // Parse elements
    List<RegistrationListener> listeners = new ArrayList<RegistrationListener>();
    NodeList nl = element.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node node = nl.item(i);
        if (node instanceof Element) {
            Element e = (Element) node;
            if (isBlueprintNamespace(e.getNamespaceURI())) {
                if (nodeNameEquals(e, INTERFACES_ELEMENT)) {
                    if (interfaces != null) {
                        throw new ComponentDefinitionException("Only one of " + INTERFACE_ATTRIBUTE + " attribute or " + INTERFACES_ELEMENT + " element must be used");
                    }
                    interfaces = parseInterfaceNames(e);
                    factoryMetadata.addProperty("interfaces", createList(context, interfaces));
                } else if (nodeNameEquals(e, SERVICE_PROPERTIES_ELEMENT)) {
                    MapMetadata map = context.parseElement(MapMetadata.class, factoryMetadata, e);
                    factoryMetadata.addProperty("serviceProperties", map);
                    NodeList enl = e.getChildNodes();
                    for (int j = 0; j < enl.getLength(); j++) {
                        Node enode = enl.item(j);
                        if (enode instanceof Element) {
                            if (isCmNamespace(enode.getNamespaceURI()) && nodeNameEquals(enode, CM_PROPERTIES_ELEMENT)) {
                                decorateCmProperties(context, (Element) enode, factoryMetadata);
                            }
                        }
                    }
                } else if (nodeNameEquals(e, REGISTRATION_LISTENER_ELEMENT)) {
                    listeners.add(context.parseElement(RegistrationListener.class, factoryMetadata, e));
                }
            } else if (isCmNamespace(e.getNamespaceURI())) {
                if (nodeNameEquals(e, MANAGED_COMPONENT_ELEMENT)) {
                    MutableBeanMetadata managedComponent = context.parseElement(MutableBeanMetadata.class, null, e);
                    generateIdIfNeeded(context, managedComponent);
                    managedComponent.setScope(BeanMetadata.SCOPE_PROTOTYPE);
                    // destroy-method on managed-component has different signature than on regular beans
                    // so we'll handle it differently
                    String destroyMethod = managedComponent.getDestroyMethod();
                    if (destroyMethod != null) {
                        factoryMetadata.addProperty("componentDestroyMethod", createValue(context, destroyMethod));
                        managedComponent.setDestroyMethod(null);
                    }
                    context.getComponentDefinitionRegistry().registerComponentDefinition(managedComponent);
                    factoryMetadata.addProperty("managedComponentName", createIdRef(context, managedComponent.getId()));
                }
            }
        }
    }
    MutableCollectionMetadata listenerCollection = context.createMetadata(MutableCollectionMetadata.class);
    listenerCollection.setCollectionClass(List.class);
    for (RegistrationListener listener : listeners) {
        MutableBeanMetadata bean = context.createMetadata(MutableBeanMetadata.class);
        bean.setRuntimeClass(ServiceListener.class);
        bean.addProperty("listener", listener.getListenerComponent());
        bean.addProperty("registerMethod", createValue(context, listener.getRegistrationMethod()));
        bean.addProperty("unregisterMethod", createValue(context, listener.getUnregistrationMethod()));
        listenerCollection.addValue(bean);
    }
    factoryMetadata.addProperty("listeners", listenerCollection);
    context.getComponentDefinitionRegistry().registerComponentDefinition(factoryMetadata);
    MutableBeanMetadata mapMetadata = context.createMetadata(MutableBeanMetadata.class);
    mapMetadata.setScope(BeanMetadata.SCOPE_SINGLETON);
    mapMetadata.setId(id);
    mapMetadata.setFactoryComponent(createRef(context, factoryMetadata.getId()));
    mapMetadata.setFactoryMethod("getServiceMap");
    return mapMetadata;
}
Also used : RegistrationListener(org.osgi.service.blueprint.reflect.RegistrationListener) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata)

Example 5 with MutableCollectionMetadata

use of org.apache.aries.blueprint.mutable.MutableCollectionMetadata in project aries by apache.

the class ExtNamespaceHandler method createList.

private static CollectionMetadata createList(ParserContext context, List<String> list) {
    MutableCollectionMetadata m = context.createMetadata(MutableCollectionMetadata.class);
    m.setCollectionClass(List.class);
    m.setValueType(String.class.getName());
    for (String v : list) {
        m.addValue(createValue(context, v, String.class.getName()));
    }
    return m;
}
Also used : MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata)

Aggregations

MutableCollectionMetadata (org.apache.aries.blueprint.mutable.MutableCollectionMetadata)7 MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)4 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)3 Element (org.w3c.dom.Element)3 NodeList (org.w3c.dom.NodeList)3 ArrayList (java.util.ArrayList)2 PassThroughMetadata (org.apache.aries.blueprint.PassThroughMetadata)2 MutableMapMetadata (org.apache.aries.blueprint.mutable.MutableMapMetadata)2 MutableServiceMetadata (org.apache.aries.blueprint.mutable.MutableServiceMetadata)2 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)2 Metadata (org.osgi.service.blueprint.reflect.Metadata)2 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)2 Node (org.w3c.dom.Node)2 MutableIdRefMetadata (org.apache.aries.blueprint.mutable.MutableIdRefMetadata)1 MutablePassThroughMetadata (org.apache.aries.blueprint.mutable.MutablePassThroughMetadata)1 MutablePropsMetadata (org.apache.aries.blueprint.mutable.MutablePropsMetadata)1 MutableRefMetadata (org.apache.aries.blueprint.mutable.MutableRefMetadata)1 MutableValueMetadata (org.apache.aries.blueprint.mutable.MutableValueMetadata)1 JaasRealm (org.apache.karaf.jaas.config.JaasRealm)1 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)1