Search in sources :

Example 36 with Metadata

use of org.osgi.service.blueprint.reflect.Metadata 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 37 with Metadata

use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.

the class AbstractParserProxy method traverse.

/**
 * Traverse to find all nested {@link ComponentMetadata} instances
 * @param metadata
 * @param output
 */
private void traverse(Metadata metadata, Set<ComponentMetadata> output) {
    if (metadata instanceof ComponentMetadata) {
        traverseComponent((ComponentMetadata) metadata, output);
    } else if (metadata instanceof CollectionMetadata) {
        CollectionMetadata collection = (CollectionMetadata) metadata;
        for (Metadata v : collection.getValues()) traverse(v, output);
    } else if (metadata instanceof MapMetadata) {
        MapMetadata map = (MapMetadata) metadata;
        for (MapEntry e : map.getEntries()) {
            traverse(e.getKey(), output);
            traverse(e.getValue(), output);
        }
    }
}
Also used : CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) WrappedServiceMetadata(org.apache.aries.application.modelling.WrappedServiceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata)

Example 38 with Metadata

use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.

the class AbstractPropertyPlaceholder method processCollectionMetadata.

protected Metadata processCollectionMetadata(CollectionMetadata metadata) {
    List<Metadata> values = new ArrayList<Metadata>(metadata.getValues());
    if (!!!values.isEmpty()) {
        try {
            if (metadata instanceof MutableCollectionMetadata) {
                processingStack.add("Collection type: " + metadata.getValueType() + "->");
                MutableCollectionMetadata mcm = (MutableCollectionMetadata) metadata;
                for (Metadata value : values) {
                    mcm.removeValue(value);
                }
                for (Metadata value : values) {
                    mcm.addValue(processMetadata(value));
                }
            } else {
                printWarning(metadata, "Collection type: " + metadata.getValueType());
                processingStack.add("Collection type: " + metadata.getValueType() + "->");
                for (Metadata value : values) {
                    processMetadata(value);
                }
            }
        } finally {
            processingStack.removeLast();
        }
    }
    return metadata;
}
Also used : CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) MutablePropsMetadata(org.apache.aries.blueprint.mutable.MutablePropsMetadata) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) NonNullMetadata(org.osgi.service.blueprint.reflect.NonNullMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ExtendedValueMetadata(org.apache.aries.blueprint.ExtendedValueMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata) ArrayList(java.util.ArrayList) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata)

Example 39 with Metadata

use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.

the class Parser method parseBeanArgument.

private BeanArgument parseBeanArgument(ComponentMetadata enclosingComponent, Element element) {
    int index = element.hasAttribute(INDEX_ATTRIBUTE) ? Integer.parseInt(element.getAttribute(INDEX_ATTRIBUTE)) : -1;
    String type = element.hasAttribute(TYPE_ATTRIBUTE) ? element.getAttribute(TYPE_ATTRIBUTE) : null;
    Metadata value = parseArgumentOrPropertyValue(element, enclosingComponent);
    return new BeanArgumentImpl(value, type, index);
}
Also used : BeanArgumentImpl(org.apache.aries.blueprint.reflect.BeanArgumentImpl) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) NonNullMetadata(org.osgi.service.blueprint.reflect.NonNullMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) NullMetadata(org.osgi.service.blueprint.reflect.NullMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) IdRefMetadata(org.osgi.service.blueprint.reflect.IdRefMetadata) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata)

Example 40 with Metadata

use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.

the class Parser method parseRegistrationListener.

