Search in sources :

Example 86 with MutableBeanMetadata

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

the class NettyServerEngineFactoryParser method parse.

public Metadata parse(Element element, ParserContext context) {
    // Endpoint definition
    MutableBeanMetadata ef = context.createMetadata(MutableBeanMetadata.class);
    if (!StringUtils.isEmpty(getIdOrName(element))) {
        ef.setId(getIdOrName(element));
    } else {
        ef.setId("netty.engine.factory-holder-" + UUID.randomUUID().toString());
    }
    ef.setRuntimeClass(NettyHttpServerEngineFactoryHolder.class);
    try {
        // Print the DOM node
        String xmlString = StaxUtils.toString(element);
        ef.addProperty("parsedElement", createValue(context, xmlString));
        ef.setInitMethod("init");
        ef.setActivation(ComponentMetadata.ACTIVATION_EAGER);
        ef.setDestroyMethod("destroy");
        return ef;
    } catch (Exception e) {
        throw new RuntimeException("Could not process configuration.", e);
    }
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata)

Example 87 with MutableBeanMetadata

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

Example 88 with MutableBeanMetadata

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

the class EndpointDefinitionParser method parse.

public Metadata parse(Element element, ParserContext context) {
    // Endpoint definition
    MutableBeanMetadata cxfBean = context.createMetadata(MutableBeanMetadata.class);
    if (!StringUtils.isEmpty(getIdOrName(element))) {
        cxfBean.setId(getIdOrName(element));
    } else {
        cxfBean.setId("cxf.endpoint." + UUID.randomUUID().toString());
    }
    cxfBean.setRuntimeClass(EP_CLASS);
    boolean isAbstract = false;
    boolean publish = true;
    NamedNodeMap atts = element.getAttributes();
    String bus = null;
    Metadata impl = 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 ("createdFromAPI".equals(name) || "abstract".equals(name)) {
            cxfBean.setScope(BeanMetadata.SCOPE_PROTOTYPE);
            isAbstract = true;
        } else if ("publish".equals(name)) {
            publish = Boolean.parseBoolean(val);
        } else if ("bus".equals(name)) {
            bus = val;
        } else if (isAttribute(pre, name)) {
            if ("endpointName".equals(name) || "serviceName".equals(name)) {
                QName q = parseQName(element, val);
                cxfBean.addProperty(name, createValue(context, q));
            } else if ("depends-on".equals(name)) {
                cxfBean.addDependsOn(val);
            } else if ("implementor".equals(name)) {
                if (val.startsWith("#")) {
                    impl = createRef(context, val.substring(1));
                } else {
                    impl = createObjectOfClass(context, val);
                }
            } else if (!"name".equals(name)) {
                cxfBean.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, cxfBean, elem);
            cxfBean.addProperty(name, map);
        } else if ("binding".equals(name)) {
            setFirstChildAsProperty(elem, context, cxfBean, "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, cxfBean, elem);
            cxfBean.addProperty(name, list);
        } else if ("implementor".equals(name)) {
            impl = context.parseElement(Metadata.class, cxfBean, elem);
        } else {
            setFirstChildAsProperty(elem, context, cxfBean, name);
        }
        elem = DOMUtils.getNextElement(elem);
    }
    if (StringUtils.isEmpty(bus)) {
        bus = "cxf";
    }
    cxfBean.addArgument(this.getBusRef(context, bus), Bus.class.getName(), 0);
    cxfBean.addArgument(impl, Object.class.getName(), 1);
    if (!isAbstract) {
        if (publish) {
            cxfBean.setInitMethod("publish");
        }
        cxfBean.setDestroyMethod("stop");
    }
    // We don't want to delay the registration of our Server
    cxfBean.setActivation(ComponentMetadata.ACTIVATION_EAGER);
    return cxfBean;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) Bus(org.apache.cxf.Bus) NamedNodeMap(org.w3c.dom.NamedNodeMap) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Metadata(org.osgi.service.blueprint.reflect.Metadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) Attr(org.w3c.dom.Attr)

Example 89 with MutableBeanMetadata

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

the class BusDefinitionParser method parse.

public Metadata parse(Element element, ParserContext context) {
    String bname = element.hasAttribute("bus") ? element.getAttribute("bus") : "cxf";
    String id = element.hasAttribute("id") ? element.getAttribute("id") : null;
    MutableBeanMetadata cxfBean = getBus(context, bname);
    parseAttributes(element, context, cxfBean);
    parseChildElements(element, context, cxfBean);
    context.getComponentDefinitionRegistry().removeComponentDefinition(bname);
    if (!StringUtils.isEmpty(id)) {
        cxfBean.addProperty("id", createValue(context, id));
    }
    return cxfBean;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata)

Example 90 with MutableBeanMetadata

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

Aggregations

MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)96 Element (org.w3c.dom.Element)23 Node (org.w3c.dom.Node)20 MutablePassThroughMetadata (org.apache.aries.blueprint.mutable.MutablePassThroughMetadata)19 Metadata (org.osgi.service.blueprint.reflect.Metadata)19 MutableRefMetadata (org.apache.aries.blueprint.mutable.MutableRefMetadata)18 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)18 MutableCollectionMetadata (org.apache.aries.blueprint.mutable.MutableCollectionMetadata)17 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)16 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)15 MutableValueMetadata (org.apache.aries.blueprint.mutable.MutableValueMetadata)13 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)12 NodeList (org.w3c.dom.NodeList)11 MutableMapMetadata (org.apache.aries.blueprint.mutable.MutableMapMetadata)10 PassThroughMetadata (org.apache.aries.blueprint.PassThroughMetadata)9 JAXBException (javax.xml.bind.JAXBException)8 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)8 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)8 ExpressionNode (org.apache.camel.model.ExpressionNode)7 Attr (org.w3c.dom.Attr)7