Search in sources :

Example 16 with ComponentMetadata

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

the class Parser method loadComponents.

private void loadComponents(Document doc) {
    defaultTimeout = TIMEOUT_DEFAULT;
    defaultAvailability = AVAILABILITY_DEFAULT;
    defaultActivation = ACTIVATION_DEFAULT;
    Element root = doc.getDocumentElement();
    if (!isBlueprintNamespace(root.getNamespaceURI()) || !nodeNameEquals(root, BLUEPRINT_ELEMENT)) {
        throw new ComponentDefinitionException("Root element must be {" + BLUEPRINT_NAMESPACE + "}" + BLUEPRINT_ELEMENT + " element");
    }
    // Parse global attributes
    if (root.hasAttribute(DEFAULT_ACTIVATION_ATTRIBUTE)) {
        defaultActivation = root.getAttribute(DEFAULT_ACTIVATION_ATTRIBUTE);
    }
    if (root.hasAttribute(DEFAULT_TIMEOUT_ATTRIBUTE)) {
        defaultTimeout = root.getAttribute(DEFAULT_TIMEOUT_ATTRIBUTE);
    }
    if (root.hasAttribute(DEFAULT_AVAILABILITY_ATTRIBUTE)) {
        defaultAvailability = root.getAttribute(DEFAULT_AVAILABILITY_ATTRIBUTE);
    }
    // Parse custom attributes
    handleCustomAttributes(root.getAttributes(), null);
    // Parse elements
    // Break into 2 loops to ensure we scan the blueprint elements before
    // This is needed so that when we process the custom element, we know
    // the component definition registry has populated all blueprint components.
    NodeList nl = root.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node node = nl.item(i);
        if (node instanceof Element) {
            Element element = (Element) node;
            String namespaceUri = element.getNamespaceURI();
            if (isBlueprintNamespace(namespaceUri)) {
                parseBlueprintElement(element);
            }
        }
    }
    for (int i = 0; i < nl.getLength(); i++) {
        Node node = nl.item(i);
        if (node instanceof Element) {
            Element element = (Element) node;
            String namespaceUri = element.getNamespaceURI();
            if (!isBlueprintNamespace(namespaceUri)) {
                Metadata component = parseCustomElement(element, null);
                if (component != null) {
                    if (!(component instanceof ComponentMetadata)) {
                        throw new ComponentDefinitionException("Expected a ComponentMetadata to be returned when parsing element " + element.getNodeName());
                    }
                    registry.registerComponentDefinition((ComponentMetadata) component);
                }
            }
        }
    }
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) 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) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata)

Example 17 with ComponentMetadata

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

the class Parser method parseArgumentOrPropertyValue.

private Metadata parseArgumentOrPropertyValue(Element element, ComponentMetadata enclosingComponent) {
    Metadata[] values = new Metadata[3];
    if (element.hasAttribute(REF_ATTRIBUTE)) {
        values[0] = new RefMetadataImpl(element.getAttribute(REF_ATTRIBUTE));
    }
    if (element.hasAttribute(VALUE_ATTRIBUTE)) {
        values[1] = new ValueMetadataImpl(element.getAttribute(VALUE_ATTRIBUTE));
    }
    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(node.getNamespaceURI()) && nodeNameEquals(node, DESCRIPTION_ELEMENT)) {
            // Ignore description elements
            } else {
                values[2] = parseValueGroup(e, enclosingComponent, null, true);
                break;
            }
        }
    }
    Metadata value = null;
    for (Metadata v : values) {
        if (v != null) {
            if (value == null) {
                value = v;
            } else {
                throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + VALUE_ATTRIBUTE + " attribute or sub element must be set");
            }
        }
    }
    if (value == null) {
        throw new ComponentDefinitionException("One of " + REF_ATTRIBUTE + " attribute, " + VALUE_ATTRIBUTE + " attribute or sub element must be set");
    }
    return value;
}
Also used : ValueMetadataImpl(org.apache.aries.blueprint.reflect.ValueMetadataImpl) 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) RefMetadataImpl(org.apache.aries.blueprint.reflect.RefMetadataImpl) IdRefMetadataImpl(org.apache.aries.blueprint.reflect.IdRefMetadataImpl)

Example 18 with ComponentMetadata

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

the class Parser method parseMapEntry.

