Return-Path: X-Original-To: apmail-ofbiz-dev-archive@www.apache.org Delivered-To: apmail-ofbiz-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F27CA8E6F for ; Sat, 3 Sep 2011 11:22:54 +0000 (UTC) Received: (qmail 99661 invoked by uid 500); 3 Sep 2011 11:22:52 -0000 Delivered-To: apmail-ofbiz-dev-archive@ofbiz.apache.org Received: (qmail 98849 invoked by uid 500); 3 Sep 2011 11:22:44 -0000 Mailing-List: contact dev-help@ofbiz.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ofbiz.apache.org Delivered-To: mailing list dev@ofbiz.apache.org Received: (qmail 98829 invoked by uid 99); 3 Sep 2011 11:22:39 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Sep 2011 11:22:39 +0000 X-ASF-Spam-Status: No, hits=0.7 required=5.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [173.236.76.174] (HELO serv01.siteground309.com) (173.236.76.174) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Sep 2011 11:22:29 +0000 Received: from [86.186.146.81] (port=1432 helo=[192.168.1.64]) by serv01.siteground309.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1QzoIa-0007a2-P7 for dev@ofbiz.apache.org; Sat, 03 Sep 2011 06:22:08 -0500 Message-ID: <4E620DE0.1040802@sandglass-software.com> Date: Sat, 03 Sep 2011 12:22:08 +0100 From: Adrian Crum Organization: Sandglass Software User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1 MIME-Version: 1.0 To: dev@ofbiz.apache.org Subject: Re: svn commit: r1164712 - /ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/SetOperation.java References: <20110902205516.09D8D2388847@eris.apache.org> <38F0B236D7AD4ECBA9C9069C6BDA459B@inspiron530> In-Reply-To: <38F0B236D7AD4ECBA9C9069C6BDA459B@inspiron530> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - serv01.siteground309.com X-AntiAbuse: Original Domain - ofbiz.apache.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - sandglass-software.com X-Virus-Checked: Checked by ClamAV on apache.org I agree it is confusing. A while ago I suggested having another attribute like from-expression, but there wasn't much interest in it. The value attribute returns a String, while from-field attribute returns an Object. -Adrian On 9/3/2011 12:16 PM, Jacques Le Roux wrote: > Is it not a bit confusing (it's not a field at all), was not value > enough? > > Jacques > > From: >> 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 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(element.getAttribute("field")); >> - this.fromField = new >> ContextAccessor(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(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()) { >> >> > >