svn commit: r1339228 - in /ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method: callops/ conditional/ envops/ ifops/ otherops/

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

svn commit: r1339228 - in /ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method: callops/ conditional/ envops/ ifops/ otherops/

adrianc
Author: adrianc
Date: Wed May 16 15:25:11 2012
New Revision: 1339228

URL: http://svn.apache.org/viewvc?rev=1339228&view=rev
Log:
A bunch of small fixups in Mini-language.

Modified:
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallSimpleMapProcessor.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/Compare.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/RegexpCondition.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ValidateMethodCondition.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/SetCalendar.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/SetOperation.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ToString.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfRegexp.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfValidateMethod.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java?rev=1339228&r1=1339227&r2=1339228&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java Wed May 16 15:25:11 2012
@@ -78,7 +78,7 @@ public final class CallService extends M
     public CallService(Element element, SimpleMethod simpleMethod) throws MiniLangException {
         super(element, simpleMethod);
         if (MiniLangValidate.validationOn()) {
-            MiniLangValidate.attributeNames(simpleMethod, element, "serviceName", "in-map-name", "include-user-login", "break-on-error", "error-code", "require-new-transaction", "transaction-timeout", "success-code");
+            MiniLangValidate.attributeNames(simpleMethod, element, "service-name", "in-map-name", "include-user-login", "break-on-error", "error-code", "require-new-transaction", "transaction-timeout", "success-code");
             MiniLangValidate.constantAttributes(simpleMethod, element, "include-user-login", "break-on-error", "error-code", "require-new-transaction", "transaction-timeout", "success-code");
             MiniLangValidate.expressionAttributes(simpleMethod, element, "service-name", "in-map-name");
             MiniLangValidate.requiredAttributes(simpleMethod, element, "service-name");

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallSimpleMapProcessor.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallSimpleMapProcessor.java?rev=1339228&r1=1339227&r2=1339228&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallSimpleMapProcessor.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallSimpleMapProcessor.java Wed May 16 15:25:11 2012
@@ -39,7 +39,7 @@ import org.w3c.dom.Element;
 /**
  * An event operation that calls a simple map processor inlined or from a separate file
  */
-public class CallSimpleMapProcessor extends MethodOperation {
+public final class CallSimpleMapProcessor extends MethodOperation {
 
     private final FlexibleMapAccessor<List<Object>> errorListFma;
     private final MapProcessor inlineMapProcessor;

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/Compare.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/Compare.java?rev=1339228&r1=1339227&r2=1339228&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/Compare.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/Compare.java Wed May 16 15:25:11 2012
@@ -28,7 +28,7 @@ import java.util.Map;
 import java.util.TimeZone;
 
 import org.ofbiz.base.util.Assert;
-import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.entity.GenericEntity;
 import org.ofbiz.minilang.MiniLangUtil;
 
@@ -200,7 +200,7 @@ public abstract class Compare {
         @Override
         public boolean doCompare(Object lValue, Object rValue, Class<?> type, Locale locale, TimeZone timeZone, String format) throws Exception {
             Object convertedLvalue = MiniLangUtil.convertType(lValue, type, locale, timeZone, format);
-            return UtilValidate.isEmpty(convertedLvalue);
+            return ObjectType.isEmpty(convertedLvalue);
         }
     }
 

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/RegexpCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/RegexpCondition.java?rev=1339228&r1=1339227&r2=1339228&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/RegexpCondition.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/RegexpCondition.java Wed May 16 15:25:11 2012
@@ -20,13 +20,12 @@ package org.ofbiz.minilang.method.condit
 
 import org.apache.oro.text.regex.MalformedPatternException;
 import org.ofbiz.base.util.CompilerMatcher;
-import org.ofbiz.base.util.GeneralException;
-import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.base.util.collections.FlexibleMapAccessor;
 import org.ofbiz.base.util.string.FlexibleStringExpander;
 import org.ofbiz.minilang.MiniLangElement;
 import org.ofbiz.minilang.MiniLangException;
 import org.ofbiz.minilang.MiniLangRuntimeException;
+import org.ofbiz.minilang.MiniLangUtil;
 import org.ofbiz.minilang.MiniLangValidate;
 import org.ofbiz.minilang.SimpleMethod;
 import org.ofbiz.minilang.method.MethodContext;
@@ -62,8 +61,8 @@ public class RegexpCondition extends Min
             fieldVal = "";
         } else if (!(fieldVal instanceof String)) {
             try {
-                fieldVal = ObjectType.simpleTypeConvert(fieldVal, "String", null, methodContext.getTimeZone(), methodContext.getLocale(), true);
-            } catch (GeneralException e) {
+                fieldVal = MiniLangUtil.convertType(fieldVal, String.class, methodContext.getLocale(), methodContext.getTimeZone(), null);
+            } catch (Exception e) {
                 throw new MiniLangRuntimeException(e, this);
             }
         }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ValidateMethodCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ValidateMethodCondition.java?rev=1339228&r1=1339227&r2=1339228&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ValidateMethodCondition.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ValidateMethodCondition.java Wed May 16 15:25:11 2012
@@ -20,12 +20,11 @@ package org.ofbiz.minilang.method.condit
 
 import java.lang.reflect.Method;
 
-import org.ofbiz.base.util.GeneralException;
-import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.base.util.collections.FlexibleMapAccessor;
 import org.ofbiz.minilang.MiniLangElement;
 import org.ofbiz.minilang.MiniLangException;
 import org.ofbiz.minilang.MiniLangRuntimeException;
+import org.ofbiz.minilang.MiniLangUtil;
 import org.ofbiz.minilang.MiniLangValidate;
 import org.ofbiz.minilang.SimpleMethod;
 import org.ofbiz.minilang.method.MethodContext;
@@ -63,8 +62,8 @@ public final class ValidateMethodConditi
             fieldVal = "";
         } else if (!(fieldVal instanceof String)) {
             try {
-                fieldVal = ObjectType.simpleTypeConvert(fieldVal, "String", null, methodContext.getTimeZone(), methodContext.getLocale(), true);
-            } catch (GeneralException e) {
+                fieldVal = MiniLangUtil.convertType(fieldVal, String.class, methodContext.getLocale(), methodContext.getTimeZone(), null);
+            } catch (Exception e) {
                 throw new MiniLangRuntimeException(e, this);
             }
         }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java?rev=1339228&r1=1339227&r2=1339228&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java Wed May 16 15:25:11 2012
@@ -92,16 +92,20 @@ public final class Assert extends Method
 
     @Override
     public String expandedString(MethodContext methodContext) {
-        String title = titleExdr.expandString(methodContext.getEnvMap());
+        return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap());
+    }
+
+    @Override
+    public String toString() {
         StringBuilder messageBuf = new StringBuilder("<assert");
-        if (!title.isEmpty()) {
+        if (!titleExdr.isEmpty()) {
             messageBuf.append(" title=\"");
-            messageBuf.append(title);
+            messageBuf.append(titleExdr);
             messageBuf.append("\"");
         }
         messageBuf.append(">");
         for (Conditional condition : conditionalList) {
-            condition.prettyPrint(messageBuf, methodContext);
+            messageBuf.append(condition);
         }
         messageBuf.append("</assert>");
         return messageBuf.toString();

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/SetCalendar.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/SetCalendar.java?rev=1339228&r1=1339227&r2=1339228&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/SetCalendar.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/SetCalendar.java Wed May 16 15:25:11 2012
@@ -27,6 +27,7 @@ import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.string.FlexibleStringExpander;
 import org.ofbiz.minilang.MiniLangException;
+import org.ofbiz.minilang.MiniLangUtil;
 import org.ofbiz.minilang.SimpleMethod;
 import org.ofbiz.minilang.method.ContextAccessor;
 import org.ofbiz.minilang.method.MethodContext;
@@ -133,7 +134,7 @@ public class SetCalendar extends MethodO
             if (timeZone == null) {
                 timeZone = TimeZone.getDefault();
             }
-            fromStamp = (Timestamp) ObjectType.simpleTypeConvert(newValue, "Timestamp", UtilDateTime.DATE_TIME_FORMAT, timeZone, locale, true);
+            fromStamp = (Timestamp) MiniLangUtil.convertType(newValue, java.sql.Timestamp.class, locale, timeZone, UtilDateTime.DATE_TIME_FORMAT);
         } catch (Exception e) {
             // Catching all exceptions - even potential ClassCastException
             if (Debug.verboseOn())

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=1339228&r1=1339227&r2=1339228&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 Wed May 16 15:25:11 2012
@@ -22,7 +22,6 @@ import javolution.util.FastList;
 import javolution.util.FastMap;
 
 import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.base.util.Scriptlet;
 import org.ofbiz.base.util.StringUtil;
@@ -79,6 +78,7 @@ public final class SetOperation extends
     private final Scriptlet scriptlet;
     private final boolean setIfEmpty;
     private final boolean setIfNull;
+    private final Class<?> targetClass;
     private final String type;
     private final FlexibleStringExpander valueFse;
 
@@ -113,6 +113,15 @@ public final class SetOperation extends
         this.valueFse = FlexibleStringExpander.getInstance(element.getAttribute("value"));
         this.defaultFse = FlexibleStringExpander.getInstance(element.getAttribute("default"));
         this.type = element.getAttribute("type");
+        Class<?> targetClass = null;
+        if (!this.type.isEmpty()) {
+            try {
+                targetClass = ObjectType.loadClass(this.type);
+            } catch (ClassNotFoundException e) {
+                MiniLangValidate.handleError("Invalid type " + this.type, simpleMethod, element);
+            }
+        }
+        this.targetClass = targetClass;
         this.setIfNull = "true".equals(element.getAttribute("set-if-null")); // default to false, anything but true is false
         this.setIfEmpty = !"false".equals(element.getAttribute("set-if-empty")); // default to true, anything but false is true
         if (!this.fromFma.isEmpty() && !this.valueFse.isEmpty()) {
@@ -157,8 +166,12 @@ public final class SetOperation extends
                 newValue = FastList.newInstance();
             } else {
                 try {
-                    newValue = ObjectType.simpleTypeConvert(newValue, this.type, null, methodContext.getTimeZone(), methodContext.getLocale(), true);
-                } catch (GeneralException e) {
+                    Class<?> targetClass = this.targetClass;
+                    if (targetClass == null) {
+                        targetClass = MiniLangUtil.getObjectClassForConversion(newValue);
+                    }
+                    newValue = MiniLangUtil.convertType(newValue, targetClass, methodContext.getLocale(), methodContext.getTimeZone(), null);
+                } catch (Exception e) {
                     String errMsg = "Could not convert field value for the field: [" + this.fieldFma.toString() + "] to the [" + this.type + "] type for the value [" + newValue + "]: " + e.toString();
                     Debug.logWarning(e, errMsg, module);
                     this.simpleMethod.addErrorMessage(methodContext, errMsg);

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ToString.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ToString.java?rev=1339228&r1=1339227&r2=1339228&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ToString.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ToString.java Wed May 16 15:25:11 2012
@@ -28,6 +28,7 @@ import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.base.util.StringUtil;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.minilang.MiniLangException;
+import org.ofbiz.minilang.MiniLangUtil;
 import org.ofbiz.minilang.SimpleMethod;
 import org.ofbiz.minilang.method.ContextAccessor;
 import org.ofbiz.minilang.method.MethodContext;
@@ -66,11 +67,11 @@ public class ToString extends MethodOper
         String outStr = null;
         try {
             if (UtilValidate.isNotEmpty(format)) {
-                outStr = (String) ObjectType.simpleTypeConvert(obj, "String", format, methodContext.getTimeZone(), methodContext.getLocale(), true);
+                outStr = (String) MiniLangUtil.convertType(obj, String.class, methodContext.getLocale(), methodContext.getTimeZone(), format);
             } else {
                 outStr = obj.toString();
             }
-        } catch (GeneralException e) {
+        } catch (Exception e) {
             Debug.logError(e, "", module);
             outStr = obj.toString();
         }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfRegexp.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfRegexp.java?rev=1339228&r1=1339227&r2=1339228&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfRegexp.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfRegexp.java Wed May 16 15:25:11 2012
@@ -27,11 +27,10 @@ import javolution.util.FastList;
 import org.apache.oro.text.regex.MalformedPatternException;
 import org.ofbiz.base.util.CompilerMatcher;
 import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.GeneralException;
-import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.base.util.string.FlexibleStringExpander;
 import org.ofbiz.minilang.MiniLangException;
+import org.ofbiz.minilang.MiniLangUtil;
 import org.ofbiz.minilang.SimpleMethod;
 import org.ofbiz.minilang.method.ContextAccessor;
 import org.ofbiz.minilang.method.MethodContext;
@@ -85,8 +84,8 @@ public class IfRegexp extends MethodOper
         }
         if (fieldVal != null) {
             try {
-                fieldString = (String) ObjectType.simpleTypeConvert(fieldVal, "String", null, methodContext.getTimeZone(), methodContext.getLocale(), true);
-            } catch (GeneralException e) {
+                fieldString = (String) MiniLangUtil.convertType(fieldVal, String.class, methodContext.getLocale(), methodContext.getTimeZone(), null);
+            } catch (Exception e) {
                 Debug.logError(e, "Could not convert object to String, using empty String", module);
             }
         }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfValidateMethod.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfValidateMethod.java?rev=1339228&r1=1339227&r2=1339228&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfValidateMethod.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ifops/IfValidateMethod.java Wed May 16 15:25:11 2012
@@ -26,10 +26,9 @@ import java.util.Map;
 import javolution.util.FastList;
 
 import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.GeneralException;
-import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.minilang.MiniLangException;
+import org.ofbiz.minilang.MiniLangUtil;
 import org.ofbiz.minilang.MiniLangValidate;
 import org.ofbiz.minilang.SimpleMethod;
 import org.ofbiz.minilang.method.ContextAccessor;
@@ -87,8 +86,8 @@ public class IfValidateMethod extends Me
         }
         if (fieldVal != null) {
             try {
-                fieldString = (String) ObjectType.simpleTypeConvert(fieldVal, "String", null, methodContext.getTimeZone(), methodContext.getLocale(), true);
-            } catch (GeneralException e) {
+                fieldString = (String) MiniLangUtil.convertType(fieldVal, String.class, methodContext.getLocale(), methodContext.getTimeZone(), null);
+            } catch (Exception e) {
                 Debug.logError(e, "Could not convert object to String, using empty String", module);
             }
         }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java?rev=1339228&r1=1339227&r2=1339228&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java Wed May 16 15:25:11 2012
@@ -31,6 +31,7 @@ import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.minilang.MiniLangException;
+import org.ofbiz.minilang.MiniLangUtil;
 import org.ofbiz.minilang.SimpleMethod;
 import org.ofbiz.minilang.method.ContextAccessor;
 import org.ofbiz.minilang.method.MethodContext;
@@ -348,7 +349,7 @@ public class Calculate extends MethodOpe
                 locale = Locale.getDefault();
             BigDecimal value;
             try {
-                BigDecimal parseVal = (BigDecimal) ObjectType.simpleTypeConvert(valueStr, "BigDecimal", null, null, locale, true);
+                BigDecimal parseVal = (BigDecimal) MiniLangUtil.convertType(valueStr, java.math.BigDecimal.class, locale, null, null);
                 value = parseVal.setScale(scale, roundingMode);
             } catch (Exception e) {
                 Debug.logError(e, "Could not parse the number string: " + valueStr, module);