Search in sources :

Example 6 with MutableCollectionMetadata

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

the class AbstractPropertyPlaceholder method processCollectionMetadata.

protected Metadata processCollectionMetadata(CollectionMetadata metadata) {
    List<Metadata> values = new ArrayList<Metadata>(metadata.getValues());
    if (!!!values.isEmpty()) {
        try {
            if (metadata instanceof MutableCollectionMetadata) {
                processingStack.add("Collection type: " + metadata.getValueType() + "->");
                MutableCollectionMetadata mcm = (MutableCollectionMetadata) metadata;
                for (Metadata value : values) {
                    mcm.removeValue(value);
                }
                for (Metadata value : values) {
                    mcm.addValue(processMetadata(value));
                }
            } else {
                printWarning(metadata, "Collection type: " + metadata.getValueType());
                processingStack.add("Collection type: " + metadata.getValueType() + "->");
                for (Metadata value : values) {
                    processMetadata(value);
                }
            }
        } finally {
            processingStack.removeLast();
        }
    }
    return metadata;
}
Also used : ArrayList(java.util.ArrayList) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) MutablePropsMetadata(org.apache.aries.blueprint.mutable.MutablePropsMetadata) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) NonNullMetadata(org.osgi.service.blueprint.reflect.NonNullMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata)

Example 7 with MutableCollectionMetadata

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

the class NamespaceHandler method parseConfig.

public ComponentMetadata parseConfig(Element element, ParserContext context) {
    MutableBeanMetadata bean = context.createMetadata(MutableBeanMetadata.class);
    bean.setRuntimeClass(Config.class);
    String name = element.getAttribute("name");
    bean.addProperty("bundleContext", createRef(context, "blueprintBundleContext"));
    bean.addProperty("name", createValue(context, name));
    String rank = element.getAttribute("rank");
    if (rank != null && rank.length() > 0) {
        bean.addProperty("rank", createValue(context, rank));
    }
    NodeList childElements = element.getElementsByTagNameNS(element.getNamespaceURI(), "module");
    if (childElements != null && childElements.getLength() > 0) {
        MutableCollectionMetadata children = context.createMetadata(MutableCollectionMetadata.class);
        for (int i = 0; i < childElements.getLength(); ++i) {
            Element childElement = (Element) childElements.item(i);
            MutableBeanMetadata md = context.createMetadata(MutableBeanMetadata.class);
            md.setRuntimeClass(Module.class);
            md.addProperty("className", createValue(context, childElement.getAttribute("className")));
            if (childElement.getAttribute("name") != null) {
                md.addProperty("name", createValue(context, childElement.getAttribute("name")));
            }
            if (childElement.getAttribute("flags") != null) {
                md.addProperty("flags", createValue(context, childElement.getAttribute("flags")));
            }
            String options = getTextValue(childElement);
            if (options != null && options.length() > 0) {
                md.addProperty("options", createValue(context, options));
            }
            children.addValue(md);
        }
        bean.addProperty("modules", children);
    }
    // Publish Config
    MutableServiceMetadata service = context.createMetadata(MutableServiceMetadata.class);
    service.setId(name);
    service.setServiceComponent(bean);
    service.addInterface(JaasRealm.class.getName());
    service.addServiceProperty(createValue(context, ProxyLoginModule.PROPERTY_MODULE), createValue(context, name));
    return service;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) JaasRealm(org.apache.karaf.jaas.config.JaasRealm) MutableServiceMetadata(org.apache.aries.blueprint.mutable.MutableServiceMetadata) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) 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