001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Jun 17, 2005
014: * @author James Dixon
015: *
016: */
017:
018: package org.pentaho.core.services;
019:
020: import java.util.ArrayList;
021: import java.util.HashMap;
022: import java.util.List;
023:
024: import org.pentaho.core.runtime.IRuntimeContext;
025: import org.pentaho.core.session.IPentahoSession;
026: import org.pentaho.core.solution.HttpRequestParameterProvider;
027: import org.pentaho.core.solution.IActionCompleteListener;
028: import org.pentaho.core.solution.IOutputHandler;
029: import org.pentaho.core.solution.IParameterProvider;
030: import org.pentaho.core.solution.ISolutionEngine;
031: import org.pentaho.core.system.PentahoSystem;
032: import org.pentaho.core.ui.IPentahoUrlFactory;
033: import org.pentaho.messages.Messages;
034: import org.pentaho.util.logging.ILogger;
035: import org.pentaho.util.logging.Logger;
036:
037: public class BaseRequestHandler implements IActionRequestHandler,
038: IActionCompleteListener {
039:
040: public static final int ON_TIMEOUT_CANCEL = 0;
041:
042: public static final int ON_TIMEOUT_RETURN = 1;
043:
044: private IPentahoUrlFactory urlFactory;
045:
046: private String solutionName;
047:
048: private String actionName;
049:
050: private String actionPath;
051:
052: private String processId;
053:
054: private String instanceId;
055:
056: private IPentahoSession session;
057:
058: private IOutputHandler outputHandler;
059:
060: private HashMap parameterProviders;
061:
062: private boolean instanceEnds;
063:
064: private boolean forcePrompt = false;
065:
066: private String parameterXsl = null;
067:
068: ArrayList messages;
069:
070: IRuntimeContext runtime = null;
071:
072: // IActionRequestHandler methods
073:
074: public BaseRequestHandler(IPentahoSession session,
075: String instanceId, IOutputHandler outputHandler,
076: IParameterProvider parameterProvider,
077: IPentahoUrlFactory urlFactory) {
078: this .session = session;
079: this .outputHandler = outputHandler;
080: this .urlFactory = urlFactory;
081: this .instanceId = instanceId;
082: parameterProviders = new HashMap();
083: messages = new ArrayList();
084: if (parameterProvider != null) {
085: parameterProviders.put(
086: HttpRequestParameterProvider.SCOPE_REQUEST,
087: parameterProvider);
088:
089: }
090: instanceEnds = true;
091: }
092:
093: public List getMessages() {
094: return messages;
095: }
096:
097: public void setInstanceEnds(boolean instanceEnds) {
098: this .instanceEnds = instanceEnds;
099: }
100:
101: public void setParameterProvider(String name,
102: IParameterProvider parameterProvider) {
103: parameterProviders.put(name, parameterProvider);
104: }
105:
106: public HashMap getParameterProviders() {
107: return parameterProviders;
108: }
109:
110: public void setOutputHandler(IOutputHandler outputHandler) {
111: this .outputHandler = outputHandler;
112: }
113:
114: public void setProcessId(String processId) {
115: this .processId = processId;
116: }
117:
118: public void setInstanceId(String instanceId) {
119: this .instanceId = instanceId;
120: }
121:
122: public String getInstanceId() {
123: return instanceId;
124: }
125:
126: public void setAction(String actionPath, String actionName) {
127: this .actionName = actionName;
128: this .actionPath = actionPath;
129:
130: }
131:
132: public void setSolutionName(String solutionName) {
133: this .solutionName = solutionName;
134: }
135:
136: public String getSolutionName() {
137: return solutionName;
138: }
139:
140: public IRuntimeContext handleActionRequest(int timeout,
141: int timeoutType) {
142:
143: // Get the solution engine
144: ISolutionEngine solutionEngine = PentahoSystem
145: .getSolutionEngineInstance(session);
146: if (solutionEngine == null) {
147: Logger
148: .error(
149: this ,
150: Messages
151: .getErrorString("BaseRequestHandler.ERROR_0001_NO_SOLUTION_ENGINE")); //$NON-NLS-1$
152: return null;
153: }
154: solutionEngine.setLoggingLevel(ILogger.DEBUG);
155: solutionEngine.init(session);
156: solutionEngine.setForcePrompt(forcePrompt);
157: if (parameterXsl != null) {
158: solutionEngine.setParameterXsl(parameterXsl);
159: }
160:
161: dispose();
162: runtime = solutionEngine.execute(solutionName, actionPath,
163: actionName, processId, false, instanceEnds, instanceId,
164: true, parameterProviders, outputHandler, this ,
165: urlFactory, messages);
166:
167: // need to wait until this is complete
168: // TODO
169:
170: // if this times out check the timeoutType before cancelling or
171: // returning and leaving the component running
172:
173: return runtime;
174: }
175:
176: public void dispose() {
177: // execute the action
178: if (runtime != null)
179: runtime.dispose();
180: }
181:
182: public IRuntimeContext handleActionAsyncRequest() {
183: // TODO: handle asynchronous executions
184: return null;
185: }
186:
187: public IRuntimeContext getRuntime(String requestHandle) {
188: return runtime;
189: }
190:
191: // IActionCompleteListener methods
192: public void actionComplete(IRuntimeContext completedRuntime) {
193: // TODO
194:
195: }
196:
197: public IOutputHandler getOutputHandler() {
198: return outputHandler;
199: }
200:
201: public void setForcePrompt(boolean forcePrompt) {
202: this .forcePrompt = forcePrompt;
203: }
204:
205: public void setParameterXsl(String xsl) {
206: this .parameterXsl = xsl;
207: }
208:
209: public String getActionName() {
210: return actionName;
211: }
212:
213: public String getActionPath() {
214: return actionPath;
215: }
216:
217: public void setActionPath(String actionPath) {
218: this.actionPath = actionPath;
219: }
220:
221: }
|