KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > interceptors > ProjectSetupInterceptor


1 /*
2  * Coefficient - facilitates project based collaboration
3  * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
4  * PO Box 395
5  * Pretoria 0001, RSA
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package za.org.coefficient.interceptors;
21
22 import za.co.csir.icomtek.workflow.WorkflowData;
23
24 import za.org.coefficient.core.CoefficientInterceptor;
25 import za.org.coefficient.core.Project;
26 import za.org.coefficient.interfaces.CoefficientContext;
27 import za.org.coefficient.util.common.InvokerFactory;
28
29 /**
30  *
31  * @version $Revision: 1.8 $ $Date: 2004/11/09 13:52:11 $
32  * @author <a HREF="mailto:detkin@csir.co.za">Dylan Etkin</a>
33  */

34 public class ProjectSetupInterceptor extends CoefficientInterceptor {
35     //~ Static fields/initializers =============================================
36

37     private static final String JavaDoc PROJECT_ID = "projectId";
38     private static final String JavaDoc CURRENT_WORKFLOW = "__current_workflow_data__";
39     public static final String JavaDoc CURRENT_PROJECT = "__current_project__";
40
41     //~ Methods ================================================================
42

43     protected int handleInvoke(CoefficientContext ctx) throws Exception JavaDoc {
44         int retVal = INVOKE_PROCESS_CHILD;
45         Long JavaDoc projectId = ctx.getParameterAsLong(PROJECT_ID, -1);
46         Project project = null;
47         String JavaDoc clearProject = ctx.getParameter("clearProject");
48         WorkflowData wd = null;
49         if (projectId.longValue() > 0) {
50             project = (Project) ctx.getSessionAttribute(CURRENT_PROJECT);
51             if ((project == null) || !project.getId().equals(projectId)
52                 || clearProject != null) {
53                 // lookup the project, set it into the context and the session
54
project = (Project)InvokerFactory.getRemoteInvoker()
55                     .invokeMethodOnModule("Project", "findProjectByPK",
56                                           new Object JavaDoc[] {projectId});
57
58                 // Check to see if this is a workflow project
59
wd = (WorkflowData)InvokerFactory.getRemoteInvoker()
60                     .invokeMethodOnService("Project", "findWorkflowDataByLinkId",
61                                            new Object JavaDoc[]{project.getId()});
62                 ctx.setProject(project);
63                 ctx.setSessionAttribute(CURRENT_WORKFLOW, wd);
64             }
65         } else if (clearProject == null) {
66             project = (Project) ctx.getSessionAttribute(CURRENT_PROJECT);
67             wd = (WorkflowData) ctx.getSessionAttribute(CURRENT_WORKFLOW);
68         } else {
69             ctx.removeSessionAttribute(CURRENT_WORKFLOW);
70             ctx.removeSessionAttribute(CURRENT_PROJECT);
71         }
72         
73         // Do workflow state evaluation if needed
74
if ((project != null) && project.getIsWorkflow()) {
75             if (wd != null) {
76                 Object JavaDoc context = InvokerFactory.getRemoteInvoker()
77                     .invokeMethodOnService("WorkflowEvaluatorFacade",
78                                            "determineState", new Object JavaDoc[]{ctx, wd});
79                 if(context instanceof CoefficientContext) {
80                     ctx = (CoefficientContext)context;
81                 }
82                 // This should not be needed since we have a ref to the obj
83
ctx.setSessionAttribute(CURRENT_WORKFLOW, wd);
84             }
85         }
86
87         return retVal;
88     }
89 }
90
Popular Tags