svn commit: r1335020 - /ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/Return.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1335020 - /ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/Return.java

adrianc
Author: adrianc
Date: Mon May  7 13:50:41 2012
New Revision: 1335020

URL: http://svn.apache.org/viewvc?rev=1335020&view=rev
Log:
Overhauled Mini-language <return> element.

Modified:
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/Return.java

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/Return.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/Return.java?rev=1335020&r1=1335019&r2=1335020&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/Return.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/Return.java Mon May  7 13:50:41 2012
@@ -18,8 +18,9 @@
  *******************************************************************************/
 package org.ofbiz.minilang.method.callops;
 
-import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.string.FlexibleStringExpander;
 import org.ofbiz.minilang.MiniLangException;
+import org.ofbiz.minilang.MiniLangValidate;
 import org.ofbiz.minilang.SimpleMethod;
 import org.ofbiz.minilang.method.MethodContext;
 import org.ofbiz.minilang.method.MethodOperation;
@@ -28,41 +29,48 @@ import org.w3c.dom.Element;
 /**
  * An event operation that returns the given response code
  */
-public class Return extends MethodOperation {
+public final class Return extends MethodOperation {
 
-    String responseCode;
+    private final FlexibleStringExpander responseCodeFse;
 
     public Return(Element element, SimpleMethod simpleMethod) throws MiniLangException {
         super(element, simpleMethod);
-        responseCode = element.getAttribute("response-code");
-        if (UtilValidate.isEmpty(responseCode))
-            responseCode = "success";
+        if (MiniLangValidate.validationOn()) {
+            MiniLangValidate.attributeNames(simpleMethod, element, "response-code");
+            MiniLangValidate.noChildElements(simpleMethod, element);
+        }
+        responseCodeFse = FlexibleStringExpander.getInstance(MiniLangValidate.checkAttribute(element.getAttribute("response-code"), "success"));
     }
 
     @Override
     public boolean exec(MethodContext methodContext) throws MiniLangException {
-        String responseCode = methodContext.expandString(this.responseCode);
+        String responseCode = responseCodeFse.expandString(methodContext.getEnvMap());
         if (methodContext.getMethodType() == MethodContext.EVENT) {
             methodContext.putEnv(simpleMethod.getEventResponseCodeName(), responseCode);
-            return false;
-        } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
-            methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), responseCode);
-            return false;
         } else {
-            return false;
+            methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), responseCode);
         }
+        return false;
     }
 
     @Override
     public String expandedString(MethodContext methodContext) {
-        // TODO: something more than a stub/dummy
-        return this.rawString();
+        return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap());
     }
 
     @Override
     public String rawString() {
-        // TODO: something more than the empty tag
-        return "<return/>";
+        return toString();
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder("<return ");
+        if (!"success".equals(responseCodeFse.getOriginal())) {
+            sb.append("response-code=\"").append(responseCodeFse).append("\" ");
+        }
+        sb.append("/>");
+        return sb.toString();
     }
 
     public static final class ReturnFactory implements Factory<Return> {