Search in sources :

Example 6 with PassThroughMetadata

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

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

the class NSHandlerOne method parse.

// process elements
public Metadata parse(Element element, ParserContext context) {
    Metadata retval = null;
    if (element.getLocalName().equals(ELT_NAME)) {
        final String id = element.getAttributeNS(NSURI, ATTRIB_ONE);
        final String value = element.getAttributeNS(NSURI, ATTRIB_TWO);
        PassThroughMetadata ptm = new PassThroughMetadata() {

            public String getId() {
                return id;
            }

            // not used currently
            public List<String> getDependsOn() {
                return null;
            }

            // also not used currently
            public int getActivation() {
                return 0;
            }

            public Object getObject() {
                return value;
            }
        };
        retval = ptm;
    }
    return retval;
}
Also used : Metadata(org.osgi.service.blueprint.reflect.Metadata) 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) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata)

Example 8 with PassThroughMetadata

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

the class IncorrectNamespaceHandler 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 9 with PassThroughMetadata

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

the class Aries1503aNamespaceHandler 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)

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