use of org.exoplatform.container.component.ComponentPlugin in project kernel by exoplatform.
the class MX4JComponentAdapter method addComponentPlugin.
private void addComponentPlugin(boolean debug, final Object component, List<org.exoplatform.container.xml.ComponentPlugin> plugins, ExoContainer container) throws Exception {
if (plugins == null)
return;
for (org.exoplatform.container.xml.ComponentPlugin plugin : plugins) {
try {
Class<?> pluginClass = ClassLoading.forName(plugin.getType(), this);
ComponentPlugin cplugin = (ComponentPlugin) container.createComponent(pluginClass, plugin.getInitParams());
cplugin.setName(plugin.getName());
cplugin.setDescription(plugin.getDescription());
Class<?> clazz = component.getClass();
final Method m = getSetMethod(clazz, plugin.getSetMethod(), pluginClass);
if (m == null) {
LOG.error("Cannot find the method '" + plugin.getSetMethod() + "' that has only one parameter of type '" + pluginClass.getName() + "' in the class '" + clazz.getName() + "'.");
continue;
}
final Object[] params = { cplugin };
SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
m.invoke(component, params);
return null;
}
});
if (debug)
LOG.debug("==> add component plugin: " + cplugin);
cplugin.setName(plugin.getName());
cplugin.setDescription(plugin.getDescription());
} catch (Exception ex) {
LOG.error("Failed to instanciate plugin " + plugin.getName() + " for component " + component + ": " + ex.getMessage(), ex);
}
}
}
use of org.exoplatform.container.component.ComponentPlugin in project kernel by exoplatform.
the class MX4JComponentAdapterMT method createPlugin.
private ComponentTask<Void> createPlugin(final MX4JComponentAdapterMT<T> caller, final ConcurrentContainerMT exocontainer, final Class<?> pluginClass, final boolean debug, final org.exoplatform.container.xml.ComponentPlugin plugin, final Constructor<T> constructor, InitParams params, List<Dependency> lDependencies) throws Exception {
final Object[] args = exocontainer.getArguments(constructor, params, lDependencies);
return new ComponentTask<Void>("create/add plugin " + plugin.getName() + " for component " + getComponentImplementation().getName(), exocontainer, caller, ComponentTaskType.INIT) {
public Void execute(final CreationalContextComponentAdapter<?> cCtx) throws Exception {
try {
getContainer().loadArguments(args);
ComponentPlugin cplugin = (ComponentPlugin) constructor.newInstance(args);
cplugin.setName(plugin.getName());
cplugin.setDescription(plugin.getDescription());
Class<?> clazz = getComponentImplementation();
final Method m = getSetMethod(clazz, plugin.getSetMethod(), pluginClass);
if (m == null) {
LOG.error("Cannot find the method '" + plugin.getSetMethod() + "' that has only one parameter of type '" + pluginClass.getName() + "' in the class '" + clazz.getName() + "'.");
return null;
}
final Object[] params = { cplugin };
SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
m.invoke(cCtx.get(), params);
return null;
}
});
if (debug)
LOG.debug("==> add component plugin: " + cplugin);
cplugin.setName(plugin.getName());
cplugin.setDescription(plugin.getDescription());
return null;
} catch (InvocationTargetException e) {
if (e.getCause() instanceof Exception) {
throw (Exception) e.getCause();
}
throw e;
}
}
};
}
use of org.exoplatform.container.component.ComponentPlugin in project kernel by exoplatform.
the class TestContainer method testPriorityPlugins.
public void testPriorityPlugins() {
RootContainer rootContainer = RootContainer.getInstance();
PortalContainer pcontainer = rootContainer.getPortalContainer("portal");
assertNotNull(pcontainer);
PriorityService ps = (PriorityService) pcontainer.getComponentInstanceOfType(PriorityService.class);
assertNotNull(ps);
List<ComponentPlugin> l = ps.getPlugins();
assertNotNull(l);
assertEquals(3, l.size());
assertEquals("PluginPriority3", l.get(0).getName());
assertEquals("PluginPriority1", l.get(1).getName());
assertEquals("PluginPriority2", l.get(2).getName());
}
Aggregations