| 1 17 18 package org.pentaho.core.services; 19 20 import java.util.ArrayList ; 21 import java.util.HashMap ; 22 import java.util.List ; 23 24 import org.pentaho.core.runtime.IRuntimeContext; 25 import org.pentaho.core.session.IPentahoSession; 26 import org.pentaho.core.solution.IActionCompleteListener; 27 import org.pentaho.core.solution.IOutputHandler; 28 import org.pentaho.core.solution.IParameterProvider; 29 import org.pentaho.core.solution.ISolutionEngine; 30 import org.pentaho.core.system.PentahoSystem; 31 import org.pentaho.core.ui.IPentahoUrlFactory; 32 import org.pentaho.messages.Messages; 33 import org.pentaho.util.logging.ILogger; 34 import org.pentaho.util.logging.Logger; 35 36 public class BaseRequestHandler implements IActionRequestHandler, IActionCompleteListener { 37 38 public static final int ON_TIMEOUT_CANCEL = 0; 39 40 public static final int ON_TIMEOUT_RETURN = 1; 41 42 private IPentahoUrlFactory urlFactory; 43 44 private String solutionName; 45 46 private String actionName; 47 48 private String actionPath; 49 50 private String processId; 51 52 private String instanceId; 53 54 private IPentahoSession session; 55 56 private IOutputHandler outputHandler; 57 58 private HashMap parameterProviders; 59 60 private boolean instanceEnds; 61 62 private boolean forcePrompt = false; 63 64 private String parameterXsl = null; 65 66 ArrayList messages; 67 68 IRuntimeContext runtime = null; 69 70 72 public BaseRequestHandler(IPentahoSession session, String instanceId, IOutputHandler outputHandler, IParameterProvider parameterProvider, IPentahoUrlFactory urlFactory) { 73 this.session = session; 74 this.outputHandler = outputHandler; 75 this.urlFactory = urlFactory; 76 this.instanceId = instanceId; 77 parameterProviders = new HashMap (); 78 messages = new ArrayList (); 79 if (parameterProvider != null) { 80 parameterProviders.put("request", parameterProvider); 82 } 83 instanceEnds = true; 84 } 85 86 public List getMessages() { 87 return messages; 88 } 89 90 public void setInstanceEnds(boolean instanceEnds) { 91 this.instanceEnds = instanceEnds; 92 } 93 94 public void setParameterProvider(String name, IParameterProvider parameterProvider) { 95 parameterProviders.put(name, parameterProvider); 96 } 97 98 public HashMap getParameterProviders() { 99 return parameterProviders; 100 } 101 102 public void setOutputHandler(IOutputHandler outputHandler) { 103 this.outputHandler = outputHandler; 104 } 105 106 public void setProcessId(String processId) { 107 this.processId = processId; 108 } 109 110 public void setInstanceId(String instanceId) { 111 this.instanceId = instanceId; 112 } 113 114 public void setAction(String actionPath, String actionName) { 115 this.actionName = actionName; 116 this.actionPath = actionPath; 117 118 } 119 120 public void setSolutionName(String solutionName) { 121 this.solutionName = solutionName; 122 } 123 124 public IRuntimeContext handleActionRequest(int timeout, int timeoutType) { 125 126 ISolutionEngine solutionEngine = PentahoSystem.getSolutionEngineInstance(session); 128 if (solutionEngine == null) { 129 Logger.error(this, Messages.getErrorString("BaseRequestHandler.ERROR_0001_NO_SOLUTION_ENGINE")); return null; 131 } 132 solutionEngine.setLoggingLevel(ILogger.DEBUG); 133 solutionEngine.init(session); 134 solutionEngine.setForcePrompt( forcePrompt ); 135 if( parameterXsl != null ) { 136 solutionEngine.setParameterXsl( parameterXsl ); 137 } 138 139 dispose(); 140 runtime = solutionEngine.execute(solutionName, actionPath, actionName, processId, false, instanceEnds, instanceId, true, parameterProviders, outputHandler, this, urlFactory, messages); 141 142 145 148 return runtime; 149 } 150 151 public void dispose() { 152 if (runtime != null) 154 runtime.dispose(); 155 } 156 157 public IRuntimeContext handleActionAsyncRequest() { 158 return null; 160 } 161 162 public IRuntimeContext getRuntime(String requestHandle) { 163 return runtime; 164 } 165 166 public void actionComplete(IRuntimeContext completedRuntime) { 168 170 } 171 172 public IOutputHandler getOutputHandler() { 173 return outputHandler; 174 } 175 176 public void setForcePrompt( boolean forcePrompt ) { 177 this.forcePrompt = forcePrompt; 178 } 179 180 public void setParameterXsl(String xsl) { 181 this.parameterXsl = xsl; 182 } 183 184 public String getActionName() { 185 return actionName; 186 } 187 188 } 189 | Popular Tags |