Search in sources :

Example 36 with MutableBeanMetadata

use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project camel by apache.

the class AbstractBeanDefinitionParser method createBeanMetadata.

public MutableBeanMetadata createBeanMetadata(Element element, ParserContext context, Class<?> runtimeClass) {
    MutableBeanMetadata answer = context.createMetadata(MutableBeanMetadata.class);
    answer.setRuntimeClass(runtimeClass);
    answer.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    answer.addProperty("bundleContext", createRef(context, "blueprintBundleContext"));
    // set the Bean scope to be prototype, so we can get a new instance per looking up
    answer.setScope(BeanMetadata.SCOPE_PROTOTYPE);
    if (!StringUtils.isEmpty(getIdOrName(element))) {
        answer.setId(getIdOrName(element));
    } else {
        // TODO we may need to throw exception for it
        answer.setId("camel.cxf.endpoint." + runtimeClass.getSimpleName() + "." + context.generateId());
    }
    return answer;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata)

Example 37 with MutableBeanMetadata

use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project camel by apache.

the class RsClientDefinitionParser method parse.

public Metadata parse(Element element, ParserContext context) {
    MutableBeanMetadata beanMetadata = createBeanMetadata(element, context, RsClientBlueprintBean.class);
    NamedNodeMap atts = element.getAttributes();
    String bus = 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 (isAttribute(pre, name)) {
            if ("depends-on".equals(name)) {
                beanMetadata.addDependsOn(val);
            } else if (!"name".equals(name)) {
                beanMetadata.addProperty(name, AbstractBPBeanDefinitionParser.createValue(context, val));
            }
        }
    }
    for (Element elem = DOMUtils.getFirstElement(element); elem != null; elem = DOMUtils.getNextElement(elem)) {
        String name = elem.getLocalName();
        if ("properties".equals(name) || "headers".equals(name)) {
            Metadata map = parseMapData(context, beanMetadata, elem);
            beanMetadata.addProperty(name, map);
        } else if ("binding".equals(name)) {
            setFirstChildAsProperty(elem, context, beanMetadata, "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, beanMetadata, elem);
            beanMetadata.addProperty(name, list);
        } else if ("features".equals(name) || "providers".equals(name) || "schemaLocations".equals(name) || "modelBeans".equals(name)) {
            Metadata list = parseListData(context, beanMetadata, elem);
            beanMetadata.addProperty(name, list);
        } else if ("model".equals(name)) {
            List<UserResource> resources = ResourceUtils.getResourcesFromElement(elem);
            MutablePassThroughMetadata value = context.createMetadata(MutablePassThroughMetadata.class);
            value.setObject(resources);
            beanMetadata.addProperty(name, value);
        } else {
            setFirstChildAsProperty(elem, context, beanMetadata, name);
        }
    }
    if (StringUtils.isEmpty(bus)) {
        bus = "cxf";
    }
    //Will create a bus if needed...
    beanMetadata.addProperty("bus", getBusRef(context, bus));
    return beanMetadata;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) NamedNodeMap(org.w3c.dom.NamedNodeMap) Element(org.w3c.dom.Element) Metadata(org.osgi.service.blueprint.reflect.Metadata) MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) UserResource(org.apache.cxf.jaxrs.model.UserResource) Attr(org.w3c.dom.Attr)

Example 38 with MutableBeanMetadata

use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project camel by apache.

the class RsServerDefinitionParser method parse.

public Metadata parse(Element element, ParserContext context) {
    MutableBeanMetadata beanMetadata = createBeanMetadata(element, context, RsServerBlueprintBean.class);
    NamedNodeMap atts = element.getAttributes();
    String bus = 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 (isAttribute(pre, name)) {
            if ("depends-on".equals(name)) {
                beanMetadata.addDependsOn(val);
            } else if (!"name".equals(name)) {
                beanMetadata.addProperty(name, AbstractBPBeanDefinitionParser.createValue(context, val));
            }
        }
    }
    for (Element elem = DOMUtils.getFirstElement(element); elem != null; elem = DOMUtils.getNextElement(elem)) {
        String name = elem.getLocalName();
        if ("properties".equals(name) || "extensionMappings".equals(name) || "languageMappings".equals(name)) {
            Metadata map = parseMapData(context, beanMetadata, elem);
            beanMetadata.addProperty(name, map);
        } else if ("binding".equals(name)) {
            setFirstChildAsProperty(elem, context, beanMetadata, "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, beanMetadata, elem);
            beanMetadata.addProperty(name, list);
        } else if ("features".equals(name) || "providers".equals(name) || "schemaLocations".equals(name) || "modelBeans".equals(name) || "serviceBeans".equals(name)) {
            Metadata list = parseListData(context, beanMetadata, elem);
            beanMetadata.addProperty(name, list);
        } else if ("model".equals(name)) {
            List<UserResource> resources = ResourceUtils.getResourcesFromElement(elem);
            MutablePassThroughMetadata value = context.createMetadata(MutablePassThroughMetadata.class);
            value.setObject(resources);
            beanMetadata.addProperty(name, value);
        } else {
            setFirstChildAsProperty(elem, context, beanMetadata, name);
        }
    }
    if (StringUtils.isEmpty(bus)) {
        bus = "cxf";
    }
    //Will create a bus if needed...
    beanMetadata.addProperty("bus", getBusRef(context, bus));
    return beanMetadata;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) NamedNodeMap(org.w3c.dom.NamedNodeMap) Element(org.w3c.dom.Element) Metadata(org.osgi.service.blueprint.reflect.Metadata) MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) UserResource(org.apache.cxf.jaxrs.model.UserResource) Attr(org.w3c.dom.Attr)

