Search in sources :

Example 21 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 22 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 23 with MutableBeanMetadata

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

the class CamelNamespaceHandler method parseRestContextNode.

private Metadata parseRestContextNode(Element element, ParserContext context) {
    LOG.trace("Parsing RestContext {}", element);
    // now parse the rests with JAXB
    Binder<Node> binder;
    try {
        binder = getJaxbContext().createBinder();
    } catch (JAXBException e) {
        throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e);
    }
    Object value = parseUsingJaxb(element, context, binder);
    if (!(value instanceof CamelRestContextFactoryBean)) {
        throw new ComponentDefinitionException("Expected an instance of " + CamelRestContextFactoryBean.class);
    }
    CamelRestContextFactoryBean rcfb = (CamelRestContextFactoryBean) value;
    String id = rcfb.getId();
    MutablePassThroughMetadata factory = context.createMetadata(MutablePassThroughMetadata.class);
    factory.setId(".camelBlueprint.passThrough." + id);
    factory.setObject(new PassThroughCallable<Object>(rcfb));
    MutableBeanMetadata factory2 = context.createMetadata(MutableBeanMetadata.class);
    factory2.setId(".camelBlueprint.factory." + id);
    factory2.setFactoryComponent(factory);
    factory2.setFactoryMethod("call");
    MutableBeanMetadata ctx = context.createMetadata(MutableBeanMetadata.class);
    ctx.setId(id);
    ctx.setRuntimeClass(List.class);
    ctx.setFactoryComponent(factory2);
    ctx.setFactoryMethod("getRests");
    // must be lazy as we want CamelContext to be activated first
    ctx.setActivation(ACTIVATION_LAZY);
    // lets inject the namespaces into any namespace aware POJOs
    injectNamespaces(element, binder);
    LOG.trace("Parsing RestContext done, returning {}", element, ctx);
    return ctx;
}
Also used : MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) ExpressionNode(org.apache.camel.model.ExpressionNode) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) CamelRestContextFactoryBean(org.apache.camel.blueprint.CamelRestContextFactoryBean)

Example 24 with MutableBeanMetadata

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

the class CamelNamespaceHandler method parseKeyStoreParametersNode.

private Metadata parseKeyStoreParametersNode(Element element, ParserContext context) {
    LOG.trace("Parsing KeyStoreParameters {}", element);
    // now parse the key store parameters with JAXB
    Binder<Node> binder;
    try {
        binder = getJaxbContext().createBinder();
    } catch (JAXBException e) {
        throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e);
    }
    Object value = parseUsingJaxb(element, context, binder);
    if (!(value instanceof KeyStoreParametersFactoryBean)) {
        throw new ComponentDefinitionException("Expected an instance of " + KeyStoreParametersFactoryBean.class);
    }
    KeyStoreParametersFactoryBean kspfb = (KeyStoreParametersFactoryBean) value;
    String id = kspfb.getId();
    MutablePassThroughMetadata factory = context.createMetadata(MutablePassThroughMetadata.class);
    factory.setId(".camelBlueprint.passThrough." + id);
    factory.setObject(new PassThroughCallable<Object>(kspfb));
    MutableBeanMetadata factory2 = context.createMetadata(MutableBeanMetadata.class);
    factory2.setId(".camelBlueprint.factory." + id);
    factory2.setFactoryComponent(factory);
    factory2.setFactoryMethod("call");
    factory2.setInitMethod("afterPropertiesSet");
    factory2.setDestroyMethod("destroy");
    factory2.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    MutableBeanMetadata ctx = context.createMetadata(MutableBeanMetadata.class);
    ctx.setId(id);
    ctx.setRuntimeClass(KeyStoreParameters.class);
    ctx.setFactoryComponent(factory2);
    ctx.setFactoryMethod("getObject");
    // must be lazy as we want CamelContext to be activated first
    ctx.setActivation(ACTIVATION_LAZY);
    LOG.trace("Parsing KeyStoreParameters done, returning {}", ctx);
    return ctx;
}
Also used : MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) KeyStoreParametersFactoryBean(org.apache.camel.util.blueprint.KeyStoreParametersFactoryBean) ExpressionNode(org.apache.camel.model.ExpressionNode) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException)

Example 25 with MutableBeanMetadata

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

the class CamelNamespaceHandler method registerBean.

protected void registerBean(ParserContext context, String contextId, AbstractCamelFactoryBean<?> fact) {
    String id = fact.getId();
    fact.setCamelContextId(contextId);
    MutablePassThroughMetadata eff = context.createMetadata(MutablePassThroughMetadata.class);
    eff.setId(".camelBlueprint.bean.passthrough." + id);
    eff.setObject(new PassThroughCallable<Object>(fact));
    MutableBeanMetadata ef = context.createMetadata(MutableBeanMetadata.class);
    ef.setId(".camelBlueprint.bean.factory." + id);
    ef.setFactoryComponent(eff);
    ef.setFactoryMethod("call");
    ef.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    ef.setInitMethod("afterPropertiesSet");
    ef.setDestroyMethod("destroy");
    MutableBeanMetadata e = context.createMetadata(MutableBeanMetadata.class);
    e.setId(id);
    e.setRuntimeClass(fact.getObjectType());
    e.setFactoryComponent(ef);
    e.setFactoryMethod("getObject");
    e.addDependsOn(".camelBlueprint.processor.bean." + contextId);
    context.getComponentDefinitionRegistry().registerComponentDefinition(e);
}
Also used : MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata)

Aggregations

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