use of org.osgi.service.blueprint.reflect.ComponentMetadata in project camel by apache.
the class CamelNamespaceHandler method getDataformatResolverReference.
private static ComponentMetadata getDataformatResolverReference(ParserContext context, String dataformat) {
// we cannot resolve dataformat names using property placeholders at this point in time
if (dataformat.startsWith(PropertiesComponent.DEFAULT_PREFIX_TOKEN)) {
return null;
}
ComponentDefinitionRegistry componentDefinitionRegistry = context.getComponentDefinitionRegistry();
ComponentMetadata cm = componentDefinitionRegistry.getComponentDefinition(".camelBlueprint.dataformatResolver." + dataformat);
if (cm == null) {
MutableReferenceMetadata svc = context.createMetadata(MutableReferenceMetadata.class);
svc.setId(".camelBlueprint.dataformatResolver." + dataformat);
svc.setFilter("(dataformat=" + dataformat + ")");
svc.setAvailability(componentDefinitionRegistry.containsComponentDefinition(dataformat) ? 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, DataFormatResolver.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(DataFormatResolver.class.getName()) != DataFormatResolver.class) {
throw new UnsupportedOperationException();
}
svc.setInterface(DataFormatResolver.class.getName());
} catch (Throwable t2) {
throw new UnsupportedOperationException();
}
}
componentDefinitionRegistry.registerComponentDefinition(svc);
cm = svc;
}
return cm;
}
use of org.osgi.service.blueprint.reflect.ComponentMetadata in project aries by apache.
the class AbstractParserProxy method parseCDRForReferences.
/**
* Extract References metadata from a ComponentDefinitionRegistry.
* @param cdr ComponentDefinitionRegistry
* @return List<WrappedReferenceMetadata>
* @throws InvalidAttributeException
*/
private List<ImportedService> parseCDRForReferences(ComponentDefinitionRegistry cdr) throws InvalidAttributeException {
_logger.debug(LOG_ENTRY, "parseCDRForReferences", new Object[] { cdr });
List<ImportedService> result = new ArrayList<ImportedService>();
for (ComponentMetadata compMetadata : findAllComponents(cdr)) {
if (compMetadata instanceof ServiceReferenceMetadata) {
ServiceReferenceMetadata referenceMetadata = (ServiceReferenceMetadata) compMetadata;
boolean optional = referenceMetadata.getAvailability() == ServiceReferenceMetadata.AVAILABILITY_OPTIONAL;
String iface = referenceMetadata.getInterface();
String compName = referenceMetadata.getComponentName();
String blueprintFilter = referenceMetadata.getFilter();
String id = referenceMetadata.getId();
boolean isMultiple = (referenceMetadata instanceof ReferenceListMetadata);
// For now we blacklist certain objectClasses and filters - this is a pretty dreadful thing to do.
if (!isBlacklisted(iface, blueprintFilter)) {
ImportedService ref = _modellingManager.getImportedService(optional, iface, compName, blueprintFilter, id, isMultiple);
result.add(ref);
}
}
}
_logger.debug(LOG_EXIT, "parseCDRForReferences", new Object[] { result });
return result;
}
use of org.osgi.service.blueprint.reflect.ComponentMetadata in project aries by apache.
the class AbstractParserProxy method findAllComponents.
/**
* Find all the components in a given {@link ComponentDefinitionRegistry} this finds top-level
* components as well as their nested counter-parts. It may however not find components in custom namespacehandler
* {@link ComponentMetadata} instances.
*
* @param cdr The {@link ComponentDefinitionRegistry} to scan
* @return a {@link Set} of {@link ComponentMetadata}
*/
private Set<ComponentMetadata> findAllComponents(ComponentDefinitionRegistry cdr) {
Set<ComponentMetadata> components = new HashSet<ComponentMetadata>();
for (String name : cdr.getComponentDefinitionNames()) {
ComponentMetadata component = cdr.getComponentDefinition(name);
traverseComponent(component, components);
}
return components;
}
use of org.osgi.service.blueprint.reflect.ComponentMetadata in project aries by apache.
the class AbstractParserProxy method traverse.
/**
* Traverse to find all nested {@link ComponentMetadata} instances
* @param metadata
* @param output
*/
private void traverse(Metadata metadata, Set<ComponentMetadata> output) {
if (metadata instanceof ComponentMetadata) {
traverseComponent((ComponentMetadata) metadata, output);
} else if (metadata instanceof CollectionMetadata) {
CollectionMetadata collection = (CollectionMetadata) metadata;
for (Metadata v : collection.getValues()) traverse(v, output);
} else if (metadata instanceof MapMetadata) {
MapMetadata map = (MapMetadata) metadata;
for (MapEntry e : map.getEntries()) {
traverse(e.getKey(), output);
traverse(e.getValue(), output);
}
}
}
use of org.osgi.service.blueprint.reflect.ComponentMetadata in project aries by apache.
the class BlueprintRepository method createInstances.
private Map<String, Object> createInstances(Collection<String> names) {
// Instance creation is synchronized inside each create method (via the use of futures), so that
// a recipe will only created once where appropriate
DependencyGraph graph = new DependencyGraph(this);
HashMap<String, Object> objects = new LinkedHashMap<String, Object>();
for (Map.Entry<String, Recipe> entry : graph.getSortedRecipes(names).entrySet()) {
String name = entry.getKey();
ComponentMetadata component = blueprintContainer.getComponentDefinitionRegistry().getComponentDefinition(name);
boolean prototype = (component instanceof BeanMetadata) && MetadataUtil.isPrototypeScope((BeanMetadata) component);
if (!prototype || names.contains(name)) {
objects.put(name, entry.getValue().create());
}
}
return objects;
}
Aggregations