Search in sources :

Example 1 with RegistrationListenerImpl

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

IdRefMetadataImpl (org.apache.aries.blueprint.reflect.IdRefMetadataImpl)1 RefMetadataImpl (org.apache.aries.blueprint.reflect.RefMetadataImpl)1 RegistrationListenerImpl (org.apache.aries.blueprint.reflect.RegistrationListenerImpl)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