Search in sources :

Example 11 with ComponentDefinitionException

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

the class Parser method parseReference.

private ComponentMetadata parseReference(Element element, boolean topElement) {
    ReferenceMetadataImpl reference = new ReferenceMetadataImpl();
    if (topElement) {
        reference.setId(getId(element));
    }
    parseReference(element, reference, topElement);
    String timeout = element.hasAttribute(TIMEOUT_ATTRIBUTE) ? element.getAttribute(TIMEOUT_ATTRIBUTE) : this.defaultTimeout;
    try {
        reference.setTimeout(Long.parseLong(timeout));
    } catch (NumberFormatException e) {
        throw new ComponentDefinitionException("Attribute " + TIMEOUT_ATTRIBUTE + " must be a valid long (was: " + timeout + ")");
    }
    ComponentMetadata r = reference;
    // Parse custom attributes
    r = handleCustomAttributes(element.getAttributes(), r);
    // Parse custom elements;
    r = handleCustomElements(element, r);
    return r;
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ReferenceMetadataImpl(org.apache.aries.blueprint.reflect.ReferenceMetadataImpl) ServiceReferenceMetadataImpl(org.apache.aries.blueprint.reflect.ServiceReferenceMetadataImpl)

Example 12 with ComponentDefinitionException

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

the class Parser method parseInterfaceNames.

public List<String> parseInterfaceNames(Element element) {
    List<String> interfaceNames = new ArrayList<String>();
    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, VALUE_ELEMENT)) {
                String v = getTextValue(e).trim();
                if (interfaceNames.contains(v)) {
                    throw new ComponentDefinitionException("The element " + INTERFACES_ELEMENT + " should not contain the same interface twice");
                }
                interfaceNames.add(getTextValue(e));
            } else {
                throw new ComponentDefinitionException("Unsupported element " + e.getNodeName() + " inside an " + INTERFACES_ELEMENT + " element");
            }
        }
    }
    return interfaceNames;
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Example 13 with ComponentDefinitionException

use of org.osgi.service.blueprint.container.ComponentDefinitionException 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 14 with ComponentDefinitionException

use of org.osgi.service.blueprint.container.ComponentDefinitionException 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 15 with ComponentDefinitionException

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

the class Parser method getNamespaceForAttributeValue.

/**
     * Takes an Attribute Node containing a namespace prefix qualified attribute value, and resolves the namespace using the DOM Node.<br> 
     *  
     * @param attrNode The DOM Node with the qualified attribute value.
     * @return The URI if one is resolvable, or null if the attr is null, or not namespace prefixed. (or not a DOM Attribute Node)
     * @throws ComponentDefinitionException if the namespace prefix in the attribute value cannot be resolved.
     */
private URI getNamespaceForAttributeValue(Node attrNode) throws ComponentDefinitionException {
    URI uri = null;
    if (attrNode != null && (attrNode instanceof Attr)) {
        Attr attr = (Attr) attrNode;
        String attrValue = attr.getValue();
        if (attrValue != null && attrValue.indexOf(":") != -1) {
            String[] parts = attrValue.split(":");
            String uriStr = attr.getOwnerElement().lookupNamespaceURI(parts[0]);
            if (uriStr != null) {
                uri = URI.create(uriStr);
            } else {
                throw new ComponentDefinitionException("Unsupported attribute namespace prefix " + parts[0] + " " + attr);
            }
        }
    }
    return uri;
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) URI(java.net.URI) Attr(org.w3c.dom.Attr)

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