Search in sources :

Example 1 with ComponentDefinitionRegistry

use of org.apache.aries.blueprint.ComponentDefinitionRegistry 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;
}
Also used : ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) LanguageResolver(org.apache.camel.spi.LanguageResolver) Bundle(org.osgi.framework.Bundle) 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 2 with ComponentDefinitionRegistry

use of org.apache.aries.blueprint.ComponentDefinitionRegistry 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;
}
Also used : ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) Bundle(org.osgi.framework.Bundle) ComponentResolver(org.apache.camel.spi.ComponentResolver) 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 3 with ComponentDefinitionRegistry

use of org.apache.aries.blueprint.ComponentDefinitionRegistry in project controller by opendaylight.

the class OpendaylightNamespaceHandler method registerNotificationServiceRefBean.

private static void registerNotificationServiceRefBean(final ParserContext context) {
    ComponentDefinitionRegistry registry = context.getComponentDefinitionRegistry();
    if (registry.getComponentDefinition(NOTIFICATION_SERVICE_NAME) == null) {
        MutableReferenceMetadata metadata = createServiceRef(context, NotificationService.class, null);
        metadata.setId(NOTIFICATION_SERVICE_NAME);
        registry.registerComponentDefinition(metadata);
    }
}
Also used : ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) MutableReferenceMetadata(org.apache.aries.blueprint.mutable.MutableReferenceMetadata)

Example 4 with ComponentDefinitionRegistry

use of org.apache.aries.blueprint.ComponentDefinitionRegistry in project controller by opendaylight.

the class OpendaylightNamespaceHandler method registerComponentProcessor.

private static MutableBeanMetadata registerComponentProcessor(final ParserContext context) {
    ComponentDefinitionRegistry registry = context.getComponentDefinitionRegistry();
    MutableBeanMetadata metadata = (MutableBeanMetadata) registry.getComponentDefinition(COMPONENT_PROCESSOR_NAME);
    if (metadata == null) {
        metadata = createBeanMetadata(context, COMPONENT_PROCESSOR_NAME, ComponentProcessor.class, false, true);
        metadata.setProcessor(true);
        addBlueprintBundleRefProperty(context, metadata);
        metadata.addProperty("blueprintContainerRestartService", createServiceRef(context, BlueprintContainerRestartService.class, null));
        LOG.debug("Registering ComponentProcessor bean: {}", metadata);
        registry.registerComponentDefinition(metadata);
    }
    return metadata;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) BlueprintContainerRestartService(org.opendaylight.controller.blueprint.BlueprintContainerRestartService)

Example 5 with ComponentDefinitionRegistry

use of org.apache.aries.blueprint.ComponentDefinitionRegistry in project controller by opendaylight.

the class OpendaylightNamespaceHandler method registerRefBean.

private static void registerRefBean(final ParserContext context, final String name, final Class<?> clazz) {
    ComponentDefinitionRegistry registry = context.getComponentDefinitionRegistry();
    if (registry.getComponentDefinition(name) == null) {
        MutableReferenceMetadata metadata = createServiceRef(context, clazz, null);
        metadata.setId(name);
        registry.registerComponentDefinition(metadata);
    }
}
Also used : ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) MutableReferenceMetadata(org.apache.aries.blueprint.mutable.MutableReferenceMetadata)

Aggregations

ComponentDefinitionRegistry (org.apache.aries.blueprint.ComponentDefinitionRegistry)29 MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)6 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)6 MutableReferenceMetadata (org.apache.aries.blueprint.mutable.MutableReferenceMetadata)5 Test (org.junit.Test)5 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)5 URL (java.net.URL)4 MutablePassThroughMetadata (org.apache.aries.blueprint.mutable.MutablePassThroughMetadata)4 URI (java.net.URI)3 PassThroughMetadata (org.apache.aries.blueprint.PassThroughMetadata)3 ParserService (org.apache.aries.blueprint.services.ParserService)3 Bundle (org.osgi.framework.Bundle)3 ComponentDefinitionRegistryImpl (org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl)2 NamespaceHandlerSet (org.apache.aries.blueprint.parser.NamespaceHandlerSet)2 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)2 Element (org.w3c.dom.Element)2 IOException (java.io.IOException)1 TransactionManager (javax.transaction.TransactionManager)1 ExportedService (org.apache.aries.application.modelling.ExportedService)1 ImportedService (org.apache.aries.application.modelling.ImportedService)1