1 24 25 package org.ofbiz.minilang.method.callops; 26 27 import java.util.*; 28 29 import org.w3c.dom.*; 30 import org.ofbiz.base.util.*; 31 32 import org.ofbiz.minilang.*; 33 import org.ofbiz.minilang.method.*; 34 35 42 public class CallClassMethod extends MethodOperation { 43 44 public static final String module = CallClassMethod.class.getName(); 45 46 String className; 47 String methodName; 48 ContextAccessor retFieldAcsr; 49 ContextAccessor retMapAcsr; 50 51 52 List parameters; 53 54 public CallClassMethod(Element element, SimpleMethod simpleMethod) { 55 super(element, simpleMethod); 56 className = element.getAttribute("class-name"); 57 methodName = element.getAttribute("method-name"); 58 retFieldAcsr = new ContextAccessor(element.getAttribute("ret-field-name")); 59 retMapAcsr = new ContextAccessor(element.getAttribute("ret-map-name")); 60 61 List parameterElements = UtilXml.childElementList(element); 62 if (parameterElements.size() > 0) { 63 parameters = new ArrayList(parameterElements.size()); 64 65 Iterator parameterIter = parameterElements.iterator(); 66 while (parameterIter.hasNext()) { 67 Element parameterElement = (Element) parameterIter.next(); 68 MethodObject methodObject = null; 69 if ("string".equals(parameterElement.getNodeName())) { 70 methodObject = new StringObject(parameterElement, simpleMethod); 71 } else if ("field".equals(parameterElement.getNodeName())) { 72 methodObject = new FieldObject(parameterElement, simpleMethod); 73 } else { 74 Debug.logWarning("Found an unsupported tag under the call-object-method tag: " + parameterElement.getNodeName() + "; ignoring", module); 76 } 77 if (methodObject != null) { 78 parameters.add(methodObject); 79 } 80 } 81 } 82 } 83 84 public boolean exec(MethodContext methodContext) { 85 String className = methodContext.expandString(this.className); 86 String methodName = methodContext.expandString(this.methodName); 87 88 Class methodClass = null; 89 try { 90 methodClass = ObjectType.loadClass(className, methodContext.getLoader()); 91 } catch (ClassNotFoundException e) { 92 Debug.logError(e, "Class to create not found with name " + className + " in create-object operation", module); 93 94 String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Class to create not found with name " + className + ": " + e.toString() + "]"; 95 methodContext.setErrorReturn(errMsg, simpleMethod); 96 return false; 97 } 98 99 return CallObjectMethod.callMethod(simpleMethod, methodContext, parameters, methodClass, null, methodName, retFieldAcsr, retMapAcsr); 100 } 101 102 public String rawString() { 103 return "<call-class-method/>"; 105 } 106 public String expandedString(MethodContext methodContext) { 107 return this.rawString(); 109 } 110 } 111 | Popular Tags |