Search in sources :

Example 1 with Metadata

use of org.osgi.service.blueprint.reflect.Metadata 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 2 with Metadata

use of org.osgi.service.blueprint.reflect.Metadata in project camel by apache.

the class EndpointDefinitionParser method parse.

public Metadata parse(Element element, ParserContext context) {
    MutableBeanMetadata endpointConfig = createBeanMetadata(element, context, CxfBlueprintEndpoint.class);
    NamedNodeMap atts = element.getAttributes();
    String bus = null;
    String address = null;
    for (int i = 0; i < atts.getLength(); i++) {
        Attr node = (Attr) atts.item(i);
        String val = node.getValue();
        String pre = node.getPrefix();
        String name = node.getLocalName();
        if ("bus".equals(name)) {
            bus = val;
        } else if ("address".equals(name)) {
            address = val;
        } else if (isAttribute(pre, name)) {
            if ("endpointName".equals(name) || "serviceName".equals(name)) {
                if (isPlaceHolder(val)) {
                    endpointConfig.addProperty(name + "String", createValue(context, val));
                } else {
                    QName q = parseQName(element, val);
                    endpointConfig.addProperty(name, createValue(context, q));
                }
            } else if ("depends-on".equals(name)) {
                endpointConfig.addDependsOn(val);
            } else if (!"name".equals(name)) {
                endpointConfig.addProperty(name, createValue(context, val));
            }
        }
    }
    Element elem = DOMUtils.getFirstElement(element);
    while (elem != null) {
        String name = elem.getLocalName();
        if ("properties".equals(name)) {
            Metadata map = parseMapData(context, endpointConfig, elem);
            endpointConfig.addProperty(name, map);
        } else if ("binding".equals(name)) {
            setFirstChildAsProperty(elem, context, endpointConfig, "bindingConfig");
        } else if ("inInterceptors".equals(name) || "inFaultInterceptors".equals(name) || "outInterceptors".equals(name) || "outFaultInterceptors".equals(name) || "features".equals(name) || "schemaLocations".equals(name) || "handlers".equals(name)) {
            Metadata list = parseListData(context, endpointConfig, elem);
            endpointConfig.addProperty(name, list);
        } else {
            setFirstChildAsProperty(elem, context, endpointConfig, name);
        }
        elem = DOMUtils.getNextElement(elem);
    }
    if (StringUtils.isEmpty(bus)) {
        bus = "cxf";
    }
    //Will create a bus if needed...
    endpointConfig.addProperty("bus", getBusRef(context, bus));
    endpointConfig.setDestroyMethod("destroy");
    endpointConfig.addArgument(createValue(context, address), String.class.getName(), 0);
    endpointConfig.addArgument(createRef(context, "blueprintBundleContext"), BundleContext.class.getName(), 1);
    return endpointConfig;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) NamedNodeMap(org.w3c.dom.NamedNodeMap) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Metadata(org.osgi.service.blueprint.reflect.Metadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) CxfBlueprintEndpoint(org.apache.camel.component.cxf.CxfBlueprintEndpoint) Attr(org.w3c.dom.Attr) BundleContext(org.osgi.framework.BundleContext)

Example 3 with Metadata

use of org.osgi.service.blueprint.reflect.Metadata in project fabric8 by jboss-fuse.

the class DirectoryNamespaceHandler method parse.

@Override
public Metadata parse(Element element, ParserContext parserContext) {
    if (parserContext.getComponentDefinitionRegistry().getComponentDefinition("." + MyConverter.class.getName()) == null) {
        MutableBeanMetadata converter = parserContext.createMetadata(MutableBeanMetadata.class);
        converter.setId("." + MyConverter.class.getName());
        converter.setRuntimeClass(MyConverter.class);
        parserContext.getComponentDefinitionRegistry().registerTypeConverter(converter);
    }
    Metadata metadata = super.parse(element, parserContext);
    if (metadata instanceof MutableBeanMetadata) {
        MutableBeanMetadata bean = (MutableBeanMetadata) metadata;
        if (bean.getRuntimeClass() == ApacheDS.class) {
            bean.setInitMethod("startup");
            bean.setDestroyMethod("shutdown");
        }
    }
    return metadata;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata)

