Search in sources :

Example 36 with ComponentMetadata

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;
}
Also used : ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) Bundle(org.osgi.framework.Bundle) DataFormatResolver(org.apache.camel.spi.DataFormatResolver) MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) MutableReferenceMetadata(org.apache.aries.blueprint.mutable.MutableReferenceMetadata)

Example 37 with ComponentMetadata

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;
}
Also used : ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) ArrayList(java.util.ArrayList) ImportedService(org.apache.aries.application.modelling.ImportedService) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)

Example 38 with ComponentMetadata

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;
}
Also used : ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 39 with ComponentMetadata

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);
        }
    }
}
Also used : CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) WrappedServiceMetadata(org.apache.aries.application.modelling.WrappedServiceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata)

Example 40 with ComponentMetadata

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;
}
Also used : IdRefRecipe(org.apache.aries.blueprint.di.IdRefRecipe) Recipe(org.apache.aries.blueprint.di.Recipe) CollectionRecipe(org.apache.aries.blueprint.di.CollectionRecipe) RefRecipe(org.apache.aries.blueprint.di.RefRecipe) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)54 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)22 Metadata (org.osgi.service.blueprint.reflect.Metadata)19 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)18 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)17 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)17 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)15 ArrayList (java.util.ArrayList)14 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)14 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)14 Element (org.w3c.dom.Element)14 ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)13 NullMetadata (org.osgi.service.blueprint.reflect.NullMetadata)12 ReferenceListMetadata (org.osgi.service.blueprint.reflect.ReferenceListMetadata)12 ReferenceMetadata (org.osgi.service.blueprint.reflect.ReferenceMetadata)12 Node (org.w3c.dom.Node)12 IdRefMetadata (org.osgi.service.blueprint.reflect.IdRefMetadata)11 PropsMetadata (org.osgi.service.blueprint.reflect.PropsMetadata)10 NodeList (org.w3c.dom.NodeList)10 NonNullMetadata (org.osgi.service.blueprint.reflect.NonNullMetadata)9