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());
}
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();
}
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();
}
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();
}
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());
}
Aggregations