Search in sources :

Example 11 with Component

use of org.exoplatform.container.xml.Component in project kernel by exoplatform.

the class TestComponentPluginProfile method testFooProfile.

public void testFooProfile() throws Exception {
    Configuration config = getConfiguration("component-plugin-configuration.xml", "foo");
    Component component = config.getComponent("Component");
    assertEquals(2, component.getComponentPlugins().size());
}
Also used : Configuration(org.exoplatform.container.xml.Configuration) Component(org.exoplatform.container.xml.Component)

Example 12 with Component

use of org.exoplatform.container.xml.Component in project kernel by exoplatform.

the class GuiceContainer method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() {
    ConfigurationManager cm = super.getComponentInstanceOfType(ConfigurationManager.class, false);
    // We check if the component has been defined in the configuration of the current container
    // The goal is to enable the GuicegContainer only if it is needed
    Component component = cm.getComponent(ModuleProvider.class);
    if (component == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("No ModuleProvider has been defined, thus the GuiceContainer will be disabled." + " To enable the Guice Integration please define a ModuleProvider");
        }
    } else {
        ModuleProvider provider = super.getComponentInstanceOfType(ModuleProvider.class, false);
        injector = Guice.createInjector(provider.getModule(), new AbstractModule() {

            @SuppressWarnings({ "unchecked", "rawtypes" })
            @Override
            protected void configure() {
                Collection<ComponentAdapter<?>> adapters = delegate.getComponentAdapters();
                Binder binder = binder();
                for (ComponentAdapter<?> adapter : adapters) {
                    Object key = adapter.getComponentKey();
                    Class<?> type;
                    Annotation annotation = null;
                    Class<? extends Annotation> annotationType = null;
                    if (key instanceof Class<?> && !((Class<?>) key).isAnnotation()) {
                        type = (Class<?>) key;
                    } else {
                        if (key instanceof String) {
                            annotation = Names.named((String) key);
                        } else if (key instanceof Class<?>) {
                            annotationType = (Class<? extends Annotation>) key;
                        }
                        type = adapter.getComponentImplementation();
                    }
                    if (annotation == null && annotationType == null) {
                        binder.bind(type).toProvider(new ComponentAdapterProvider(type, adapter));
                    } else {
                        // As we don't know the type, we will bind it for each super classes and interfaces too
                        ComponentAdapterProvider provider = new ComponentAdapterProvider(type, adapter);
                        bindAll(binder, type, provider, annotation, annotationType);
                    }
                }
            }
        });
        LOG.info("A GuiceContainer has been enabled using the ModuleProvider " + provider.getClass());
    }
    super.start();
}
Also used : Annotation(java.lang.annotation.Annotation) AbstractModule(com.google.inject.AbstractModule) Binder(com.google.inject.Binder) Component(org.exoplatform.container.xml.Component) ConfigurationManager(org.exoplatform.container.configuration.ConfigurationManager) AbstractComponentAdapter(org.exoplatform.container.AbstractComponentAdapter) ComponentAdapter(org.exoplatform.container.spi.ComponentAdapter)

Example 13 with Component

use of org.exoplatform.container.xml.Component in project kernel by exoplatform.

