Search in sources :

Example 11 with ComponentDefinitionRegistry

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

the class AbstractParserProxy method parse.

public List<? extends WrappedServiceMetadata> parse(InputStream blueprintToParse) throws Exception {
    _logger.debug(LOG_ENTRY, "parse", new Object[] { blueprintToParse });
    ComponentDefinitionRegistry cdr = parseCDR(blueprintToParse);
    List<? extends WrappedServiceMetadata> result = parseCDRForServices(cdr, true);
    _logger.debug(LOG_EXIT, "parse", new Object[] { result });
    return result;
}
Also used : ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry)

Example 12 with ComponentDefinitionRegistry

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

the class AbstractParserProxy method parseAllServiceElements.

public ParsedServiceElements parseAllServiceElements(InputStream blueprintToParse) throws Exception {
    _logger.debug(LOG_ENTRY, "parseAllServiceElements", new Object[] { blueprintToParse });
    ComponentDefinitionRegistry cdr = parseCDR(blueprintToParse);
    Collection<ExportedService> services = parseCDRForServices(cdr, false);
    Collection<ImportedService> references = parseCDRForReferences(cdr);
    ParsedServiceElements result = _modellingManager.getParsedServiceElements(services, references);
    _logger.debug(LOG_EXIT, "parseAllServiceElements", new Object[] { result });
    return result;
}
Also used : ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) ExportedService(org.apache.aries.application.modelling.ExportedService) ImportedService(org.apache.aries.application.modelling.ImportedService) ParsedServiceElements(org.apache.aries.application.modelling.ParsedServiceElements)

Example 13 with ComponentDefinitionRegistry

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

the class BlueprintNamespaceHandler method parse.

@Override
public Metadata parse(Element element, ParserContext parserContext) {
    try {
        // Get the spring context
        org.springframework.beans.factory.xml.ParserContext springContext = getOrCreateParserContext(parserContext);
        // Parse spring bean
        BeanDefinition bd = springHandler.parse(element, springContext);
        for (String name : springContext.getRegistry().getBeanDefinitionNames()) {
            if (springContext.getRegistry().getBeanDefinition(name) == bd) {
                ComponentDefinitionRegistry registry = parserContext.getComponentDefinitionRegistry();
                if (registry.containsComponentDefinition(name)) {
                    // Hack: we can't really make the difference between a top level bean
                    // and an inlined bean when using custom (eventually nested) namespaces.
                    // To work around the problem, the BlueprintBeanFactory will always register
                    // a BeanMetadata for each bean, but here, we unregister it and return it instead
                    // so that the caller is responsible for registering the metadata.
                    ComponentMetadata metadata = registry.getComponentDefinition(name);
                    registry.removeComponentDefinition(name);
                    return metadata;
                }
            }
        }
        return null;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata)

Example 14 with ComponentDefinitionRegistry

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

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

the class CmNamespaceHandler method decorate.

public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) {
    LOGGER.debug("Decorating node {{}}{}", node.getNamespaceURI(), node.getLocalName());
    ComponentDefinitionRegistry registry = context.getComponentDefinitionRegistry();
    registerManagedObjectManager(context, registry);
    if (node instanceof Element) {
        if (nodeNameEquals(node, MANAGED_PROPERTIES_ELEMENT)) {
            return decorateManagedProperties(context, (Element) node, component);
        } else if (nodeNameEquals(node, CM_PROPERTIES_ELEMENT)) {
            return decorateCmProperties(context, (Element) node, component);
        } else {
            throw new ComponentDefinitionException("Unsupported element: " + node.getNodeName());
        }
    } else {
        throw new ComponentDefinitionException("Illegal use of blueprint cm namespace");
    }
}
Also used : ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) Element(org.w3c.dom.Element)

Aggregations

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