1 package org.ofbiz.shark.tool; 2 3 import java.util.Map ; 4 import java.util.HashMap ; 5 6 import org.ofbiz.shark.container.SharkContainer; 7 import org.ofbiz.service.LocalDispatcher; 8 import org.ofbiz.service.GenericServiceException; 9 import org.ofbiz.service.ServiceUtil; 10 import org.ofbiz.base.util.Debug; 11 12 import org.enhydra.shark.toolagent.AbstractToolAgent; 13 import org.enhydra.shark.api.internal.toolagent.ToolAgentGeneralException; 14 import org.enhydra.shark.api.internal.toolagent.ApplicationBusy; 15 import org.enhydra.shark.api.internal.toolagent.ApplicationNotDefined; 16 import org.enhydra.shark.api.internal.toolagent.ApplicationNotStarted; 17 import org.enhydra.shark.api.internal.toolagent.AppParameter; 18 import org.enhydra.shark.api.SharkTransaction; 19 import org.enhydra.shark.xpdl.elements.ExtendedAttributes; 20 21 28 public class ServiceEngineAgent extends AbstractToolAgent { 29 30 public static final String module = ServiceEngineAgent.class.getName(); 31 32 public void invokeApplication (SharkTransaction trans, long handle, String applicationName, String procInstId, String actInstId, 33 AppParameter[] parameters, Integer appMode) throws ApplicationNotStarted, 34 ApplicationNotDefined, ApplicationBusy, ToolAgentGeneralException { 35 36 super.invokeApplication(trans, handle, applicationName, procInstId, actInstId, parameters, appMode); 37 38 status = APP_STATUS_RUNNING; 40 41 LocalDispatcher dispatcher = SharkContainer.getDispatcher(); 43 Map serviceContext = new HashMap (); 44 this.getServiceContext(parameters, serviceContext); 45 46 Map serviceResult = null; 48 try { 49 serviceResult = dispatcher.runSync(appName, serviceContext); 50 } catch (GenericServiceException e) { 51 status = APP_STATUS_INVALID; 52 Debug.logError(e, module); 53 throw new ToolAgentGeneralException(e); 54 } 55 56 this.getServiceResults(parameters, serviceResult); 58 59 if (ServiceUtil.isError(serviceResult)) { 61 status = APP_STATUS_INVALID; 62 } else { 63 status = APP_STATUS_FINISHED; 64 } 65 } 66 67 private void getServiceContext(AppParameter[] params, Map context) { 68 if (params != null && context != null) { 69 for (int i = 1; i < params.length; i++) { 70 if (params[i].the_mode.equals(AppParameter.MODE_IN) || params[i].the_mode.equals(AppParameter.MODE_INOUT)) { 71 context.put(params[i].the_formal_name, params[i].the_value); 72 } 73 } 74 } 75 } 76 77 private void getServiceResults(AppParameter[] params, Map result) { 78 if (params != null && result != null) { 79 for (int i = 1; i < params.length; i++) { 80 if (params[i].the_mode.equals(AppParameter.MODE_OUT) || params[i].the_mode.equals(AppParameter.MODE_INOUT)) { 81 params[i].the_value = result.get(params[i].the_formal_name); 82 } 83 } 84 } 85 } 86 87 protected ExtendedAttributes readParamsFromExtAttributes (String extAttribs) throws Exception { 88 ExtendedAttributes eas = super.readParamsFromExtAttributes(extAttribs); 89 return eas; 90 } 91 } 92 | Popular Tags |