Is it not a bit confusing (it's not a field at all), was not value enough?

Jacques

From: <[email protected]>
Author: adrianc
Date: Fri Sep  2 20:55:15 2011
New Revision: 1164712

URL: http://svn.apache.org/viewvc?rev=1164712&view=rev
Log:
Improved mini-language <set> operation: now supports groovy: syntax in the 
from-field attribute.

Modified:
   
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/SetOperation.java

Modified: 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/SetOperation.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/SetOperation.java?rev=1164712&r1=1164711&r2=1164712&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/SetOperation.java
 (original)
+++ 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/SetOperation.java
 Fri Sep  2 20:55:15 2011
@@ -21,8 +21,10 @@ package org.ofbiz.minilang.method.envops
import javolution.util.FastList;
import javolution.util.FastMap;

+import org.codehaus.groovy.runtime.InvokerHelper;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
+import org.ofbiz.base.util.GroovyUtil;
import org.ofbiz.base.util.ObjectType;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.string.FlexibleStringExpander;
@@ -54,11 +56,16 @@ public class SetOperation extends Method
    protected String type;
    protected boolean setIfNull; // default to false
    protected boolean setIfEmpty; // default to true
+    protected Class<?> parsedGroovyScript = null;

    public SetOperation(Element element, SimpleMethod simpleMethod) {
        super(element, simpleMethod);
        this.field = new ContextAccessor<Object>(element.getAttribute("field"));
-        this.fromField = new 
ContextAccessor<Object>(element.getAttribute("from-field"));
+        String fromFieldStr = element.getAttribute("from-field");
+        if (fromFieldStr != null && fromFieldStr.startsWith("groovy:")) {
+            this.parsedGroovyScript = 
GroovyUtil.parseClass(fromFieldStr.replace("groovy:", ""));
+        }
+        this.fromField = new ContextAccessor<Object>(fromFieldStr);
        this.valueExdr = 
FlexibleStringExpander.getInstance(element.getAttribute("value"));
        this.defaultExdr = 
FlexibleStringExpander.getInstance(element.getAttribute("default-value"));
        this.type = element.getAttribute("type");
@@ -75,7 +82,9 @@ public class SetOperation extends Method
    @Override
    public boolean exec(MethodContext methodContext) {
        Object newValue = null;
-        if (!this.fromField.isEmpty()) {
+        if (this.parsedGroovyScript != null) {
+ newValue = InvokerHelper.createScript(this.parsedGroovyScript, GroovyUtil.getBinding(methodContext.getEnvMap())).run();
+        } else if (!this.fromField.isEmpty()) {
            newValue = this.fromField.get(methodContext);
if (Debug.verboseOn()) Debug.logVerbose("In screen getting value for field from [" + this.fromField.toString() + "]: " + newValue, module);
        } else if (!this.valueExdr.isEmpty()) {




Reply via email to