Search in sources :

Example 6 with MutableReferenceMetadata

use of org.apache.aries.blueprint.mutable.MutableReferenceMetadata in project aries by apache.

the class CmNamespaceHandler method createServiceRef.

private MutableReferenceMetadata createServiceRef(ParserContext context, Class<?> cls, String filter) {
    MutableReferenceMetadata m = context.createMetadata(MutableReferenceMetadata.class);
    m.setRuntimeInterface(cls);
    m.setInterface(cls.getName());
    m.setActivation(ReferenceMetadata.ACTIVATION_EAGER);
    m.setAvailability(ReferenceMetadata.AVAILABILITY_MANDATORY);
    if (filter != null) {
        m.setFilter(filter);
    }
    return m;
}
Also used : MutableReferenceMetadata(org.apache.aries.blueprint.mutable.MutableReferenceMetadata)

Example 7 with MutableReferenceMetadata

use of org.apache.aries.blueprint.mutable.MutableReferenceMetadata 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

MutableReferenceMetadata (org.apache.aries.blueprint.mutable.MutableReferenceMetadata)7 ComponentDefinitionRegistry (org.apache.aries.blueprint.ComponentDefinitionRegistry)3 PassThroughMetadata (org.apache.aries.blueprint.PassThroughMetadata)3 MutablePassThroughMetadata (org.apache.aries.blueprint.mutable.MutablePassThroughMetadata)3 Bundle (org.osgi.framework.Bundle)3 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)3 Element (org.w3c.dom.Element)2 ArrayList (java.util.ArrayList)1 MutableRefMetadata (org.apache.aries.blueprint.mutable.MutableRefMetadata)1 ComponentResolver (org.apache.camel.spi.ComponentResolver)1 DataFormatResolver (org.apache.camel.spi.DataFormatResolver)1 LanguageResolver (org.apache.camel.spi.LanguageResolver)1 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)1 Target (org.osgi.service.blueprint.reflect.Target)1 Node (org.w3c.dom.Node)1