Search in sources :

Example 1 with PassThroughMetadata

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

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

use of org.apache.aries.blueprint.PassThroughMetadata in project admin-console-beta by connexta.

the class BundleUtils method populateServices.

private void populateServices(Bundle bundle, BundleField toPopulate) {
    Optional<BlueprintContainer> blueprintContainer = getBlueprintContainer(bundle);
    if (blueprintContainer.isPresent()) {
        List<ComponentMetadata> cmpMetas = blueprintContainer.get().getComponentIds().stream().map(id -> blueprintContainer.get().getComponentMetadata(id)).collect(Collectors.toList());
        for (ComponentMetadata meta : cmpMetas) {
            if (meta instanceof ReferenceListMetadata) {
                populateServiceRefLists((ReferenceListMetadata) meta, bundle, toPopulate);
            } else if (meta instanceof ReferenceMetadata) {
                populateServiceRef((ReferenceMetadata) meta, bundle, toPopulate);
            } else if (meta instanceof BeanMetadata || meta instanceof ServiceMetadata || meta instanceof PassThroughMetadata) {
                continue;
            } else {
                LOGGER.warn("Unable to handle blueprint metadata of type {} for bundle {}.", meta.getClass(), bundle.getSymbolicName());
            }
        }
        getRegisteredServices(bundle).forEach(ref -> toPopulate.addService(createServiceField(ref)));
    }
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) ServiceReferenceField(org.codice.ddf.admin.query.dev.system.fields.ServiceReferenceField) ServiceReferenceListField(org.codice.ddf.admin.query.dev.system.fields.ServiceReferenceListField) BundleService(org.apache.karaf.bundle.core.BundleService) LoggerFactory(org.slf4j.LoggerFactory) PackageField(org.codice.ddf.admin.query.dev.system.fields.PackageField) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) ArrayList(java.util.ArrayList) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) Parser(org.apache.felix.utils.manifest.Parser) ServiceField(org.codice.ddf.admin.query.dev.system.fields.ServiceField) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) Clause(org.apache.felix.utils.manifest.Clause) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) GetBundles(org.codice.ddf.admin.query.dev.system.discover.GetBundles) Bundle(org.osgi.framework.Bundle) BundleField(org.codice.ddf.admin.query.dev.system.fields.BundleField) ServiceReference(org.osgi.framework.ServiceReference) Logger(org.slf4j.Logger) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata) Collectors(java.util.stream.Collectors) BundleContext(org.osgi.framework.BundleContext) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) List(java.util.List) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata)

Example 4 with PassThroughMetadata

use of org.apache.aries.blueprint.PassThroughMetadata in project aries by apache.

the class Aries1503bNamespaceHandler method parse.

@Override
public Metadata parse(Element element, ParserContext context) {
    MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
    metadata.setProcessor(true);
    metadata.setId("aries-1503");
    metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
    metadata.addArgument(new PassThroughMetadata() {

        @Override
        public Object getObject() {
            return "ARIES-1503";
        }

        @Override
        public String getId() {
            return "aries-1503-arg";
        }

        @Override
        public int getActivation() {
            return 0;
        }

        @Override
        public List<String> getDependsOn() {
            return null;
        }
    }, null, 0);
    metadata.setRuntimeClass(String.class);
    return metadata;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) List(java.util.List)

Example 5 with PassThroughMetadata

use of org.apache.aries.blueprint.PassThroughMetadata in project aries by apache.

the class Aries1682NamespaceHandler method parse.

@Override
public Metadata parse(Element element, ParserContext context) {
    MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
    metadata.setProcessor(true);
    metadata.setId("aries-1682");
    metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
    metadata.addArgument(new PassThroughMetadata() {

        @Override
        public Object getObject() {
            return "ARIES-1682";
        }

        @Override
        public String getId() {
            return "aries-1682-arg";
        }

        @Override
        public int getActivation() {
            return 0;
        }

        @Override
        public List<String> getDependsOn() {
            return null;
        }
    }, null, 0);
    metadata.setRuntimeClass(String.class);
    return metadata;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) List(java.util.List)

Aggregations

PassThroughMetadata (org.apache.aries.blueprint.PassThroughMetadata)9 List (java.util.List)5 MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)5 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)5 Bundle (org.osgi.framework.Bundle)4 ComponentDefinitionRegistry (org.apache.aries.blueprint.ComponentDefinitionRegistry)3 MutablePassThroughMetadata (org.apache.aries.blueprint.mutable.MutablePassThroughMetadata)3 MutableReferenceMetadata (org.apache.aries.blueprint.mutable.MutableReferenceMetadata)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)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 CollectionUtils (org.apache.commons.collections.CollectionUtils)1