Search in sources :

Example 1 with MutableServiceReferenceMetadata

use of org.apache.aries.blueprint.mutable.MutableServiceReferenceMetadata in project aries by apache.

the class AbstractPropertyPlaceholder method processServiceReferenceMetadata.

private Metadata processServiceReferenceMetadata(ServiceReferenceMetadata component) {
    if (component instanceof MutableServiceReferenceMetadata) {
        ValueMetadata valueMetadata = ((MutableServiceReferenceMetadata) component).getExtendedFilter();
        if (valueMetadata != null) {
            ((MutableServiceReferenceMetadata) component).setExtendedFilter(doProcessValueMetadata(valueMetadata));
        }
    }
    for (ReferenceListener listener : component.getReferenceListeners()) {
        Target listenerComponent = listener.getListenerComponent();
        try {
            processingStack.add("Reference Listener " + listenerComponent + "->");
            if (listener instanceof MutableReferenceListener) {
                ((MutableReferenceListener) listener).setListenerComponent((Target) processMetadata(listenerComponent));
            } else {
                //Say that we can't change this listener, but continue processing
                //If the value is mutable then we may be ok!
                printWarning(listener, "Reference Binding Listener");
                processMetadata(listenerComponent);
            }
        } finally {
            processingStack.removeLast();
        }
    }
    return component;
}
Also used : MutableReferenceListener(org.apache.aries.blueprint.mutable.MutableReferenceListener) Target(org.osgi.service.blueprint.reflect.Target) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) MutableReferenceListener(org.apache.aries.blueprint.mutable.MutableReferenceListener) ReferenceListener(org.osgi.service.blueprint.reflect.ReferenceListener) MutableServiceReferenceMetadata(org.apache.aries.blueprint.mutable.MutableServiceReferenceMetadata)

Example 2 with MutableServiceReferenceMetadata

use of org.apache.aries.blueprint.mutable.MutableServiceReferenceMetadata in project controller by opendaylight.

the class OpendaylightNamespaceHandler method decorateServiceReferenceType.

private static ComponentMetadata decorateServiceReferenceType(final Attr attr, final ComponentMetadata component, final ParserContext context) {
    if (!(component instanceof MutableServiceReferenceMetadata)) {
        throw new ComponentDefinitionException("Expected an instanceof MutableServiceReferenceMetadata");
    }
    // We don't actually need the ComponentProcessor for augmenting the OSGi filter here but we create it
    // to workaround an issue in Aries where it doesn't use the extended filter unless there's a
    // Processor or ComponentDefinitionRegistryProcessor registered. This may actually be working as
    // designed in Aries b/c the extended filter was really added to allow the OSGi filter to be
    // substituted by a variable via the "cm:property-placeholder" processor. If so, it's a bit funky
    // but as long as there's at least one processor registered, it correctly uses the extended filter.
    registerComponentProcessor(context);
    MutableServiceReferenceMetadata serviceRef = (MutableServiceReferenceMetadata) component;
    String oldFilter = serviceRef.getExtendedFilter() == null ? null : serviceRef.getExtendedFilter().getStringValue();
    String filter;
    if (Strings.isNullOrEmpty(oldFilter)) {
        filter = String.format("(type=%s)", attr.getValue());
    } else {
        filter = String.format("(&(%s)(type=%s))", oldFilter, attr.getValue());
    }
    LOG.debug("decorateServiceReferenceType for {} with type {}, old filter: {}, new filter: {}", serviceRef.getId(), attr.getValue(), oldFilter, filter);
    serviceRef.setExtendedFilter(createValue(context, filter));
    return component;
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) MutableServiceReferenceMetadata(org.apache.aries.blueprint.mutable.MutableServiceReferenceMetadata)

Example 3 with MutableServiceReferenceMetadata

use of org.apache.aries.blueprint.mutable.MutableServiceReferenceMetadata in project aries by apache.

the class ExtNamespaceHandler method decorateProxyMethod.

private ComponentMetadata decorateProxyMethod(Node node, ComponentMetadata component, ParserContext context) {
    if (!(component instanceof ServiceReferenceMetadata)) {
        throw new ComponentDefinitionException("Attribute " + node.getNodeName() + " can only be used on a <reference> or <reference-list> element");
    }
    if (!(component instanceof MutableServiceReferenceMetadata)) {
        throw new ComponentDefinitionException("Expected an instance of MutableServiceReferenceMetadata");
    }
    int method = 0;
    String value = ((Attr) node).getValue();
    String[] flags = value.trim().split(" ");
    for (String flag : flags) {
        if (PROXY_METHOD_DEFAULT.equals(flag)) {
            method += ExtendedReferenceListMetadata.PROXY_METHOD_DEFAULT;
        } else if (PROXY_METHOD_CLASSES.equals(flag)) {
            method += ExtendedReferenceListMetadata.PROXY_METHOD_CLASSES;
        } else if (PROXY_METHOD_GREEDY.equals(flag)) {
            method += ExtendedReferenceListMetadata.PROXY_METHOD_GREEDY;
        } else {
            throw new ComponentDefinitionException("Unknown proxy method: " + flag);
        }
    }
    if ((method & ExtendedReferenceListMetadata.PROXY_METHOD_GREEDY) != 0 && !(component instanceof ReferenceListMetadata)) {
        throw new ComponentDefinitionException("Greedy proxying is only available for <reference-list> element");
    }
    ((MutableServiceReferenceMetadata) component).setProxyMethod(method);
    return component;
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) MutableServiceReferenceMetadata(org.apache.aries.blueprint.mutable.MutableServiceReferenceMetadata) org.apache.aries.blueprint(org.apache.aries.blueprint) Attr(org.w3c.dom.Attr) MutableServiceReferenceMetadata(org.apache.aries.blueprint.mutable.MutableServiceReferenceMetadata)

Aggregations

MutableServiceReferenceMetadata (org.apache.aries.blueprint.mutable.MutableServiceReferenceMetadata)3 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)2 org.apache.aries.blueprint (org.apache.aries.blueprint)1 MutableReferenceListener (org.apache.aries.blueprint.mutable.MutableReferenceListener)1 ReferenceListener (org.osgi.service.blueprint.reflect.ReferenceListener)1 Target (org.osgi.service.blueprint.reflect.Target)1 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)1 Attr (org.w3c.dom.Attr)1