use of org.exoplatform.container.xml.ExternalComponentPlugins in project kernel by exoplatform.
the class TestExternalComponentPluginsProfile method testFooProfile.
public void testFooProfile() throws Exception {
Configuration config = getConfiguration("external-component-plugins.xml", "foo");
int size = 0;
for (Iterator<ExternalComponentPlugins> it = config.getExternalComponentPluginsIterator(); it.hasNext(); ) {
ExternalComponentPlugins ecp = it.next();
assertEquals(2, ecp.getComponentPlugins().size());
size++;
}
assertEquals(2, size);
}
use of org.exoplatform.container.xml.ExternalComponentPlugins in project kernel by exoplatform.
the class MX4JComponentAdapterMT method getInitTasks.
/**
* {@inheritDoc}
*/
protected Collection<ComponentTask<Void>> getInitTasks() {
Component component = null;
String componentKey;
boolean debug = false;
// Get the component
Object key = getComponentKey();
if (key instanceof String)
componentKey = (String) key;
else
componentKey = ((Class<?>) key).getName();
try {
ConfigurationManager manager = (ConfigurationManager) exocontainer.getComponentInstanceOfType(ConfigurationManager.class);
component = manager == null ? null : manager.getComponent(componentKey);
if (component != null) {
debug = component.getShowDeployInfo();
}
List<ComponentTask<Void>> tasks = new ArrayList<ComponentTask<Void>>();
Set<Dependency> dependencies = new HashSet<Dependency>();
final Class<T> implementationClass = getComponentImplementation();
boolean isSingleton = this.isSingleton;
boolean isInitialized = this.isInitialized;
if (debug)
LOG.debug("==> create component : " + implementationClass.getName());
boolean hasInjectableConstructor = !isSingleton || ContainerUtil.hasInjectableConstructor(implementationClass);
boolean hasOnlyEmptyPublicConstructor = !isSingleton || ContainerUtil.hasOnlyEmptyPublicConstructor(implementationClass);
if (hasInjectableConstructor || hasOnlyEmptyPublicConstructor) {
// There is at least one constructor JSR 330 compliant or we already know
// that it is not a singleton such that the new behavior is expected
List<Dependency> lDependencies = new ArrayList<Dependency>();
boolean isInjectPresent = container.initializeComponent(implementationClass, lDependencies, tasks, this);
dependencies.addAll(lDependencies);
isSingleton = manageScope(isSingleton, isInitialized, hasInjectableConstructor, isInjectPresent);
} else if (!isInitialized) {
// The adapter has not been initialized yet
// The old behavior is expected as there is no constructor JSR 330 compliant
isSingleton = this.isSingleton = true;
scope.set(Singleton.class);
}
if (component != null && component.getComponentPlugins() != null) {
addComponentPlugin(tasks, dependencies, debug, component.getComponentPlugins());
}
ExternalComponentPlugins ecplugins = manager == null ? null : manager.getConfiguration().getExternalComponentPlugins(componentKey);
if (ecplugins != null) {
addComponentPlugin(tasks, dependencies, debug, ecplugins.getComponentPlugins());
}
initDependencies.compareAndSet(null, new CopyOnWriteArraySet<Dependency>(dependencies));
tasks.add(new ComponentTask<Void>("initialize component " + getComponentImplementation().getName(), container, this, ComponentTaskType.INIT) {
public Void execute(CreationalContextComponentAdapter<?> cCtx) throws Exception {
// check if component implement the ComponentLifecycle
if (cCtx.get() instanceof ComponentLifecycle && exocontainer instanceof ExoContainer) {
ComponentLifecycle lc = (ComponentLifecycle) cCtx.get();
lc.initComponent((ExoContainer) exocontainer);
}
return null;
}
});
if (!isInitialized) {
this.isInitialized = true;
}
return tasks;
} catch (Exception e) {
String msg = "Cannot initialize component " + getComponentImplementation();
if (component != null) {
msg = "Cannot initialize component key=" + component.getKey() + " type=" + component.getType() + " found at " + component.getDocumentURL();
}
throw new RuntimeException(msg, e);
}
}
use of org.exoplatform.container.xml.ExternalComponentPlugins in project kernel by exoplatform.
the class MX4JComponentAdapter method createInstance.
private T createInstance(final CreationalContextComponentAdapter<T> ctx, final Component component, final ConfigurationManager manager, final String componentKey, final InitParams params, final boolean debug) throws Exception {
try {
return SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<T>() {
public T run() throws Exception {
T instance;
final Class<T> implementationClass = getComponentImplementation();
// Please note that we cannot fully initialize the Object "instance_" before releasing other
// threads because it could cause StackOverflowError due to recursive calls
instance = exocontainer.createComponent(implementationClass, params);
if (instance_ != null) {
// to component plugins
return instance_;
} else if (ctx.get() != null)
return ctx.get();
ctx.push(instance);
boolean isSingleton = MX4JComponentAdapter.this.isSingleton;
boolean isInitialized = MX4JComponentAdapter.this.isInitialized;
if (debug)
LOG.debug("==> create component : " + instance);
boolean hasInjectableConstructor = !isSingleton || ContainerUtil.hasInjectableConstructor(implementationClass);
boolean hasOnlyEmptyPublicConstructor = !isSingleton || ContainerUtil.hasOnlyEmptyPublicConstructor(implementationClass);
if (hasInjectableConstructor || hasOnlyEmptyPublicConstructor) {
// There is at least one constructor JSR 330 compliant or we already know
// that it is not a singleton such that the new behavior is expected
boolean isInjectPresent = container.initializeComponent(instance);
isSingleton = manageScope(isSingleton, isInitialized, hasInjectableConstructor, isInjectPresent);
} else if (!isInitialized) {
// The adapter has not been initialized yet
// The old behavior is expected as there is no constructor JSR 330 compliant
isSingleton = MX4JComponentAdapter.this.isSingleton = true;
scope.set(Singleton.class);
}
if (component != null && component.getComponentPlugins() != null) {
addComponentPlugin(debug, instance, component.getComponentPlugins(), exocontainer);
}
ExternalComponentPlugins ecplugins = manager == null ? null : manager.getConfiguration().getExternalComponentPlugins(componentKey);
if (ecplugins != null) {
addComponentPlugin(debug, instance, ecplugins.getComponentPlugins(), exocontainer);
}
// check if component implement the ComponentLifecycle
if (instance instanceof ComponentLifecycle) {
ComponentLifecycle lc = (ComponentLifecycle) instance;
lc.initComponent(exocontainer);
}
if (!isInitialized) {
if (isSingleton) {
instance_ = instance;
}
MX4JComponentAdapter.this.isInitialized = true;
}
return instance;
}
});
} catch (PrivilegedActionException e) {
Throwable cause = e.getCause();
if (cause instanceof Exception) {
throw (Exception) cause;
}
throw new Exception(cause);
}
}
use of org.exoplatform.container.xml.ExternalComponentPlugins in project kernel by exoplatform.
the class TestConfigurationXML method testTrimValue.
@SuppressWarnings("unchecked")
public void testTrimValue() throws Exception {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("test-trim-value.xml");
assertNotNull(is);
try {
IBindingFactory bfact = BindingDirectory.getFactory(XMLObject.class);
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
Configuration conf = (Configuration) uctx.unmarshalDocument(is, null);
assertNotNull(conf);
Iterator it = conf.getContainerLifecyclePluginIterator();
assertNotNull(it);
assertTrue(it.hasNext());
ContainerLifecyclePlugin conlp = (ContainerLifecyclePlugin) it.next();
assertEquals("container-lifecycle-plugin-type", conlp.getType());
assertNotNull(conlp.getInitParams());
assertEquals("container-lifecycle-plugin-value-param-value", (conlp.getInitParams().getValueParam("container-lifecycle-plugin-value-param-name")).getValue());
it = conf.getComponentLifecyclePluginIterator();
assertNotNull(it);
assertTrue(it.hasNext());
ComponentLifecyclePlugin comlp = (ComponentLifecyclePlugin) it.next();
assertEquals("component-lifecycle-plugin", comlp.getType());
ManageableComponents mc = comlp.getManageableComponents();
assertNotNull(mc);
assertEquals("manageable-components-component-type", mc.getComponentsType().get(0));
ValuesParam valuesParam = comlp.getInitParams().getValuesParam("component-lifecycle-plugin-values-param-name");
assertNotNull(valuesParam);
assertNotNull(valuesParam.getValues());
assertTrue(valuesParam.getValues().contains("component-lifecycle-plugin-values-param-value1"));
assertTrue(valuesParam.getValues().contains("component-lifecycle-plugin-values-param-value2"));
Component c = conf.getComponent("component-key1");
assertNotNull(c);
assertEquals("component-type1", c.getType());
PropertiesParam propertiesParam = c.getInitParams().getPropertiesParam("component-key1-properties-param-name");
assertNotNull(propertiesParam);
assertEquals("component-key1-properties-param-prop-value", propertiesParam.getProperty("component-key1-properties-param-prop-name"));
c = conf.getComponent("component-type2");
assertNotNull(c);
ObjectParameter objectParameter = c.getInitParams().getObjectParam("component-key2-object-param-name");
assertNotNull(objectParameter);
MyObject o = (MyObject) objectParameter.getObject();
assertNotNull(o);
assertEquals("string-value", o.field1);
assertEquals(1, o.field2);
assertEquals(1l, o.field3);
assertEquals(1d, o.field4);
assertEquals(true, o.field5);
assertNotNull(o.field6);
assertEquals("entry-value", o.field6.get("entry-name"));
assertNotNull(o.field7);
assertTrue(o.field7.contains("string-value"));
assertNotNull(o.field8);
assertEquals(1, o.field8[0]);
List list = c.getComponentPlugins();
assertNotNull(list);
assertFalse(list.isEmpty());
ComponentPlugin cp = (ComponentPlugin) list.get(0);
assertEquals("component-plugins-name", cp.getName());
assertEquals("set-method-name", cp.getSetMethod());
assertEquals("component-plugins-type", cp.getType());
assertEquals(1, cp.getPriority());
it = conf.getExternalComponentPluginsIterator();
assertNotNull(it);
assertTrue(it.hasNext());
ExternalComponentPlugins ecps = (ExternalComponentPlugins) it.next();
assertEquals("target-component-name", ecps.getTargetComponent());
list = ecps.getComponentPlugins();
assertNotNull(list);
assertFalse(list.isEmpty());
cp = (ComponentPlugin) list.get(0);
assertEquals("component-plugins-name", cp.getName());
assertEquals("set-method-name", cp.getSetMethod());
assertEquals("component-plugins-type", cp.getType());
assertEquals(1, cp.getPriority());
list = conf.getImports();
assertNotNull(list);
assertFalse(list.isEmpty());
assertEquals("import-value", list.get(0));
list = conf.getRemoveConfiguration();
assertNotNull(list);
assertFalse(list.isEmpty());
assertEquals("remove-configuration-value", list.get(0));
} finally {
try {
is.close();
} catch (Exception e) {
// ignore me
}
}
}
use of org.exoplatform.container.xml.ExternalComponentPlugins in project kernel by exoplatform.
the class ExoContainer method initContainerInternal.
protected void initContainerInternal() {
ConfigurationManager manager = getComponentInstanceOfType(ConfigurationManager.class);
ContainerUtil.addContainerLifecyclePlugin(this, manager);
ContainerUtil.addComponentLifecyclePlugin(this, manager);
ContainerUtil.addComponents(this, manager);
for (ContainerLifecyclePlugin plugin : containerLifecyclePlugin_) {
try {
plugin.initContainer(this);
} catch (Exception e) {
LOG.warn("An error occurs with the ContainerLifecyclePlugin '" + getPluginName(plugin) + "'", e);
}
}
Collection<ExternalComponentPlugins> unusedPlugins = getExternalComponentPluginsUnused();
if (unusedPlugins != null) {
for (ExternalComponentPlugins plugins : unusedPlugins) {
LOG.warn("Some external plugins has for target '{}' which is unknown, please configure it or " + "define the annotation 'DefinitionByType' to enable the auto-registration on the target", plugins.getTargetComponent());
}
}
}
Aggregations