Example 4 with Metadata

use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.

the class BlueprintContainerImpl method getMetadata.

private <T extends ComponentMetadata> void getMetadata(Class<T> clazz, Metadata component, Collection<T> metadatas) {
    if (component == null) {
        return;
    }
    if (clazz.isInstance(component)) {
        metadatas.add(clazz.cast(component));
    }
    if (component instanceof BeanMetadata) {
        getMetadata(clazz, ((BeanMetadata) component).getFactoryComponent(), metadatas);
        for (BeanArgument arg : ((BeanMetadata) component).getArguments()) {
            getMetadata(clazz, arg.getValue(), metadatas);
        }
        for (BeanProperty prop : ((BeanMetadata) component).getProperties()) {
            getMetadata(clazz, prop.getValue(), metadatas);
        }
    }
    if (component instanceof CollectionMetadata) {
        for (Metadata m : ((CollectionMetadata) component).getValues()) {
            getMetadata(clazz, m, metadatas);
        }
    }
    if (component instanceof MapMetadata) {
        for (MapEntry m : ((MapMetadata) component).getEntries()) {
            getMetadata(clazz, m.getKey(), metadatas);
            getMetadata(clazz, m.getValue(), metadatas);
        }
    }
    if (component instanceof PropsMetadata) {
        for (MapEntry m : ((PropsMetadata) component).getEntries()) {
            getMetadata(clazz, m.getKey(), metadatas);
            getMetadata(clazz, m.getValue(), metadatas);
        }
    }
    if (component instanceof ServiceReferenceMetadata) {
        for (ReferenceListener l : ((ServiceReferenceMetadata) component).getReferenceListeners()) {
            getMetadata(clazz, l.getListenerComponent(), metadatas);
        }
    }
    if (component instanceof ServiceMetadata) {
        getMetadata(clazz, ((ServiceMetadata) component).getServiceComponent(), metadatas);
        for (MapEntry m : ((ServiceMetadata) component).getServiceProperties()) {
            getMetadata(clazz, m.getKey(), metadatas);
            getMetadata(clazz, m.getValue(), metadatas);
        }
        for (RegistrationListener l : ((ServiceMetadata) component).getRegistrationListeners()) {
            getMetadata(clazz, l.getListenerComponent(), metadatas);
        }
    }
}
Also used : BeanArgument(org.osgi.service.blueprint.reflect.BeanArgument) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) RegistrationListener(org.osgi.service.blueprint.reflect.RegistrationListener) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ReferenceListener(org.osgi.service.blueprint.reflect.ReferenceListener) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Example 5 with Metadata

use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.

the class NSHandlerFour method parse.

// process elements
public Metadata parse(Element element, ParserContext context) {
    Metadata retval = null;
    if (element.getLocalName().equals(ELT_NAME)) {
        final String id = element.getAttributeNS(NSURI, ATTRIB_ID);
        MutableBeanMetadata bm = context.createMetadata(MutableBeanMetadata.class);
        bm.setId(id);
        bm.setScope("PROTOTYPE");
        bm.setClassName(TestBean.class.getName());
        retval = bm;
    }
    return retval;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) MutableRefMetadata(org.apache.aries.blueprint.mutable.MutableRefMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata)

Aggregations

Metadata (org.osgi.service.blueprint.reflect.Metadata)46 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)35 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)32 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)27 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)26 MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)24 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)23 Element (org.w3c.dom.Element)20 ReferenceMetadata (org.osgi.service.blueprint.reflect.ReferenceMetadata)17 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)17 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)16 ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)16 MutableRefMetadata (org.apache.aries.blueprint.mutable.MutableRefMetadata)15 NonNullMetadata (org.osgi.service.blueprint.reflect.NonNullMetadata)15 NullMetadata (org.osgi.service.blueprint.reflect.NullMetadata)15 IdRefMetadata (org.osgi.service.blueprint.reflect.IdRefMetadata)12 ReferenceListMetadata (org.osgi.service.blueprint.reflect.ReferenceListMetadata)12 Node (org.w3c.dom.Node)12 NodeList (org.w3c.dom.NodeList)12 MutableMapMetadata (org.apache.aries.blueprint.mutable.MutableMapMetadata)11