private MapEntry parseMapEntry(Element element, ComponentMetadata enclosingComponent, String keyType, String valueType) {
    // Parse attributes
    String key = element.hasAttribute(KEY_ATTRIBUTE) ? element.getAttribute(KEY_ATTRIBUTE) : null;
    String keyRef = element.hasAttribute(KEY_REF_ATTRIBUTE) ? element.getAttribute(KEY_REF_ATTRIBUTE) : null;
    String value = element.hasAttribute(VALUE_ATTRIBUTE) ? element.getAttribute(VALUE_ATTRIBUTE) : null;
    String valueRef = element.hasAttribute(VALUE_REF_ATTRIBUTE) ? element.getAttribute(VALUE_REF_ATTRIBUTE) : null;
    // Parse elements
    NonNullMetadata keyValue = null;
    Metadata valValue = null;
    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 (nodeNameEquals(e, KEY_ELEMENT)) {
                keyValue = parseMapKeyEntry(e, enclosingComponent, keyType);
            } else {
                valValue = parseValueGroup(e, enclosingComponent, valueType, true);
            }
        }
    }
    // Check key
    if (keyValue != null && (key != null || keyRef != null) || (keyValue == null && key == null && keyRef == null)) {
        throw new ComponentDefinitionException("Only and only one of " + KEY_ATTRIBUTE + " attribute, " + KEY_REF_ATTRIBUTE + " attribute or " + KEY_ELEMENT + " element must be set");
    } else if (keyValue == null && key != null) {
        keyValue = new ValueMetadataImpl(key, keyType);
    } else if (keyValue == null) /*&& keyRef != null*/
    {
        keyValue = new RefMetadataImpl(keyRef);
    }
    // Check value
    if (valValue != null && (value != null || valueRef != null) || (valValue == null && value == null && valueRef == null)) {
        throw new ComponentDefinitionException("Only and only one of " + VALUE_ATTRIBUTE + " attribute, " + VALUE_REF_ATTRIBUTE + " attribute or sub element must be set");
    } else if (valValue == null && value != null) {
        valValue = new ValueMetadataImpl(value, valueType);
    } else if (valValue == null) /*&& valueRef != null*/
    {
        valValue = new RefMetadataImpl(valueRef);
    }
    return new MapEntryImpl(keyValue, valValue);
}
Also used : ValueMetadataImpl(org.apache.aries.blueprint.reflect.ValueMetadataImpl) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) MapEntryImpl(org.apache.aries.blueprint.reflect.MapEntryImpl) 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) NonNullMetadata(org.osgi.service.blueprint.reflect.NonNullMetadata) RefMetadataImpl(org.apache.aries.blueprint.reflect.RefMetadataImpl) IdRefMetadataImpl(org.apache.aries.blueprint.reflect.IdRefMetadataImpl)

Example 19 with ComponentMetadata

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

the class Parser method parseServiceListener.

private ReferenceListener parseServiceListener(Element element, ComponentMetadata enclosingComponent) {
    ReferenceListenerImpl listener = new ReferenceListenerImpl();
    Metadata listenerComponent = null;
    // Parse attributes
    if (element.hasAttribute(REF_ATTRIBUTE)) {
        listenerComponent = new RefMetadataImpl(element.getAttribute(REF_ATTRIBUTE));
    }
    String bindMethodName = null;
    String unbindMethodName = null;
    if (element.hasAttribute(BIND_METHOD_ATTRIBUTE)) {
        bindMethodName = element.getAttribute(BIND_METHOD_ATTRIBUTE);
        listener.setBindMethod(bindMethodName);
    }
    if (element.hasAttribute(UNBIND_METHOD_ATTRIBUTE)) {
        unbindMethodName = element.getAttribute(UNBIND_METHOD_ATTRIBUTE);
        listener.setUnbindMethod(unbindMethodName);
    }
    if (bindMethodName == null && unbindMethodName == null) {
        throw new ComponentDefinitionException("One of " + BIND_METHOD_ATTRIBUTE + " or " + UNBIND_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 + ", " + BLUEPRINT_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 + ", " + BLUEPRINT_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 + ", " + BLUEPRINT_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 + ", " + BLUEPRINT_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 + ", " + BLUEPRINT_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 + ", " + BLUEPRINT_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) ReferenceListenerImpl(org.apache.aries.blueprint.reflect.ReferenceListenerImpl) 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) RefMetadataImpl(org.apache.aries.blueprint.reflect.RefMetadataImpl) IdRefMetadataImpl(org.apache.aries.blueprint.reflect.IdRefMetadataImpl)

Example 20 with ComponentMetadata

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

the class Parser method parseRefList.

private ComponentMetadata parseRefList(Element element, boolean topElement) {
    ReferenceListMetadataImpl references = new ReferenceListMetadataImpl();
    if (topElement) {
        references.setId(getId(element));
    }
    if (element.hasAttribute(MEMBER_TYPE_ATTRIBUTE)) {
        String memberType = element.getAttribute(MEMBER_TYPE_ATTRIBUTE);
        if (USE_SERVICE_OBJECT.equals(memberType)) {
            references.setMemberType(ReferenceListMetadata.USE_SERVICE_OBJECT);
        } else if (USE_SERVICE_REFERENCE.equals(memberType)) {
            references.setMemberType(ReferenceListMetadata.USE_SERVICE_REFERENCE);
        }
    } else {
        references.setMemberType(ReferenceListMetadata.USE_SERVICE_OBJECT);
    }
    parseReference(element, references, topElement);
    ComponentMetadata r = references;
    // Parse custom attributes
    r = handleCustomAttributes(element.getAttributes(), r);
    // Parse custom elements;
    r = handleCustomElements(element, r);
    return r;
}
Also used : ReferenceListMetadataImpl(org.apache.aries.blueprint.reflect.ReferenceListMetadataImpl) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata)

Aggregations

ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)45 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)22 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)17 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)17 Metadata (org.osgi.service.blueprint.reflect.Metadata)16 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)15 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)15 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)14 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)14 ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)13 NullMetadata (org.osgi.service.blueprint.reflect.NullMetadata)12 ReferenceListMetadata (org.osgi.service.blueprint.reflect.ReferenceListMetadata)12 ReferenceMetadata (org.osgi.service.blueprint.reflect.ReferenceMetadata)12 Node (org.w3c.dom.Node)12 ArrayList (java.util.ArrayList)11 IdRefMetadata (org.osgi.service.blueprint.reflect.IdRefMetadata)11 Element (org.w3c.dom.Element)11 PropsMetadata (org.osgi.service.blueprint.reflect.PropsMetadata)10 NodeList (org.w3c.dom.NodeList)10 NonNullMetadata (org.osgi.service.blueprint.reflect.NonNullMetadata)9