1 25 package org.ofbiz.minilang; 26 27 import java.util.Map ; 28 29 import org.ofbiz.service.DispatchContext; 30 import org.ofbiz.service.GenericServiceException; 31 import org.ofbiz.service.ModelService; 32 import org.ofbiz.service.ServiceDispatcher; 33 import org.ofbiz.service.engine.GenericAsyncEngine; 34 35 42 public final class SimpleServiceEngine extends GenericAsyncEngine { 43 44 45 public SimpleServiceEngine(ServiceDispatcher dispatcher) { 46 super(dispatcher); 47 } 48 49 52 public void runSyncIgnore(String localName, ModelService modelService, Map context) throws GenericServiceException { 53 Map result = runSync(localName, modelService, context); 54 } 55 56 60 public Map runSync(String localName, ModelService modelService, Map context) throws GenericServiceException { 61 Object result = serviceInvoker(localName, modelService, context); 62 if (result == null || !(result instanceof Map )) 63 throw new GenericServiceException("Service did not return expected result"); 64 return (Map ) result; 65 } 66 67 private Object serviceInvoker(String localName, ModelService modelService, Map context) throws GenericServiceException { 69 DispatchContext dctx = dispatcher.getLocalContext(localName); 71 72 if (modelService.location == null || modelService.invoke == null) 74 throw new GenericServiceException("Cannot locate service to invoke (location or invoke name missing)"); 75 76 ClassLoader classLoader = null; 78 79 if (dctx != null) 80 classLoader = dctx.getClassLoader(); 81 82 85 try { 86 return SimpleMethod.runSimpleService(this.getLocation(modelService), modelService.invoke, dctx, context, classLoader); 87 } catch (MiniLangException e) { 88 throw new GenericServiceException("Error running simple method [" + modelService.invoke + 89 "] in XML file [" + modelService.location + "]: ", e); 90 } 91 } 92 } 93 | Popular Tags |