001: /*
002: * $Id: WfActivityAbstractImplementation.java,v 1.2 2003/08/28 19:06:14 ajzeneski Exp $
003: *
004: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: *
024: */
025: package org.ofbiz.workflow.impl;
026:
027: import java.util.HashMap;
028: import java.util.List;
029: import java.util.Map;
030:
031: import org.ofbiz.base.util.Debug;
032: import org.ofbiz.service.DispatchContext;
033: import org.ofbiz.service.GenericResultWaiter;
034: import org.ofbiz.service.GenericServiceException;
035: import org.ofbiz.service.LocalDispatcher;
036: import org.ofbiz.service.ModelService;
037: import org.ofbiz.workflow.WfException;
038:
039: /**
040: * WfActivityAbstractImplementation.java
041: *
042: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
043: * @author Oswin Ondarza and Manuel Soto
044: * @version $Revision: 1.2 $
045: * @since 2.0
046: */
047: public abstract class WfActivityAbstractImplementation {
048:
049: public static final String module = WfActivityAbstractImplementation.class
050: .getName();
051:
052: private WfActivityImpl wfActivity = null;
053: private Map resultContext = new HashMap();
054: private boolean complete = false;
055:
056: public WfActivityAbstractImplementation(WfActivityImpl wfActivity) {
057: this .wfActivity = wfActivity;
058: }
059:
060: /**
061: * Run the implementation.
062: * @throws WfException
063: */
064: public abstract void run() throws WfException;
065:
066: protected GenericResultWaiter runService(String serviceName,
067: String params, String extend) throws WfException {
068: LocalDispatcher dispatcher = getActivity().getDispatcher();
069: DispatchContext dctx = dispatcher.getDispatchContext();
070: ModelService service = null;
071: Debug
072: .logVerbose(
073: "[WfActivityAbstractImplementation.runService] : Getting the service model.",
074: module);
075: try {
076: service = dctx.getModelService(serviceName);
077: } catch (GenericServiceException e) {
078: throw new WfException(e.getMessage(), e);
079: }
080: if (service == null)
081: throw new WfException(
082: "Cannot determine model service for service name");
083:
084: return runService(service, params, extend);
085: }
086:
087: protected GenericResultWaiter runService(ModelService service,
088: String params, String extend) throws WfException {
089: LocalDispatcher dispatcher = getActivity().getDispatcher();
090: List paramNames = service.getParameterNames(
091: ModelService.IN_PARAM, true);
092: if (paramNames != null && paramNames.size() == 0)
093: paramNames = null;
094:
095: Map ctx = getActivity().actualContext(params, extend,
096: paramNames, false);
097:
098: GenericResultWaiter waiter = new GenericResultWaiter();
099: Debug
100: .logVerbose(
101: "[WfActivityAbstractImplementation.runService] : Invoking the service.",
102: module);
103: try {
104: dispatcher.runAsync(service.name, ctx, waiter, false);
105: } catch (GenericServiceException e) {
106: throw new WfException(e.getMessage(), e);
107: }
108:
109: return waiter;
110: }
111:
112: protected void setResult(Map result) {
113: this .resultContext.putAll(result);
114: }
115:
116: protected WfActivityImpl getActivity() throws WfException {
117: if (this .wfActivity == null)
118: throw new WfException("Activity object is null");
119: return wfActivity;
120: }
121:
122: /**
123: * Returns the result context.
124: * @return Map
125: */
126: public Map getResult() {
127: return resultContext;
128: }
129:
130: /**
131: * Getter for property complete.
132: * @return Value of property complete.
133: */
134: public boolean isComplete() {
135: return this .complete;
136: }
137:
138: /**
139: * Setter for property complete.
140: * @param complete New value of property complete.
141: */
142: protected void setComplete(boolean complete) {
143: this.complete = complete;
144: }
145: }
|