KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > core > services > BaseRequestHandler


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Jun 17, 2005
14  * @author James Dixon
15  *
16  */

17
18 package org.pentaho.core.services;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.List JavaDoc;
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 JavaDoc solutionName;
45
46     private String JavaDoc actionName;
47
48     private String JavaDoc actionPath;
49
50     private String JavaDoc processId;
51
52     private String JavaDoc instanceId;
53
54     private IPentahoSession session;
55
56     private IOutputHandler outputHandler;
57
58     private HashMap JavaDoc parameterProviders;
59
60     private boolean instanceEnds;
61     
62     private boolean forcePrompt = false;
63
64     private String JavaDoc parameterXsl = null;
65     
66     ArrayList JavaDoc messages;
67
68     IRuntimeContext runtime = null;
69
70     // IActionRequestHandler methods
71

72     public BaseRequestHandler(IPentahoSession session, String JavaDoc 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 JavaDoc();
78         messages = new ArrayList JavaDoc();
79         if (parameterProvider != null) {
80             parameterProviders.put("request", parameterProvider); //$NON-NLS-1$
81

82         }
83         instanceEnds = true;
84     }
85
86     public List JavaDoc getMessages() {
87         return messages;
88     }
89
90     public void setInstanceEnds(boolean instanceEnds) {
91         this.instanceEnds = instanceEnds;
92     }
93
94     public void setParameterProvider(String JavaDoc name, IParameterProvider parameterProvider) {
95         parameterProviders.put(name, parameterProvider);
96     }
97
98     public HashMap JavaDoc getParameterProviders() {
99         return parameterProviders;
100     }
101
102     public void setOutputHandler(IOutputHandler outputHandler) {
103         this.outputHandler = outputHandler;
104     }
105
106     public void setProcessId(String JavaDoc processId) {
107         this.processId = processId;
108     }
109
110     public void setInstanceId(String JavaDoc instanceId) {
111         this.instanceId = instanceId;
112     }
113
114     public void setAction(String JavaDoc actionPath, String JavaDoc actionName) {
115         this.actionName = actionName;
116         this.actionPath = actionPath;
117
118     }
119
120     public void setSolutionName(String JavaDoc solutionName) {
121         this.solutionName = solutionName;
122     }
123
124     public IRuntimeContext handleActionRequest(int timeout, int timeoutType) {
125
126         // Get the solution engine
127
ISolutionEngine solutionEngine = PentahoSystem.getSolutionEngineInstance(session);
128         if (solutionEngine == null) {
129             Logger.error(this, Messages.getErrorString("BaseRequestHandler.ERROR_0001_NO_SOLUTION_ENGINE")); //$NON-NLS-1$
130
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         // need to wait until this is complete
143
// TODO
144

145         // if this times out check the timeoutType before cancelling or
146
// returning and leaving the component running
147

148         return runtime;
149     }
150
151     public void dispose() {
152         // execute the action
153
if (runtime != null)
154             runtime.dispose();
155     }
156
157     public IRuntimeContext handleActionAsyncRequest() {
158         // TODO: handle asynchronous executions
159
return null;
160     }
161
162     public IRuntimeContext getRuntime(String JavaDoc requestHandle) {
163         return runtime;
164     }
165
166     // IActionCompleteListener methods
167
public void actionComplete(IRuntimeContext completedRuntime) {
168         // TODO
169

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 JavaDoc xsl) {
181         this.parameterXsl = xsl;
182     }
183
184     public String JavaDoc getActionName() {
185       return actionName;
186     }
187     
188 }
189
Popular Tags