Search in sources :

Example 41 with ComponentDefinitionException

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

the class Parser method parseProperty.

private MapEntry parseProperty(Element element) {
    // Parse attributes
    if (!element.hasAttribute(KEY_ATTRIBUTE)) {
        throw new ComponentDefinitionException(KEY_ATTRIBUTE + " attribute is required");
    }
    String value;
    if (element.hasAttribute(VALUE_ATTRIBUTE)) {
        value = element.getAttribute(VALUE_ATTRIBUTE);
    } else {
        value = getTextValue(element);
    }
    String key = element.getAttribute(KEY_ATTRIBUTE);
    return new MapEntryImpl(new ValueMetadataImpl(key), new ValueMetadataImpl(value));
}
Also used : ValueMetadataImpl(org.apache.aries.blueprint.reflect.ValueMetadataImpl) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) MapEntryImpl(org.apache.aries.blueprint.reflect.MapEntryImpl)

Example 42 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 43 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)

Example 44 with ComponentDefinitionException

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

the class BeanRecipe method getInstanceFromFactory.

private Object getInstanceFromFactory(List<Object> args, List<ReifiedType> argTypes) {
    Object factoryObj = getFactoryObj();
    // Map of matching methods
    Map<Method, List<Object>> matches = findMatchingMethods(factoryObj.getClass(), factoryMethod, true, args, argTypes);
    if (matches.size() == 1) {
        try {
            Map.Entry<Method, List<Object>> match = matches.entrySet().iterator().next();
            return invoke(match.getKey(), factoryObj, match.getValue().toArray());
        } catch (Throwable e) {
            throw wrapAsCompDefEx(e);
        }
    } else if (matches.size() == 0) {
        throw new ComponentDefinitionException("Unable to find a matching factory method " + factoryMethod + " on class " + factoryObj.getClass().getName() + " for arguments " + argsToString(args) + " when instanciating bean " + getName());
    } else {
        throw new ComponentDefinitionException("Multiple matching factory methods " + factoryMethod + " found on class " + factoryObj.getClass().getName() + " for arguments " + argsToString(args) + " when instanciating bean " + getName() + ": " + matches.keySet());
    }
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) ArrayList(java.util.ArrayList) List(java.util.List) Method(java.lang.reflect.Method) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 45 with ComponentDefinitionException

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

the class BeanRecipe method createProxyBean.

private Object createProxyBean(ReferenceRecipe rr) {
    try {
        VoidableCallable vc = new VoidableCallable();
        rr.addVoidableChild(vc);
        return blueprintContainer.getProxyManager().createDelegatingProxy(blueprintContainer.getBundleContext().getBundle(), rr.getProxyChildBeanClasses(), vc, vc.call());
    } catch (UnableToProxyException e) {
        throw new ComponentDefinitionException(e);
    }
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) UnableToProxyException(org.apache.aries.proxy.UnableToProxyException)

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