Search in sources :

Example 16 with MutablePassThroughMetadata

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

the class CamelNamespaceHandler method parseRouteContextNode.

private Metadata parseRouteContextNode(Element element, ParserContext context) {
    LOG.trace("Parsing RouteContext {}", element);
    // now 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 CamelRouteContextFactoryBean)) {
        throw new ComponentDefinitionException("Expected an instance of " + CamelRouteContextFactoryBean.class);
    }
    CamelRouteContextFactoryBean rcfb = (CamelRouteContextFactoryBean) 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("getRoutes");
    // 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 RouteContext 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) CamelRouteContextFactoryBean(org.apache.camel.blueprint.CamelRouteContextFactoryBean) ExpressionNode(org.apache.camel.model.ExpressionNode) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException)

Example 17 with MutablePassThroughMetadata

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

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

use of org.apache.aries.blueprint.mutable.MutablePassThroughMetadata in project cxf by apache.

the class AbstractBPBeanDefinitionParser method getBus.

protected MutableBeanMetadata getBus(ParserContext context, String name) {
    ComponentDefinitionRegistry cdr = context.getComponentDefinitionRegistry();
    ComponentMetadata meta = cdr.getComponentDefinition("blueprintBundle");
    if (!cdr.containsComponentDefinition(InterceptorTypeConverter.class.getName())) {
        MutablePassThroughMetadata md = context.createMetadata(MutablePassThroughMetadata.class);
        md.setObject(new InterceptorTypeConverter());
        md.setId(InterceptorTypeConverter.class.getName());
        context.getComponentDefinitionRegistry().registerTypeConverter(md);
    }
    if (!cdr.containsComponentDefinition(name)) {
        // Create a bus
        MutableBeanMetadata bus = context.createMetadata(MutableBeanMetadata.class);
        bus.setId(name);
        bus.setRuntimeClass(BlueprintBus.class);
        if (meta != null) {
            // blueprint-no-osgi does not provide a bundleContext
            bus.addProperty("bundleContext", createRef(context, "blueprintBundleContext"));
        }
        bus.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
        bus.setDestroyMethod("shutdown");
        bus.setInitMethod("initialize");
        context.getComponentDefinitionRegistry().registerComponentDefinition(bus);
        return bus;
    }
    return (MutableBeanMetadata) cdr.getComponentDefinition(name);
}
Also used : MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata)

Example 20 with MutablePassThroughMetadata

use of org.apache.aries.blueprint.mutable.MutablePassThroughMetadata in project cxf by apache.

the class JAXRSServerFactoryBeanDefinitionParser method mapElement.

@Override
protected void mapElement(ParserContext ctx, MutableBeanMetadata bean, Element el, String name) {
    if ("properties".equals(name) || "extensionMappings".equals(name) || "languageMappings".equals(name)) {
        bean.addProperty(name, this.parseMapData(ctx, bean, el));
    } else if ("executor".equals(name)) {
        setFirstChildAsProperty(el, ctx, bean, "serviceFactory.executor");
    } else if ("invoker".equals(name)) {
        setFirstChildAsProperty(el, ctx, bean, "serviceFactory.invoker");
    } else if ("binding".equals(name)) {
        setFirstChildAsProperty(el, ctx, bean, "bindingConfig");
    } else if ("inInterceptors".equals(name) || "inFaultInterceptors".equals(name) || "outInterceptors".equals(name) || "outFaultInterceptors".equals(name)) {
        bean.addProperty(name, this.parseListData(ctx, bean, el));
    } else if ("features".equals(name) || "schemaLocations".equals(name) || "providers".equals(name) || "serviceBeans".equals(name) || "modelBeans".equals(name)) {
        bean.addProperty(name, this.parseListData(ctx, bean, el));
    } else if ("serviceFactories".equals(name)) {
        bean.addProperty("resourceProviders", this.parseListData(ctx, bean, el));
    } else if ("resourceClasses".equals(name)) {
        List<String> resources = getResourceClassesFromElement(el);
        MutableCollectionMetadata list = ctx.createMetadata(MutableCollectionMetadata.class);
        list.setCollectionClass(List.class);
        for (String res : resources) {
            MutableBeanMetadata objectOfClass = createObjectOfClass(ctx, res);
            list.addValue(objectOfClass);
        }
        bean.addProperty("serviceBeans", list);
    } else if ("model".equals(name)) {
        List<UserResource> resources = ResourceUtils.getResourcesFromElement(el);
        MutableCollectionMetadata list = ctx.createMetadata(MutableCollectionMetadata.class);
        list.setCollectionClass(List.class);
        for (UserResource res : resources) {
            MutablePassThroughMetadata factory = ctx.createMetadata(MutablePassThroughMetadata.class);
            factory.setObject(new PassThroughCallable<Object>(res));
            MutableBeanMetadata resourceBean = ctx.createMetadata(MutableBeanMetadata.class);
            resourceBean.setFactoryComponent(factory);
            resourceBean.setFactoryMethod("call");
            list.addValue(resourceBean);
        }
        bean.addProperty("modelBeans", list);
    } else {
        setFirstChildAsProperty(el, ctx, bean, name);
    }
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) UserResource(org.apache.cxf.jaxrs.model.UserResource) ArrayList(java.util.ArrayList) List(java.util.List) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata)

Aggregations

MutablePassThroughMetadata (org.apache.aries.blueprint.mutable.MutablePassThroughMetadata)24 MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)17 JAXBException (javax.xml.bind.JAXBException)8 ExpressionNode (org.apache.camel.model.ExpressionNode)7 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)7 Node (org.w3c.dom.Node)7 UserResource (org.apache.cxf.jaxrs.model.UserResource)3 Attr (org.w3c.dom.Attr)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 MutableCollectionMetadata (org.apache.aries.blueprint.mutable.MutableCollectionMetadata)2 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)2 Metadata (org.osgi.service.blueprint.reflect.Metadata)2 Element (org.w3c.dom.Element)2 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 JAXBElement (javax.xml.bind.JAXBElement)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 QName (javax.xml.namespace.QName)1