Search in sources :

Example 1 with ReferenceListenerImpl

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

Aggregations

IdRefMetadataImpl (org.apache.aries.blueprint.reflect.IdRefMetadataImpl)1 RefMetadataImpl (org.apache.aries.blueprint.reflect.RefMetadataImpl)1 ReferenceListenerImpl (org.apache.aries.blueprint.reflect.ReferenceListenerImpl)1 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)1 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)1 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)1 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)1 IdRefMetadata (org.osgi.service.blueprint.reflect.IdRefMetadata)1 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)1 Metadata (org.osgi.service.blueprint.reflect.Metadata)1 NonNullMetadata (org.osgi.service.blueprint.reflect.NonNullMetadata)1 NullMetadata (org.osgi.service.blueprint.reflect.NullMetadata)1 PropsMetadata (org.osgi.service.blueprint.reflect.PropsMetadata)1 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)1 ReferenceListMetadata (org.osgi.service.blueprint.reflect.ReferenceListMetadata)1 ReferenceMetadata (org.osgi.service.blueprint.reflect.ReferenceMetadata)1 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)1 ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)1 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)1 Element (org.w3c.dom.Element)1