1 24 package org.ofbiz.service.group; 25 26 import java.util.HashMap ; 27 import java.util.List ; 28 import java.util.Map ; 29 30 import org.ofbiz.service.DispatchContext; 31 import org.ofbiz.service.GenericServiceException; 32 import org.ofbiz.service.ModelService; 33 import org.ofbiz.service.ServiceDispatcher; 34 import org.ofbiz.base.util.Debug; 35 import org.w3c.dom.Element ; 36 37 44 public class GroupServiceModel { 45 46 public static final String module = GroupServiceModel.class.getName(); 47 48 private String serviceName, serviceMode; 49 private boolean resultToContext = false; 50 51 55 public GroupServiceModel(Element service) { 56 this.serviceName = service.getAttribute("name"); 57 this.serviceMode = service.getAttribute("mode"); 58 this.resultToContext = service.getAttribute("result-to-context").equalsIgnoreCase("true") ? true : false; 59 } 60 61 66 public GroupServiceModel(String serviceName, String serviceMode) { 67 this.serviceName = serviceName; 68 this.serviceMode = serviceMode; 69 } 70 71 75 public String getMode() { 76 return this.serviceMode; 77 } 78 79 83 public String getName() { 84 return this.serviceName; 85 } 86 87 91 public boolean resultToContext() { 92 return this.resultToContext; 93 } 94 95 103 public Map invoke(ServiceDispatcher dispatcher, String localName, Map context) throws GenericServiceException { 104 DispatchContext dctx = dispatcher.getLocalContext(localName); 105 ModelService model = dctx.getModelService(getName()); 106 if (model == null) 107 throw new GenericServiceException("Group defined service (" + getName() + ") is not a defined service."); 108 109 Map thisContext = model.makeValid(context, ModelService.IN_PARAM); 110 Debug.logInfo("Running grouped service [" + serviceName + "]", module); 111 if (getMode().equals("async")) { 112 List requiredOut = model.getParameterNames(ModelService.OUT_PARAM, false); 113 if (requiredOut.size() > 0) { 114 Debug.logWarning("Grouped service (" + getName() + ") requested 'async' invocation; running sync because of required OUT parameters.", module); 115 return dispatcher.runSync(localName, model, thisContext); 116 } else { 117 dispatcher.runAsync(localName, model, thisContext, false); 118 return new HashMap (); 119 } 120 } else { 121 return dispatcher.runSync(localName, model, thisContext); 122 } 123 } 124 125 128 public String toString() { 129 StringBuffer str = new StringBuffer (); 130 str.append(getName()); 131 str.append("::"); 132 str.append(getMode()); 133 str.append("::"); 134 return str.toString(); 135 } 136 } 137 | Popular Tags |