use of org.pentaho.platform.engine.services.solution.PojoComponent in project pentaho-platform by pentaho.
the class RuntimeContext method resolveComponent.
protected IComponent resolveComponent(final ISolutionActionDefinition actionDefinition, final String currentInstanceId, final String currentProcessId, final IPentahoSession currentSession) throws ClassNotFoundException, PluginBeanException, InstantiationException, IllegalAccessException {
// try to create an instance of the component class specified in the
// action document
String componentAlias = actionDefinition.getComponentName().trim();
String componentClassName = RuntimeContext.getComponentClassName(componentAlias, this);
Element componentDefinition = (Element) actionDefinition.getComponentSection();
setCurrentComponent(componentClassName);
setCurrentActionDef(actionDefinition);
IComponent component = null;
Class componentClass = null;
Object componentTmp = null;
// Explicitly using the short name instead of the fully layed out class name
if ((pluginManager != null) && (pluginManager.isBeanRegistered(componentAlias))) {
if (RuntimeContext.debug) {
// $NON-NLS-1$ //$NON-NLS-2$
this.debug("Component alias " + componentAlias + " will be resolved by the plugin manager.");
}
componentTmp = pluginManager.getBean(componentAlias);
if (RuntimeContext.debug) {
// $NON-NLS-1$
this.debug("Component found in a plugin, class is: " + componentTmp.getClass().getName());
}
}
if (RuntimeContext.debug) {
// $NON-NLS-1$ //$NON-NLS-2$
this.debug("Component alias " + componentAlias + " will be resolved by the platform");
}
// Ok - the plugin didn't load - try the old route
if (componentTmp == null) {
componentClass = Class.forName(componentClassName);
componentTmp = componentClass.newInstance();
}
if (componentTmp instanceof IComponent) {
component = (IComponent) componentTmp;
} else if (componentTmp instanceof IAction) {
component = new ActionDelegate(componentTmp);
} else {
// Try this out...
PojoComponent pc = new PojoComponent();
pc.setPojo(componentTmp);
component = pc;
}
component.setInstanceId(currentInstanceId);
component.setActionName(getActionName());
component.setProcessId(currentProcessId);
// to the dom nodes.
if (component instanceof IParameterResolver) {
component.setActionDefinition(ActionFactory.getActionDefinition((Element) actionDefinition.getNode(), new ActionSequenceParameterMgr(this, currentSession, (IParameterResolver) component)));
} else {
component.setActionDefinition(ActionFactory.getActionDefinition((Element) actionDefinition.getNode(), new ActionSequenceParameterMgr(this, currentSession)));
}
// create a map of the top level component definition nodes and their text
Map<String, String> componentDefinitionMap = new HashMap<String, String>();
List elements = componentDefinition.elements();
Element element;
String name;
String value;
String customXsl = null;
for (int idx = 0; idx < elements.size(); idx++) {
element = (Element) elements.get(idx);
name = element.getName();
value = element.getText();
// see if we have a target window for the output
if ("target".equals(name)) {
// $NON-NLS-1$
setParameterTarget(value);
} else if ("xsl".equals(name)) {
// $NON-NLS-1$
// setParameterXsl(value);
customXsl = value;
}
componentDefinitionMap.put(element.getName(), element.getText());
}
if (customXsl != null) {
setParameterXsl(customXsl);
}
component.setComponentDefinitionMap(componentDefinitionMap);
component.setComponentDefinition(componentDefinition);
component.setRuntimeContext(this);
component.setSession(currentSession);
component.setLoggingLevel(getLoggingLevel());
component.setMessages(getMessages());
return component;
}
Aggregations