1 24 package org.ofbiz.minilang.method.callops; 25 26 import java.util.*; 27 28 import org.w3c.dom.*; 29 import org.ofbiz.base.util.*; 30 import org.ofbiz.minilang.*; 31 import org.ofbiz.minilang.method.*; 32 33 40 public class CallSimpleMethod extends MethodOperation { 41 42 public static final String module = CallSimpleMethod.class.getName(); 43 44 String xmlResource; 45 String methodName; 46 47 public CallSimpleMethod(Element element, SimpleMethod simpleMethod) { 48 super(element, simpleMethod); 49 this.methodName = element.getAttribute("method-name"); 50 this.xmlResource = element.getAttribute("xml-resource"); 51 } 52 53 public boolean exec(MethodContext methodContext) { 54 if (this.methodName != null && this.methodName.length() > 0) { 55 String methodName = methodContext.expandString(this.methodName); 56 String xmlResource = methodContext.expandString(this.xmlResource); 57 58 SimpleMethod simpleMethodToCall = null; 59 if (xmlResource == null || xmlResource.length() == 0) { 60 simpleMethodToCall = this.simpleMethod.getSimpleMethodInSameFile(methodName); 61 } else { 62 Map simpleMethods = null; 63 try { 64 simpleMethods = SimpleMethod.getSimpleMethods(xmlResource, methodName, methodContext.getLoader()); 65 } catch (MiniLangException e) { 66 String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [error getting methods from resource: " + e.getMessage() + "]"; 67 Debug.logError(e, errMsg, module); 68 methodContext.setErrorReturn(errMsg, simpleMethod); 69 return false; 70 } 71 72 simpleMethodToCall = (SimpleMethod) simpleMethods.get(methodName); 73 } 74 75 if (simpleMethodToCall == null) { 76 String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process, could not find SimpleMethod " + methodName + " in XML document in resource: " + xmlResource; 77 methodContext.setErrorReturn(errMsg, simpleMethod); 78 return false; 79 } 80 81 String returnVal = simpleMethodToCall.exec(methodContext); 82 if (Debug.verboseOn()) Debug.logVerbose("Called inline simple-method named [" + methodName + "] in resource [" + xmlResource + "], returnVal is [" + returnVal + "]", module); 83 84 if (returnVal != null && returnVal.equals(simpleMethodToCall.getDefaultErrorCode())) { 85 if (methodContext.getMethodType() == MethodContext.EVENT) { 87 methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); 88 } else if (methodContext.getMethodType() == MethodContext.SERVICE) { 89 methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); 90 } 91 return false; 92 } 93 94 if (methodContext.getMethodType() == MethodContext.EVENT) { 96 String responseCode = (String ) methodContext.getEnv(simpleMethod.getEventResponseCodeName()); 97 if (responseCode != null && responseCode.equals(simpleMethod.getDefaultErrorCode())) { 98 Debug.logWarning("Got error [" + responseCode + "] calling inline simple-method named [" + methodName + "] in resource [" + xmlResource + "], message is " + methodContext.getEnv(simpleMethod.getEventErrorMessageName()) , module); 99 return false; 100 } 101 } else if (methodContext.getMethodType() == MethodContext.SERVICE) { 102 String resonseMessage = (String ) methodContext.getEnv(simpleMethod.getServiceResponseMessageName()); 103 if (resonseMessage != null && resonseMessage.equals(simpleMethod.getDefaultErrorCode())) { 104 Debug.logWarning("Got error [" + resonseMessage + "] calling inline simple-method named [" + methodName + "] in resource [" + xmlResource + "], message is " + methodContext.getEnv(simpleMethod.getServiceErrorMessageName()) + ", and the error message list is: " + methodContext.getEnv(simpleMethod.getServiceErrorMessageListName()), module); 105 return false; 106 } 107 } 108 } else { 109 String errMsg = "ERROR in call-simple-method: methodName was missing; not running simpleMethod"; 110 Debug.logError(errMsg, module); 111 methodContext.setErrorReturn(errMsg, simpleMethod); 112 return false; 113 } 114 115 return true; 116 } 117 118 public String rawString() { 119 return "<call-simple-method/>"; 121 } 122 public String expandedString(MethodContext methodContext) { 123 return this.rawString(); 125 } 126 } 127 | Popular Tags |