1 25 package org.ofbiz.workflow.impl; 26 27 import java.util.HashMap ; 28 import java.util.Map ; 29 30 import org.ofbiz.service.DispatchContext; 31 import org.ofbiz.service.GenericServiceException; 32 import org.ofbiz.service.LocalDispatcher; 33 import org.ofbiz.service.ModelService; 34 import org.ofbiz.workflow.EvaluationException; 35 import org.ofbiz.workflow.TransitionCondition; 36 37 38 48 public class ServiceCondition implements TransitionCondition { 49 50 53 public Boolean evaluateCondition(Map context, Map attrs, String expression, DispatchContext dctx) throws EvaluationException { 54 String serviceName = (String ) attrs.get("serviceName"); 56 if (serviceName == null || serviceName.length() == 0) 57 throw new EvaluationException("Invalid serviceName; be sure to set the serviceName ExtendedAttribute"); 58 59 LocalDispatcher dispatcher = dctx.getDispatcher(); 61 if (dispatcher == null) 62 throw new EvaluationException("Bad LocalDispatcher found in the DispatchContext"); 63 64 Map newContext = new HashMap (context); 66 newContext.putAll(attrs); 67 68 Map serviceContext = null; 70 ModelService model = null; 71 try { 72 model = dctx.getModelService(serviceName); 73 serviceContext = model.makeValid(newContext, ModelService.IN_PARAM); 74 } catch (GenericServiceException e) { 75 throw new EvaluationException("Cannot get ModelService object for service named: " + serviceName, e); 76 } 77 78 Map serviceResult = null; 80 try { 81 serviceResult = dispatcher.runSync(serviceName, serviceContext); 82 } catch (GenericServiceException e) { 83 throw new EvaluationException("Cannot invoke the service named: " + serviceName, e); 84 } 85 86 Boolean evaluationResult = null; 88 try { 89 evaluationResult = (Boolean ) serviceResult.get("evaluationResult"); 90 } catch (ClassCastException e) { 91 throw new EvaluationException("Service did not return a valid evaluationResult object"); 92 } 93 94 return evaluationResult; 95 } 96 97 } 98 | Popular Tags |