Search in sources :

Example 16 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 17 with ComponentDefinitionRegistry

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

the class AbstractParserProxy method parse.

public List<? extends WrappedServiceMetadata> parse(List<URL> blueprintsToParse) throws Exception {
    _logger.debug(LOG_ENTRY, "parse", new Object[] { blueprintsToParse });
    ComponentDefinitionRegistry cdr = parseCDR(blueprintsToParse);
    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 18 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 19 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 handler's bundle to the application context classloader
    applicationContext.addSourceBundle(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) ExtendedBlueprintContainer(org.apache.aries.blueprint.services.ExtendedBlueprintContainer)

Example 20 with ComponentDefinitionRegistry

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

the class TxNamespaceHandler method parseElement.

private void parseElement(Element elt, ParserContext pc) {
    LOGGER.debug("parser asked to parse element {} ", elt.getNodeName());
    ComponentDefinitionRegistry cdr = pc.getComponentDefinitionRegistry();
    if ("enable".equals(elt.getLocalName())) {
        Node n = elt.getChildNodes().item(0);
        if ((n == null || Boolean.parseBoolean(n.getNodeValue())) && !cdr.containsComponentDefinition(ANNOTATION_PARSER_BEAN_NAME)) {
            LOGGER.debug("Enabling annotation based transactions");
            MutableBeanMetadata meta = createAnnotationParserBean(pc, cdr);
            cdr.registerComponentDefinition(meta);
        }
    }
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) Node(org.w3c.dom.Node)

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