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;
}
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;
}
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;
}
Aggregations