Example 39 with MutableBeanMetadata

use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project camel by apache.

the class AbstractBeanDefinitionParser method parse.

public Metadata parse(Element element, ParserContext context, Class<?> runtime) {
    MutableBeanMetadata config = createBeanMetadata(element, context, runtime);
    config.setScope(BeanMetadata.SCOPE_PROTOTYPE);
    String camelContextId = "camelContext";
    NamedNodeMap atts = element.getAttributes();
    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 ("camelContextId".equals(name)) {
            camelContextId = val;
        }
    }
    config.addDependsOn(camelContextId);
    config.addProperty("camelContext", createRef(context, camelContextId));
    return config;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) NamedNodeMap(org.w3c.dom.NamedNodeMap) Attr(org.w3c.dom.Attr)

Example 40 with MutableBeanMetadata

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

the class NamespaceHandler method parseKeystore.

public ComponentMetadata parseKeystore(Element element, ParserContext context) {
    MutableBeanMetadata bean = context.createMetadata(MutableBeanMetadata.class);
    bean.setRuntimeClass(ResourceKeystoreInstance.class);
    // Parse name
    String name = element.getAttribute("name");
    bean.addProperty("name", createValue(context, name));
    // Parse rank
    String rank = element.getAttribute("rank");
    if (rank != null && rank.length() > 0) {
        bean.addProperty("rank", createValue(context, rank));
    }
    // Parse path
    String path = element.getAttribute("path");
    if (path != null && path.length() > 0) {
        bean.addProperty("path", createValue(context, path));
    }
    // Parse keystorePassword
    String keystorePassword = element.getAttribute("keystorePassword");
    if (keystorePassword != null && keystorePassword.length() > 0) {
        bean.addProperty("keystorePassword", createValue(context, keystorePassword));
    }
    // Parse keyPasswords
    String keyPasswords = element.getAttribute("keyPasswords");
    if (keyPasswords != null && keyPasswords.length() > 0) {
        bean.addProperty("keyPasswords", createValue(context, keyPasswords));
    }
    // Publish Config
    MutableServiceMetadata service = context.createMetadata(MutableServiceMetadata.class);
    service.setId(name);
    service.setServiceComponent(bean);
    service.addInterface(KeystoreInstance.class.getName());
    return service;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableServiceMetadata(org.apache.aries.blueprint.mutable.MutableServiceMetadata) KeystoreInstance(org.apache.karaf.jaas.config.KeystoreInstance) ResourceKeystoreInstance(org.apache.karaf.jaas.config.impl.ResourceKeystoreInstance)

Aggregations

MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)68 MutablePassThroughMetadata (org.apache.aries.blueprint.mutable.MutablePassThroughMetadata)17 Element (org.w3c.dom.Element)17 Node (org.w3c.dom.Node)14 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)12 Metadata (org.osgi.service.blueprint.reflect.Metadata)11 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)10 PassThroughMetadata (org.apache.aries.blueprint.PassThroughMetadata)9 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)9 JAXBException (javax.xml.bind.JAXBException)8 MutableCollectionMetadata (org.apache.aries.blueprint.mutable.MutableCollectionMetadata)7 MutableRefMetadata (org.apache.aries.blueprint.mutable.MutableRefMetadata)7 ExpressionNode (org.apache.camel.model.ExpressionNode)7 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)7 Attr (org.w3c.dom.Attr)7 NamedNodeMap (org.w3c.dom.NamedNodeMap)6 NodeList (org.w3c.dom.NodeList)6 List (java.util.List)5 QName (javax.xml.namespace.QName)5 ComponentDefinitionRegistry (org.apache.aries.blueprint.ComponentDefinitionRegistry)4