the class SpringContainer method start.

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void start() {
    ConfigurationManager cm = super.getComponentInstanceOfType(ConfigurationManager.class, false);
    // We check if the component has been defined in the configuration of the current container
    // The goal is to enable the SpringContainer only if it is needed
    Component component = cm.getComponent(ApplicationContextProvider.class);
    if (component == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("No ApplicationContextProvider has been defined, thus the SpringContainer will be disabled." + " To enable the Spring Integration please define an ApplicationContextProvider");
        }
    } else {
        DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
        bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());
        Collection<ComponentAdapter<?>> adapters = delegate.getComponentAdapters();
        for (ComponentAdapter<?> adapter : adapters) {
            Object key = adapter.getComponentKey();
            String name = keyToBeanName(key);
            String factoryName = name + "#factory";
            RootBeanDefinition def = new RootBeanDefinition(adapter.getComponentImplementation(), AbstractBeanDefinition.AUTOWIRE_NO, false);
            def.setScope(BeanDefinition.SCOPE_PROTOTYPE);
            def.setFactoryBeanName(factoryName);
            def.setFactoryMethodName("getInstance");
            def.setLazyInit(true);
            def.setTargetType(adapter.getComponentImplementation());
            if (key instanceof String) {
                def.addQualifier(new AutowireCandidateQualifier(Named.class, key));
            } else if (key instanceof Class<?> && ((Class<?>) key).isAnnotation()) {
                def.addQualifier(new AutowireCandidateQualifier((Class<?>) key));
            } else {
                def.setPrimary(true);
            }
            bf.registerBeanDefinition(name, def);
            bf.registerSingleton(factoryName, new ComponentAdapterFactoryBean(adapter));
        }
        GenericApplicationContext parentContext = new GenericApplicationContext(bf);
        parentContext.refresh();
        ApplicationContextProvider provider = super.getComponentInstanceOfType(ApplicationContextProvider.class, false);
        ctx = provider.getApplicationContext(parentContext);
        LOG.info("A SpringContainer has been enabled using the ApplicationContextProvider " + provider.getClass());
    }
    super.start();
}
Also used : Named(javax.inject.Named) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) AutowireCandidateQualifier(org.springframework.beans.factory.support.AutowireCandidateQualifier) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) QualifierAnnotationAutowireCandidateResolver(org.springframework.beans.factory.annotation.QualifierAnnotationAutowireCandidateResolver) Component(org.exoplatform.container.xml.Component) ConfigurationManager(org.exoplatform.container.configuration.ConfigurationManager) ComponentAdapter(org.exoplatform.container.spi.ComponentAdapter) AbstractComponentAdapter(org.exoplatform.container.AbstractComponentAdapter)

Example 14 with Component

use of org.exoplatform.container.xml.Component in project kernel by exoplatform.

the class TestField method getConfiguredCollection.

private XMLCollection getConfiguredCollection(String... profiles) throws Exception {
    Configuration config = getConfiguration("field-configuration.xml", profiles);
    Component a = config.getComponent(InitParamsHolder.class.getName());
    ObjectParameter op = a.getInitParams().getObjectParam("test.configuration");
    XMLObject o = op.getXMLObject();
    XMLField xf = o.getField("role");
    return xf.getCollection();
}
Also used : XMLField(org.exoplatform.xml.object.XMLField) Configuration(org.exoplatform.container.xml.Configuration) ObjectParameter(org.exoplatform.container.xml.ObjectParameter) XMLObject(org.exoplatform.xml.object.XMLObject) Component(org.exoplatform.container.xml.Component)

Example 15 with Component

use of org.exoplatform.container.xml.Component in project kernel by exoplatform.

the class TestInitParamProfile method testFooBarProfiles.

public void testFooBarProfiles() throws Exception {
    Configuration config = getConfiguration("init-param-configuration.xml", "foo", "bar");
    Component component = config.getComponent("Component");
    InitParams initParams = component.getInitParams();
    ValueParam valueParam = initParams.getValueParam("param");
    assertEquals("bar", valueParam.getValue());
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) Configuration(org.exoplatform.container.xml.Configuration) Component(org.exoplatform.container.xml.Component) ValueParam(org.exoplatform.container.xml.ValueParam)

Aggregations

Component (org.exoplatform.container.xml.Component)16 Configuration (org.exoplatform.container.xml.Configuration)9 ConfigurationManager (org.exoplatform.container.configuration.ConfigurationManager)6 InitParams (org.exoplatform.container.xml.InitParams)5 ObjectParameter (org.exoplatform.container.xml.ObjectParameter)4 ValueParam (org.exoplatform.container.xml.ValueParam)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 PrivilegedActionException (java.security.PrivilegedActionException)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 AbstractComponentAdapter (org.exoplatform.container.AbstractComponentAdapter)2 ComponentTask (org.exoplatform.container.ComponentTask)2 CyclicDependencyException (org.exoplatform.container.CyclicDependencyException)2 Dependency (org.exoplatform.container.Dependency)2 DefinitionException (org.exoplatform.container.context.DefinitionException)2 ComponentAdapter (org.exoplatform.container.spi.ComponentAdapter)2 ExternalComponentPlugins (org.exoplatform.container.xml.ExternalComponentPlugins)2 XMLField (org.exoplatform.xml.object.XMLField)2 XMLObject (org.exoplatform.xml.object.XMLObject)2 IBindingFactory (org.jibx.runtime.IBindingFactory)2