public RegistrationListener parseRegistrationListener(Element element, ComponentMetadata enclosingComponent) {
    RegistrationListenerImpl listener = new RegistrationListenerImpl();
    Metadata listenerComponent = null;
    // Parse attributes
    if (element.hasAttribute(REF_ATTRIBUTE)) {
        listenerComponent = new RefMetadataImpl(element.getAttribute(REF_ATTRIBUTE));
    }
    String registrationMethod = null;
    if (element.hasAttribute(REGISTRATION_METHOD_ATTRIBUTE)) {
        registrationMethod = element.getAttribute(REGISTRATION_METHOD_ATTRIBUTE);
        listener.setRegistrationMethod(registrationMethod);
    }
    String unregistrationMethod = null;
    if (element.hasAttribute(UNREGISTRATION_METHOD_ATTRIBUTE)) {
        unregistrationMethod = element.getAttribute(UNREGISTRATION_METHOD_ATTRIBUTE);
        listener.setUnregistrationMethod(unregistrationMethod);
    }
    if (registrationMethod == null && unregistrationMethod == null) {
        throw new ComponentDefinitionException("One of " + REGISTRATION_METHOD_ATTRIBUTE + " or " + UNREGISTRATION_METHOD_ATTRIBUTE + " must be set");
    }
    // Parse elements
    NodeList nl = element.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node node = nl.item(i);
        if (node instanceof Element) {
            Element e = (Element) node;
            if (isBlueprintNamespace(e.getNamespaceURI())) {
                if (nodeNameEquals(e, REF_ELEMENT)) {
                    if (listenerComponent != null) {
                        throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
                    }
                    String component = e.getAttribute(COMPONENT_ID_ATTRIBUTE);
                    if (component == null || component.length() == 0) {
                        throw new ComponentDefinitionException("Element " + REF_ELEMENT + " must have a valid " + COMPONENT_ID_ATTRIBUTE + " attribute");
                    }
                    listenerComponent = new RefMetadataImpl(component);
                } else if (nodeNameEquals(e, BEAN_ELEMENT)) {
                    if (listenerComponent != null) {
                        throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
                    }
                    listenerComponent = parseBeanMetadata(e, false);
                } else if (nodeNameEquals(e, REFERENCE_ELEMENT)) {
                    if (listenerComponent != null) {
                        throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
                    }
                    listenerComponent = parseReference(e, false);
                } else if (nodeNameEquals(e, SERVICE_ELEMENT)) {
                    if (listenerComponent != null) {
                        throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
                    }
                    listenerComponent = parseService(e, false);
                }
            } else {
                if (listenerComponent != null) {
                    throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
                }
                listenerComponent = parseCustomElement(e, enclosingComponent);
            }
        }
    }
    if (listenerComponent == null) {
        throw new ComponentDefinitionException("One of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element must be set");
    }
    listener.setListenerComponent((Target) listenerComponent);
    return listener;
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) NonNullMetadata(org.osgi.service.blueprint.reflect.NonNullMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) NullMetadata(org.osgi.service.blueprint.reflect.NullMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) IdRefMetadata(org.osgi.service.blueprint.reflect.IdRefMetadata) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) RegistrationListenerImpl(org.apache.aries.blueprint.reflect.RegistrationListenerImpl) RefMetadataImpl(org.apache.aries.blueprint.reflect.RefMetadataImpl) IdRefMetadataImpl(org.apache.aries.blueprint.reflect.IdRefMetadataImpl)

Aggregations

Metadata (org.osgi.service.blueprint.reflect.Metadata)46 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)35 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)32 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)27 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)26 MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)24 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)23 Element (org.w3c.dom.Element)20 ReferenceMetadata (org.osgi.service.blueprint.reflect.ReferenceMetadata)17 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)17 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)16 ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)16 MutableRefMetadata (org.apache.aries.blueprint.mutable.MutableRefMetadata)15 NonNullMetadata (org.osgi.service.blueprint.reflect.NonNullMetadata)15 NullMetadata (org.osgi.service.blueprint.reflect.NullMetadata)15 IdRefMetadata (org.osgi.service.blueprint.reflect.IdRefMetadata)12 ReferenceListMetadata (org.osgi.service.blueprint.reflect.ReferenceListMetadata)12 Node (org.w3c.dom.Node)12 NodeList (org.w3c.dom.NodeList)12 MutableMapMetadata (org.apache.aries.blueprint.mutable.MutableMapMetadata)11