use of org.apache.aries.blueprint.mutable.MutableReferenceMetadata in project camel by apache.
the class CamelNamespaceHandler method getLanguageResolverReference.
private static ComponentMetadata getLanguageResolverReference(ParserContext context, String language) {
// we cannot resolve language names using property placeholders at this point in time
if (language.startsWith(PropertiesComponent.DEFAULT_PREFIX_TOKEN)) {
return null;
}
ComponentDefinitionRegistry componentDefinitionRegistry = context.getComponentDefinitionRegistry();
ComponentMetadata cm = componentDefinitionRegistry.getComponentDefinition(".camelBlueprint.languageResolver." + language);
if (cm == null) {
MutableReferenceMetadata svc = context.createMetadata(MutableReferenceMetadata.class);
svc.setId(".camelBlueprint.languageResolver." + language);
svc.setFilter("(language=" + language + ")");
svc.setAvailability(componentDefinitionRegistry.containsComponentDefinition(language) ? AVAILABILITY_OPTIONAL : AVAILABILITY_MANDATORY);
try {
// Try to set the runtime interface (only with aries blueprint > 0.1
svc.getClass().getMethod("setRuntimeInterface", Class.class).invoke(svc, LanguageResolver.class);
} catch (Throwable t) {
// Check if the bundle can see the class
try {
PassThroughMetadata ptm = (PassThroughMetadata) componentDefinitionRegistry.getComponentDefinition("blueprintBundle");
Bundle b = (Bundle) ptm.getObject();
if (b.loadClass(LanguageResolver.class.getName()) != LanguageResolver.class) {
throw new UnsupportedOperationException();
}
svc.setInterface(LanguageResolver.class.getName());
} catch (Throwable t2) {
throw new UnsupportedOperationException();
}
}
componentDefinitionRegistry.registerComponentDefinition(svc);
cm = svc;
}
return cm;
}
use of org.apache.aries.blueprint.mutable.MutableReferenceMetadata in project camel by apache.
the class CamelNamespaceHandler method getComponentResolverReference.
private static ComponentMetadata getComponentResolverReference(ParserContext context, String component) {
// we cannot resolve component names using property placeholders at this point in time
if (component.startsWith(PropertiesComponent.DEFAULT_PREFIX_TOKEN)) {
return null;
}
ComponentDefinitionRegistry componentDefinitionRegistry = context.getComponentDefinitionRegistry();
ComponentMetadata cm = componentDefinitionRegistry.getComponentDefinition(".camelBlueprint.componentResolver." + component);
if (cm == null) {
MutableReferenceMetadata svc = context.createMetadata(MutableReferenceMetadata.class);
svc.setId(".camelBlueprint.componentResolver." + component);
svc.setFilter("(component=" + component + ")");
svc.setAvailability(componentDefinitionRegistry.containsComponentDefinition(component) ? AVAILABILITY_OPTIONAL : AVAILABILITY_MANDATORY);
try {
// Try to set the runtime interface (only with aries blueprint > 0.1
svc.getClass().getMethod("setRuntimeInterface", Class.class).invoke(svc, ComponentResolver.class);
} catch (Throwable t) {
// Check if the bundle can see the class
try {
PassThroughMetadata ptm = (PassThroughMetadata) componentDefinitionRegistry.getComponentDefinition("blueprintBundle");
Bundle b = (Bundle) ptm.getObject();
if (b.loadClass(ComponentResolver.class.getName()) != ComponentResolver.class) {
throw new UnsupportedOperationException();
}
svc.setInterface(ComponentResolver.class.getName());
} catch (Throwable t2) {
throw new UnsupportedOperationException();
}
}
componentDefinitionRegistry.registerComponentDefinition(svc);
cm = svc;
}
return cm;
}
use of org.apache.aries.blueprint.mutable.MutableReferenceMetadata in project aries by apache.
the class ExtNamespaceHandler method decorateAdditionalInterfaces.
private ComponentMetadata decorateAdditionalInterfaces(Node node, ComponentMetadata component, ParserContext context) {
if (!(component instanceof MutableReferenceMetadata)) {
throw new ComponentDefinitionException("Expected an instanceof MutableReferenceMetadata");
}
MutableReferenceMetadata mrm = (MutableReferenceMetadata) component;
List<String> list = new ArrayList<String>();
Node nd = node.getFirstChild();
while (nd != null) {
if (nd instanceof Element && nodeNameEquals(nd, INTERFACE_VALUE)) {
list.add(((Element) nd).getTextContent());
}
nd = nd.getNextSibling();
}
mrm.setExtraInterfaces(list);
return component;
}
use of org.apache.aries.blueprint.mutable.MutableReferenceMetadata in project aries by apache.
the class ExtNamespaceHandler method createReference.
private MutableReferenceMetadata createReference(ParserContext context, String value) {
MutableReferenceMetadata m = context.createMetadata(MutableReferenceMetadata.class);
// use the class instance directly rather than loading the class from the specified the interface name.
m.setRuntimeInterface(PropertyEvaluator.class);
m.setFilter("(org.apache.aries.blueprint.ext.evaluator.name=" + value + ")");
m.setBundleContext(ctx);
return m;
}
use of org.apache.aries.blueprint.mutable.MutableReferenceMetadata in project aries by apache.
the class SpringOsgiNamespaceHandler method parseReference.
private Metadata parseReference(Element element, ParserContext context) {
MutableReferenceMetadata metadata = context.createMetadata(MutableReferenceMetadata.class);
// Parse attributes
if (element.hasAttribute(ID_ATTRIBUTE)) {
metadata.setId(element.getAttribute(ID_ATTRIBUTE));
} else {
metadata.setId(generateId(context));
}
metadata.setAvailability(CARDINALITY_0_1.equals(element.getAttribute(CARDINALITY_ATTRIBUTE)) ? ReferenceMetadata.AVAILABILITY_OPTIONAL : ReferenceMetadata.AVAILABILITY_MANDATORY);
metadata.setTimeout(getLong(element.getAttribute(TIMEOUT_ATTRIBUTE), DEFAULT_TIMEOUT));
metadata.setInterface(element.getAttribute(INTERFACE_ATTRIBUTE));
metadata.setFilter(element.getAttribute(FILTER_ATTRIBUTE));
String[] dependsOn = StringUtils.tokenizeToStringArray(element.getAttribute(DEPENDS_ON_ATTRIBUTE), ",; ");
metadata.setDependsOn(dependsOn != null ? Arrays.asList(dependsOn) : null);
metadata.setComponentName(element.getAttribute(BEAN_NAME_ELEMENT));
// Parse child elements
for (Element child : getChildren(element)) {
if (element.getNamespaceURI().equals(child.getNamespaceURI())) {
if (INTERFACES_ELEMENT.equals(child.getLocalName())) {
List<String> itfs = parseInterfaces(child);
metadata.setExtraInterfaces(itfs);
} else if (LISTENER_ELEMENT.equals(child.getLocalName())) {
String bindMethod = nonEmpty(child.getAttribute(BIND_METHOD_ATTRIBUTE));
String unbindMethod = nonEmpty(child.getAttribute(UNBIND_METHOD_ATTRIBUTE));
String refStr = nonEmpty(child.getAttribute(REF_ATTRIBUTE));
Target listenerComponent = null;
if (refStr != null) {
MutableRefMetadata ref = context.createMetadata(MutableRefMetadata.class);
ref.setComponentId(refStr);
listenerComponent = ref;
}
for (Element cchild : getChildren(child)) {
if (listenerComponent != null) {
throw new IllegalArgumentException("Only one of @ref attribute or inlined bean definition element is allowed");
}
listenerComponent = parseInlinedTarget(context, metadata, cchild);
}
if (listenerComponent == null) {
throw new IllegalArgumentException("Missing @ref attribute or inlined bean definition element");
}
metadata.addServiceListener(listenerComponent, bindMethod, unbindMethod);
}
} else {
throw new UnsupportedOperationException("Custom namespaces not supported");
}
}
return metadata;
}
Aggregations