KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > workflow > impl > WfActivityAbstractImplementation


1 /*
2  * $Id: WfActivityAbstractImplementation.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.workflow.impl;
26
27 import java.util.HashMap JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import org.ofbiz.base.util.Debug;
32 import org.ofbiz.service.DispatchContext;
33 import org.ofbiz.service.GenericResultWaiter;
34 import org.ofbiz.service.GenericServiceException;
35 import org.ofbiz.service.LocalDispatcher;
36 import org.ofbiz.service.ModelService;
37 import org.ofbiz.workflow.WfException;
38
39 /**
40  * WfActivityAbstractImplementation.java
41  *
42  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
43  * @author Oswin Ondarza and Manuel Soto
44  * @version $Rev: 5462 $
45  * @since 2.0
46  */

47 public abstract class WfActivityAbstractImplementation {
48
49     public static final String JavaDoc module = WfActivityAbstractImplementation.class.getName();
50
51     private WfActivityImpl wfActivity = null;
52     private Map JavaDoc resultContext = new HashMap JavaDoc();
53     private boolean complete = false;
54
55     public WfActivityAbstractImplementation(WfActivityImpl wfActivity) {
56         this.wfActivity = wfActivity;
57     }
58
59     /**
60      * Run the implementation.
61      * @throws WfException
62      */

63     public abstract void run() throws WfException;
64
65     protected GenericResultWaiter runService(String JavaDoc serviceName, String JavaDoc params, String JavaDoc extend) throws WfException {
66         LocalDispatcher dispatcher = getActivity().getDispatcher();
67         DispatchContext dctx = dispatcher.getDispatchContext();
68         ModelService service = null;
69         Debug.logVerbose("[WfActivityAbstractImplementation.runService] : Getting the service model.", module);
70         try {
71             service = dctx.getModelService(serviceName);
72         } catch (GenericServiceException e) {
73             throw new WfException(e.getMessage(), e);
74         }
75         if (service == null)
76             throw new WfException("Cannot determine model service for service name");
77
78         return runService(service, params, extend);
79     }
80
81     protected GenericResultWaiter runService(ModelService service, String JavaDoc params, String JavaDoc extend) throws WfException {
82         LocalDispatcher dispatcher = getActivity().getDispatcher();
83         List JavaDoc paramNames = service.getParameterNames(ModelService.IN_PARAM, true);
84         if (paramNames != null && paramNames.size() == 0)
85             paramNames = null;
86                  
87         Map JavaDoc ctx = getActivity().actualContext(params, extend, paramNames, false);
88         
89         GenericResultWaiter waiter = new GenericResultWaiter();
90         Debug.logVerbose("[WfActivityAbstractImplementation.runService] : Invoking the service.", module);
91         try {
92             dispatcher.runAsync(service.name, ctx, waiter, false);
93         } catch (GenericServiceException e) {
94             throw new WfException(e.getMessage(), e);
95         }
96
97         return waiter;
98     }
99
100     protected void setResult(Map JavaDoc result) {
101         this.resultContext.putAll(result);
102     }
103
104     protected WfActivityImpl getActivity() throws WfException {
105         if (this.wfActivity == null)
106             throw new WfException("Activity object is null");
107         return wfActivity;
108     }
109
110     /**
111      * Returns the result context.
112      * @return Map
113      */

114     public Map JavaDoc getResult() {
115         return resultContext;
116     }
117
118     /**
119      * Getter for property complete.
120      * @return Value of property complete.
121      */

122     public boolean isComplete() {
123         return this.complete;
124     }
125
126     /**
127      * Setter for property complete.
128      * @param complete New value of property complete.
129      */

130     protected void setComplete(boolean complete) {
131         this.complete = complete;
132     }
133 }
134
Popular Tags