Search in sources :

Example 26 with ComponentMetadata

use of org.osgi.service.blueprint.reflect.ComponentMetadata in project aries by apache.

the class BlueprintContainerImpl method getMetadata.

private <T extends ComponentMetadata> void getMetadata(Class<T> clazz, Metadata component, Collection<T> metadatas) {
    if (component == null) {
        return;
    }
    if (clazz.isInstance(component)) {
        metadatas.add(clazz.cast(component));
    }
    if (component instanceof BeanMetadata) {
        getMetadata(clazz, ((BeanMetadata) component).getFactoryComponent(), metadatas);
        for (BeanArgument arg : ((BeanMetadata) component).getArguments()) {
            getMetadata(clazz, arg.getValue(), metadatas);
        }
        for (BeanProperty prop : ((BeanMetadata) component).getProperties()) {
            getMetadata(clazz, prop.getValue(), metadatas);
        }
    }
    if (component instanceof CollectionMetadata) {
        for (Metadata m : ((CollectionMetadata) component).getValues()) {
            getMetadata(clazz, m, metadatas);
        }
    }
    if (component instanceof MapMetadata) {
        for (MapEntry m : ((MapMetadata) component).getEntries()) {
            getMetadata(clazz, m.getKey(), metadatas);
            getMetadata(clazz, m.getValue(), metadatas);
        }
    }
    if (component instanceof PropsMetadata) {
        for (MapEntry m : ((PropsMetadata) component).getEntries()) {
            getMetadata(clazz, m.getKey(), metadatas);
            getMetadata(clazz, m.getValue(), metadatas);
        }
    }
    if (component instanceof ServiceReferenceMetadata) {
        for (ReferenceListener l : ((ServiceReferenceMetadata) component).getReferenceListeners()) {
            getMetadata(clazz, l.getListenerComponent(), metadatas);
        }
    }
    if (component instanceof ServiceMetadata) {
        getMetadata(clazz, ((ServiceMetadata) component).getServiceComponent(), metadatas);
        for (MapEntry m : ((ServiceMetadata) component).getServiceProperties()) {
            getMetadata(clazz, m.getKey(), metadatas);
            getMetadata(clazz, m.getValue(), metadatas);
        }
        for (RegistrationListener l : ((ServiceMetadata) component).getRegistrationListeners()) {
            getMetadata(clazz, l.getListenerComponent(), metadatas);
        }
    }
}
Also used : BeanArgument(org.osgi.service.blueprint.reflect.BeanArgument) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) RegistrationListener(org.osgi.service.blueprint.reflect.RegistrationListener) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) 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) ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ReferenceListener(org.osgi.service.blueprint.reflect.ReferenceListener) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Example 27 with ComponentMetadata

use of org.osgi.service.blueprint.reflect.ComponentMetadata in project aries by apache.

the class BlueprintContainerImpl method getMetadata.

public <T extends ComponentMetadata> Collection<T> getMetadata(Class<T> clazz) {
    Collection<T> metadatas = new ArrayList<T>();
    for (String name : componentDefinitionRegistry.getComponentDefinitionNames()) {
        ComponentMetadata component = componentDefinitionRegistry.getComponentDefinition(name);
        getMetadata(clazz, component, metadatas);
    }
    metadatas = Collections.unmodifiableCollection(metadatas);
    return metadatas;
}
Also used : ArrayList(java.util.ArrayList) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata)

Example 28 with ComponentMetadata

use of org.osgi.service.blueprint.reflect.ComponentMetadata in project aries by apache.

the class BlueprintContainerImpl method instantiateEagerComponents.

protected void instantiateEagerComponents() {
    List<String> components = new ArrayList<String>();
    for (String name : componentDefinitionRegistry.getComponentDefinitionNames()) {
        ComponentMetadata component = componentDefinitionRegistry.getComponentDefinition(name);
        boolean eager = component.getActivation() == ComponentMetadata.ACTIVATION_EAGER;
        if (component instanceof BeanMetadata) {
            BeanMetadata local = (BeanMetadata) component;
            eager &= MetadataUtil.isSingletonScope(local);
        }
        if (eager) {
            components.add(name);
        }
    }
    LOGGER.debug("Instantiating components: {}", components);
    try {
        repository.createAll(components);
    } catch (ComponentDefinitionException e) {
        throw e;
    } catch (Throwable t) {
        throw new ComponentDefinitionException("Unable to instantiate components", t);
    }
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) ArrayList(java.util.ArrayList) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata)

Example 29 with ComponentMetadata

use of org.osgi.service.blueprint.reflect.ComponentMetadata in project karaf by apache.

the class NamespaceHandler method parseCompleters.

private Metadata parseCompleters(ParserContext context, ComponentMetadata enclosingComponent, Element element) {
    MutableCollectionMetadata collection = context.createMetadata(MutableCollectionMetadata.class);
    collection.setCollectionClass(List.class);
    NodeList children = element.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child instanceof Element) {
            Metadata metadata;
            if (nodeNameEquals(child, REF)) {
                metadata = context.parseElement(RefMetadata.class, context.getEnclosingComponent(), (Element) child);
            } else if (nodeNameEquals(child, NULL)) {
                metadata = context.parseElement(NullMetadata.class, context.getEnclosingComponent(), (Element) child);
            } else if (nodeNameEquals(child, BEAN)) {
                metadata = context.parseElement(BeanMetadata.class, enclosingComponent, (Element) child);
            } else {
                throw new IllegalStateException("Unexpected element " + child.getNodeName());
            }
            collection.addValue(metadata);
        }
    }
    return collection;
}
Also used : RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) MutableRefMetadata(org.apache.aries.blueprint.mutable.MutableRefMetadata) IdRefMetadata(org.osgi.service.blueprint.reflect.IdRefMetadata) MutableIdRefMetadata(org.apache.aries.blueprint.mutable.MutableIdRefMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) MutableRefMetadata(org.apache.aries.blueprint.mutable.MutableRefMetadata) IdRefMetadata(org.osgi.service.blueprint.reflect.IdRefMetadata) MutableIdRefMetadata(org.apache.aries.blueprint.mutable.MutableIdRefMetadata) MutableServiceMetadata(org.apache.aries.blueprint.mutable.MutableServiceMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) NullMetadata(org.osgi.service.blueprint.reflect.NullMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableValueMetadata(org.apache.aries.blueprint.mutable.MutableValueMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata)

Example 30 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)

Aggregations

ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)45 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)22 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)17 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)17 Metadata (org.osgi.service.blueprint.reflect.Metadata)16 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)15 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)15 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)14 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)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 ArrayList (java.util.ArrayList)11 IdRefMetadata (org.osgi.service.blueprint.reflect.IdRefMetadata)11 Element (org.w3c.dom.Element)11 PropsMetadata (org.osgi.service.blueprint.reflect.PropsMetadata)10 NodeList (org.w3c.dom.NodeList)10 NonNullMetadata (org.osgi.service.blueprint.reflect.NonNullMetadata)9