Search in sources :

Example 26 with ComponentDefinitionRegistry

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

the class BeanRecipe method addInterceptors.

private Object addInterceptors(final Object original, Collection<Class<?>> requiredInterfaces) throws ComponentDefinitionException {
    Object intercepted = null;
    if (requiredInterfaces.isEmpty())
        requiredInterfaces.add(original.getClass());
    ComponentDefinitionRegistry reg = blueprintContainer.getComponentDefinitionRegistry();
    List<Interceptor> interceptors = reg.getInterceptors(interceptorLookupKey);
    if (interceptors != null && interceptors.size() > 0) {
        /* BLUEPRINT-NOOSGI
            try {
                Bundle b = FrameworkUtil.getBundle(original.getClass());
                if (b == null) {
                    // we have a class from the framework parent, so use our bundle for proxying.
                    b = blueprintContainer.getBundleContext().getBundle();
                }
                intercepted = blueprintContainer.getProxyManager().createInterceptingProxy(b,
                        requiredInterfaces, original, new Collaborator(interceptorLookupKey, interceptors));
            } catch (org.apache.aries.proxy.UnableToProxyException e) {
                Bundle b = blueprintContainer.getBundleContext().getBundle();
                throw new ComponentDefinitionException("Unable to create proxy for bean " + name + " in bundle " + b.getSymbolicName() + " version " + b.getVersion(), e);
            }
            */
        throw new ComponentDefinitionException("Unable to create proxy for bean " + name + ".  Not supported in blueprint-noosgi");
    } else {
        intercepted = original;
    }
    return intercepted;
}
Also used : ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) Interceptor(org.apache.aries.blueprint.Interceptor)

Example 27 with ComponentDefinitionRegistry

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

the class BlueprintNamespaceHandler method getOrCreateParserContext.

private org.springframework.beans.factory.xml.ParserContext getOrCreateParserContext(ParserContext parserContext) {
    ComponentDefinitionRegistry registry = parserContext.getComponentDefinitionRegistry();
    ExtendedBlueprintContainer container = getBlueprintContainer(parserContext);
    // Create spring application context
    SpringApplicationContext applicationContext = getPassThrough(parserContext, SPRING_APPLICATION_CONTEXT_ID, SpringApplicationContext.class);
    if (applicationContext == null) {
        applicationContext = new SpringApplicationContext(container);
        registry.registerComponentDefinition(createPassThrough(parserContext, SPRING_APPLICATION_CONTEXT_ID, applicationContext, "destroy"));
    }
    // Create registry
    DefaultListableBeanFactory beanFactory = getPassThrough(parserContext, SPRING_BEAN_FACTORY_ID, DefaultListableBeanFactory.class);
    if (beanFactory == null) {
        beanFactory = applicationContext.getBeanFactory();
        registry.registerComponentDefinition(createPassThrough(parserContext, SPRING_BEAN_FACTORY_ID, beanFactory));
    }
    // Create spring parser context
    org.springframework.beans.factory.xml.ParserContext springParserContext = getPassThrough(parserContext, SPRING_CONTEXT_ID, org.springframework.beans.factory.xml.ParserContext.class);
    if (springParserContext == null) {
        // Create spring context
        springParserContext = createSpringParserContext(parserContext, beanFactory);
        registry.registerComponentDefinition(createPassThrough(parserContext, SPRING_CONTEXT_ID, springParserContext));
    }
    // Create processor
    if (!parserContext.getComponentDefinitionRegistry().containsComponentDefinition(SPRING_BEAN_PROCESSOR_ID)) {
        MutableBeanMetadata bm = parserContext.createMetadata(MutableBeanMetadata.class);
        bm.setId(SPRING_BEAN_PROCESSOR_ID);
        bm.setProcessor(true);
        bm.setScope(BeanMetadata.SCOPE_SINGLETON);
        bm.setRuntimeClass(SpringBeanProcessor.class);
        bm.setActivation(BeanMetadata.ACTIVATION_EAGER);
        bm.addArgument(createRef(parserContext, "blueprintBundleContext"), null, 0);
        bm.addArgument(createRef(parserContext, "blueprintContainer"), null, 0);
        bm.addArgument(createRef(parserContext, SPRING_APPLICATION_CONTEXT_ID), null, 0);
        registry.registerComponentDefinition(bm);
    }
    // Add the namespace handlers' bundle to the application context classloader
    for (URI uri : parserContext.getNamespaces()) {
        NamespaceHandler ns = parserContext.getNamespaceHandler(uri);
        if (ns instanceof BlueprintNamespaceHandler) {
            applicationContext.addSourceBundle(((BlueprintNamespaceHandler) ns).bundle);
        }
    }
    return springParserContext;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) NamespaceHandler(org.apache.aries.blueprint.NamespaceHandler) ExtendedBlueprintContainer(org.apache.aries.blueprint.services.ExtendedBlueprintContainer) URI(java.net.URI)

Example 28 with ComponentDefinitionRegistry

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

the class BlueprintBeanFactory method registerBeanDefinition.

@Override
public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) throws BeanDefinitionStoreException {
    ComponentDefinitionRegistry registry = container.getComponentDefinitionRegistry();
    ComponentMetadata metadata = registry.getComponentDefinition(beanName);
    if (metadata != null && !(metadata instanceof SpringMetadata)) {
        throw new BeanDefinitionStoreException(beanDefinition.getResourceDescription(), beanName, "Cannot register bean definition [" + beanDefinition + "] for bean '" + beanName + "': There is already bound.");
    }
    super.registerBeanDefinition(beanName, beanDefinition);
    if (!beanDefinition.isAbstract()) {
        registry.registerComponentDefinition(new SpringMetadata(beanName));
    }
}
Also used : ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata)

Example 29 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)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