1 25 package org.ofbiz.workflow.impl; 26 27 import java.util.HashMap ; 28 import java.util.List ; 29 import java.util.Map ; 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 47 public abstract class WfActivityAbstractImplementation { 48 49 public static final String module = WfActivityAbstractImplementation.class.getName(); 50 51 private WfActivityImpl wfActivity = null; 52 private Map resultContext = new HashMap (); 53 private boolean complete = false; 54 55 public WfActivityAbstractImplementation(WfActivityImpl wfActivity) { 56 this.wfActivity = wfActivity; 57 } 58 59 63 public abstract void run() throws WfException; 64 65 protected GenericResultWaiter runService(String serviceName, String params, String 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 params, String extend) throws WfException { 82 LocalDispatcher dispatcher = getActivity().getDispatcher(); 83 List paramNames = service.getParameterNames(ModelService.IN_PARAM, true); 84 if (paramNames != null && paramNames.size() == 0) 85 paramNames = null; 86 87 Map 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 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 114 public Map getResult() { 115 return resultContext; 116 } 117 118 122 public boolean isComplete() { 123 return this.complete; 124 } 125 126 130 protected void setComplete(boolean complete) { 131 this.complete = complete; 132 } 133 } 134 | Popular Tags |