Search in sources :

Example 6 with MutableBeanMetadata

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

the class CamelNamespaceHandler method parseCamelContextNode.

private Metadata parseCamelContextNode(Element element, ParserContext context) {
    LOG.trace("Parsing CamelContext {}", element);
    // Find the id, generate one if needed
    String contextId = element.getAttribute("id");
    boolean implicitId = false;
    // let's avoid folks having to explicitly give an ID to a camel context
    if (ObjectHelper.isEmpty(contextId)) {
        // if no explicit id was set then use a default auto generated name
        CamelContextNameStrategy strategy = new DefaultCamelContextNameStrategy();
        contextId = strategy.getName();
        element.setAttributeNS(null, "id", contextId);
        implicitId = true;
    }
    // now let's parse the routes 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 CamelContextFactoryBean)) {
        throw new ComponentDefinitionException("Expected an instance of " + CamelContextFactoryBean.class);
    }
    CamelContextFactoryBean ccfb = (CamelContextFactoryBean) value;
    ccfb.setImplicitId(implicitId);
    // The properties component is always used / created by the CamelContextFactoryBean
    // so we need to ensure that the resolver is ready to use
    ComponentMetadata propertiesComponentResolver = getComponentResolverReference(context, "properties");
    MutablePassThroughMetadata factory = context.createMetadata(MutablePassThroughMetadata.class);
    factory.setId(".camelBlueprint.passThrough." + contextId);
    factory.setObject(new PassThroughCallable<Object>(value));
    MutableBeanMetadata factory2 = context.createMetadata(MutableBeanMetadata.class);
    factory2.setId(".camelBlueprint.factory." + contextId);
    factory2.setFactoryComponent(factory);
    factory2.setFactoryMethod("call");
    factory2.setInitMethod("afterPropertiesSet");
    factory2.setDestroyMethod("destroy");
    factory2.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    factory2.addProperty("bundleContext", createRef(context, "blueprintBundleContext"));
    factory2.addDependsOn(propertiesComponentResolver.getId());
    // We need to add other components which the camel context dependsOn
    if (ObjectHelper.isNotEmpty(ccfb.getDependsOn())) {
        factory2.setDependsOn(Arrays.asList(ccfb.getDependsOn().split(" |,")));
    }
    context.getComponentDefinitionRegistry().registerComponentDefinition(factory2);
    MutableBeanMetadata ctx = context.createMetadata(MutableBeanMetadata.class);
    ctx.setId(contextId);
    ctx.setRuntimeClass(BlueprintCamelContext.class);
    ctx.setFactoryComponent(factory2);
    ctx.setFactoryMethod("getContext");
    ctx.setInitMethod("init");
    ctx.setDestroyMethod("destroy");
    // Register factory beans
    registerBeans(context, contextId, ccfb.getThreadPools());
    registerBeans(context, contextId, ccfb.getEndpoints());
    registerBeans(context, contextId, ccfb.getRedeliveryPolicies());
    registerBeans(context, contextId, ccfb.getBeansFactory());
    // Register processors
    MutablePassThroughMetadata beanProcessorFactory = context.createMetadata(MutablePassThroughMetadata.class);
    beanProcessorFactory.setId(".camelBlueprint.processor.bean.passThrough." + contextId);
    beanProcessorFactory.setObject(new PassThroughCallable<Object>(new CamelInjector(contextId)));
    MutableBeanMetadata beanProcessor = context.createMetadata(MutableBeanMetadata.class);
    beanProcessor.setId(".camelBlueprint.processor.bean." + contextId);
    beanProcessor.setRuntimeClass(CamelInjector.class);
    beanProcessor.setFactoryComponent(beanProcessorFactory);
    beanProcessor.setFactoryMethod("call");
    beanProcessor.setProcessor(true);
    beanProcessor.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    context.getComponentDefinitionRegistry().registerComponentDefinition(beanProcessor);
    MutablePassThroughMetadata regProcessorFactory = context.createMetadata(MutablePassThroughMetadata.class);
    regProcessorFactory.setId(".camelBlueprint.processor.registry.passThrough." + contextId);
    regProcessorFactory.setObject(new PassThroughCallable<Object>(new CamelDependenciesFinder(contextId, context)));
    MutableBeanMetadata regProcessor = context.createMetadata(MutableBeanMetadata.class);
    regProcessor.setId(".camelBlueprint.processor.registry." + contextId);
    regProcessor.setRuntimeClass(CamelDependenciesFinder.class);
    regProcessor.setFactoryComponent(regProcessorFactory);
    regProcessor.setFactoryMethod("call");
    regProcessor.setProcessor(true);
    regProcessor.addDependsOn(".camelBlueprint.processor.bean." + contextId);
    regProcessor.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    context.getComponentDefinitionRegistry().registerComponentDefinition(regProcessor);
    // lets inject the namespaces into any namespace aware POJOs
    injectNamespaces(element, binder);
    LOG.trace("Parsing CamelContext done, returning {}", ctx);
    return ctx;
}
Also used : MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) ExpressionNode(org.apache.camel.model.ExpressionNode) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) DefaultCamelContextNameStrategy(org.apache.camel.impl.DefaultCamelContextNameStrategy) CamelContextNameStrategy(org.apache.camel.spi.CamelContextNameStrategy) DefaultCamelContextNameStrategy(org.apache.camel.impl.DefaultCamelContextNameStrategy) CamelContextFactoryBean(org.apache.camel.blueprint.CamelContextFactoryBean)

Example 7 with MutableBeanMetadata

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

the class Aries1503bNamespaceHandler method parse.

@Override
public Metadata parse(Element element, ParserContext context) {
    MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
    metadata.setProcessor(true);
    metadata.setId("aries-1503");
    metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
    metadata.addArgument(new PassThroughMetadata() {

        @Override
        public Object getObject() {
            return "ARIES-1503";
        }

        @Override
        public String getId() {
            return "aries-1503-arg";
        }

        @Override
        public int getActivation() {
            return 0;
        }

        @Override
        public List<String> getDependsOn() {
            return null;
        }
    }, null, 0);
    metadata.setRuntimeClass(String.class);
    return metadata;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) List(java.util.List)

Example 8 with MutableBeanMetadata

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

the class Aries1682NamespaceHandler method parse.

@Override
public Metadata parse(Element element, ParserContext context) {
    MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
    metadata.setProcessor(true);
    metadata.setId("aries-1682");
    metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
    metadata.addArgument(new PassThroughMetadata() {

        @Override
        public Object getObject() {
            return "ARIES-1682";
        }

        @Override
        public String getId() {
            return "aries-1682-arg";
        }

        @Override
        public int getActivation() {
            return 0;
        }

        @Override
        public List<String> getDependsOn() {
            return null;
        }
    }, null, 0);
    metadata.setRuntimeClass(String.class);
    return metadata;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) List(java.util.List)

Example 9 with MutableBeanMetadata

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

the class NSHandlerFive 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)

Example 10 with MutableBeanMetadata

use of org.apache.aries.blueprint.mutable.MutableBeanMetadata 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

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