Search in sources :

Example 56 with ComponentDefinitionException

use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.

the class Parser method parseReference.

private void parseReference(Element element, ServiceReferenceMetadataImpl reference, boolean topElement) {
    // Parse attributes
    if (topElement) {
        reference.setActivation(parseActivation(element));
    } else {
        reference.setActivation(ComponentMetadata.ACTIVATION_LAZY);
    }
    if (element.hasAttribute(DEPENDS_ON_ATTRIBUTE)) {
        reference.setDependsOn(parseList(element.getAttribute(DEPENDS_ON_ATTRIBUTE)));
    }
    if (element.hasAttribute(INTERFACE_ATTRIBUTE)) {
        reference.setInterface(element.getAttribute(INTERFACE_ATTRIBUTE));
    }
    if (element.hasAttribute(FILTER_ATTRIBUTE)) {
        reference.setFilter(element.getAttribute(FILTER_ATTRIBUTE));
    }
    if (element.hasAttribute(COMPONENT_NAME_ATTRIBUTE)) {
        reference.setComponentName(element.getAttribute(COMPONENT_NAME_ATTRIBUTE));
    }
    String availability = element.hasAttribute(AVAILABILITY_ATTRIBUTE) ? element.getAttribute(AVAILABILITY_ATTRIBUTE) : defaultAvailability;
    if (AVAILABILITY_MANDATORY.equals(availability)) {
        reference.setAvailability(ServiceReferenceMetadata.AVAILABILITY_MANDATORY);
    } else if (AVAILABILITY_OPTIONAL.equals(availability)) {
        reference.setAvailability(ServiceReferenceMetadata.AVAILABILITY_OPTIONAL);
    } else {
        throw new ComponentDefinitionException("Illegal value for " + AVAILABILITY_ATTRIBUTE + " attribute: " + availability);
    }
    // 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, REFERENCE_LISTENER_ELEMENT)) {
                    reference.addServiceListener(parseServiceListener(e, reference));
                }
            }
        }
    }
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 57 with ComponentDefinitionException

use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.

the class Parser method handleCustomScope.

/**
     * Tests if a scope attribute value is a custom scope, and if so invokes
     * the appropriate namespace handler, passing the blueprint scope node. 
     * <p> 
     * Currently this tests for custom scope by looking for the presence of
     * a ':' char within the scope attribute value. This is valid as long as
     * the blueprint schema continues to restrict that custom scopes should
     * require that characters presence.
     * <p>
     *  
     * @param scope Value of scope attribute
     * @param bean DOM element for bean associated to this scope 
     * @return Metadata as processed by NS Handler.
     * @throws ComponentDefinitionException if an undeclared prefix is used, 
     *           if a namespace handler is unavailable for a resolved prefix, 
     *           or if the resolved prefix results as the blueprint namespace.
     */
private ComponentMetadata handleCustomScope(Node scope, Element bean, ComponentMetadata metadata) {
    URI scopeNS = getNamespaceForAttributeValue(scope);
    if (scopeNS != null && !BLUEPRINT_NAMESPACE.equals(scopeNS.toString())) {
        NamespaceHandler nsHandler = getNamespaceHandler(scopeNS);
        ParserContextImpl context = new ParserContextImpl(this, registry, metadata, scope);
        metadata = nsHandler.decorate(scope, metadata, context);
    } else if (scopeNS != null) {
        throw new ComponentDefinitionException("Custom scopes cannot use the blueprint namespace " + scope);
    }
    return metadata;
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) NamespaceHandler(org.apache.aries.blueprint.NamespaceHandler) URI(java.net.URI)

Aggregations

ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)57 Node (org.w3c.dom.Node)23 Element (org.w3c.dom.Element)17 NodeList (org.w3c.dom.NodeList)15 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)14 MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)12 ArrayList (java.util.ArrayList)11 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)8 JAXBException (javax.xml.bind.JAXBException)7 MutablePassThroughMetadata (org.apache.aries.blueprint.mutable.MutablePassThroughMetadata)7 IdRefMetadataImpl (org.apache.aries.blueprint.reflect.IdRefMetadataImpl)7 RefMetadataImpl (org.apache.aries.blueprint.reflect.RefMetadataImpl)7 ExpressionNode (org.apache.camel.model.ExpressionNode)7 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)7 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)7 ExtendedBeanMetadata (org.apache.aries.blueprint.ExtendedBeanMetadata)6 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)6 IdRefMetadata (org.osgi.service.blueprint.reflect.IdRefMetadata)6 Metadata (org.osgi.service.blueprint.reflect.Metadata)6 ReferenceMetadata (org.osgi.service.blueprint.reflect.ReferenceMetadata)6