Search in sources :

Example 1 with IParameterResolver

use of org.pentaho.platform.api.engine.IParameterResolver 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;
}
Also used : IAction(org.pentaho.platform.api.action.IAction) HashMap(java.util.HashMap) IComponent(org.pentaho.platform.api.engine.IComponent) IRuntimeElement(org.pentaho.platform.api.repository.IRuntimeElement) Element(org.dom4j.Element) ActionDelegate(org.pentaho.platform.engine.services.solution.ActionDelegate) IParameterResolver(org.pentaho.platform.api.engine.IParameterResolver) List(java.util.List) ArrayList(java.util.ArrayList) ActionSequenceParameterMgr(org.pentaho.platform.engine.services.actionsequence.ActionSequenceParameterMgr) PojoComponent(org.pentaho.platform.engine.services.solution.PojoComponent)

Example 2 with IParameterResolver

use of org.pentaho.platform.api.engine.IParameterResolver in project pentaho-platform by pentaho.

the class TemplateUtilTest method testTableTemplate.

public void testTableTemplate() {
    IRuntimeContext mockRuntimeContext = mock(IRuntimeContext.class);
    IPentahoSession mockSession = mock(IPentahoSession.class);
    IParameterManager mockParameterManager = mock(IParameterManager.class);
    IPentahoResultSet mockPentahoResultSet = mock(IPentahoResultSet.class);
    Object[] mockRow = new Object[] { "field0", "field1" };
    when(mockPentahoResultSet.getColumnCount()).thenReturn(mockRow.length);
    when(mockPentahoResultSet.getDataRow(0)).thenReturn(mockRow);
    when(mockParameterManager.getCurrentInputNames()).thenReturn(new HashSet<Object>(Arrays.asList(new String[] { "param1" })));
    when(mockRuntimeContext.getSession()).thenReturn(mockSession);
    when(mockRuntimeContext.getParameterManager()).thenReturn(mockParameterManager);
    when(mockRuntimeContext.getInputParameterValue("param1")).thenReturn(mockPentahoResultSet);
    String template = "table {param1:col:1} and text";
    IParameterResolver resolver = mock(IParameterResolver.class);
    assertEquals("table field1 and text", TemplateUtil.applyTemplate(template, mockRuntimeContext, resolver));
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IParameterManager(org.pentaho.platform.api.engine.IParameterManager) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IParameterResolver(org.pentaho.platform.api.engine.IParameterResolver)

Aggregations

IParameterResolver (org.pentaho.platform.api.engine.IParameterResolver)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Element (org.dom4j.Element)1 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)1 IAction (org.pentaho.platform.api.action.IAction)1 IComponent (org.pentaho.platform.api.engine.IComponent)1 IParameterManager (org.pentaho.platform.api.engine.IParameterManager)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)1 IRuntimeElement (org.pentaho.platform.api.repository.IRuntimeElement)1 ActionSequenceParameterMgr (org.pentaho.platform.engine.services.actionsequence.ActionSequenceParameterMgr)1 ActionDelegate (org.pentaho.platform.engine.services.solution.ActionDelegate)1 PojoComponent (org.pentaho.platform.engine.services.solution.PojoComponent)1