svn commit: r1349182 - in /ofbiz/trunk/framework/minilang: dtd/ src/org/ofbiz/minilang/method/envops/

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

svn commit: r1349182 - in /ofbiz/trunk/framework/minilang: dtd/ src/org/ofbiz/minilang/method/envops/

adrianc
Author: adrianc
Date: Tue Jun 12 08:16:03 2012
New Revision: 1349182

URL: http://svn.apache.org/viewvc?rev=1349182&view=rev
Log:
Overhauled Mini-language <clear-field>, <create-object>, <field-to-list>, <first-from-list>, <list-to-list>, <map-to-map> elements.

The overhaul includes: removing unnecessary object creation, make the class thread-safe, add syntax validation, and misc code cleanups.

Modified:
    ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ClearField.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/CreateObject.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/FieldToList.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/FirstFromList.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ListToList.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/MapToMap.java

Modified: ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd?rev=1349182&r1=1349181&r2=1349182&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd (original)
+++ ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd Tue Jun 12 08:16:03 2012
@@ -1183,53 +1183,33 @@ under the License.
             </xs:attribute>
         </xs:complexType>
     </xs:element>
-    <xs:element name="create-object" substitutionGroup="CallOperations">
+    <xs:element name="create-object" substitutionGroup="EnvOperations">
         <xs:annotation>
             <xs:documentation>
-                Creates an object of the given class and if the field attribute is specified saves it in that field.
+                Creates an object of the specified class.
                 The string and field sub-elements are passed to the constructor method as arguments in the order they are specified.
                 If the sub-elements do not match the constructor method arguments an error will be returned.
+                &lt;br/&gt;&lt;br/&gt;
+                Deprecated - use the script element.
             </xs:documentation>
         </xs:annotation>
         <xs:complexType>
             <xs:choice minOccurs="0" maxOccurs="unbounded">
-                <xs:element ref="field">
-                    <xs:annotation>
-                        <xs:documentation>
-                            Used to specify a field to be passed as an argument to the constructor method.
-                            The field can be in a map in the environment or if no map-name is specified then
-                            the field will come directly from the environment.
-                        </xs:documentation>
-                    </xs:annotation>
-                </xs:element>
-                <xs:element ref="string">
-                    <xs:annotation>
-                        <xs:documentation>
-                            Used to specify an inline String argument to the method call.
-                        </xs:documentation>
-                    </xs:annotation>
-                </xs:element>
+                <xs:element ref="field" />
+                <xs:element ref="string" />
             </xs:choice>
-            <xs:attributeGroup ref="attlist.create-object"/>
+            <xs:attribute type="xs:token" name="class-name" use="required">
+                <xs:annotation>
+                    <xs:documentation>
+                        The name of the class to construct an instance of.
+                        &lt;br/&gt;&lt;br/&gt;
+                        Required. Attribute type: constant.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute ref="field" />
         </xs:complexType>
     </xs:element>
-    <xs:attributeGroup name="attlist.create-object">
-        <xs:attribute type="xs:string" name="class-name" use="required">
-            <xs:annotation>
-                <xs:documentation>
-                    The name of the class to construct an object of.
-                </xs:documentation>
-            </xs:annotation>
-        </xs:attribute>
-        <xs:attribute type="xs:string" name="field">
-            <xs:annotation>
-                <xs:documentation>
-                    The name of a field to put the new object in.
-                    If not specified the object will be created but ignored after that.
-                </xs:documentation>
-            </xs:annotation>
-        </xs:attribute>
-    </xs:attributeGroup>
     <!-- Operations to copy map fields in the current env to context specific containers -->
     <!-- Event specific operations -->
     <xs:element name="field-to-request" substitutionGroup="EventOperations">
@@ -1436,50 +1416,90 @@ under the License.
     <xs:element name="map-to-map" substitutionGroup="EnvOperations">
         <xs:annotation>
             <xs:documentation>
-                The map-to-map tag copies all fields from one map to another map.
+                Copies a map to another map. Does nothing if the source map does not exist.
+                If a target map is not specified, the source map is copied to the current
+                envirnment (memory space).
             </xs:documentation>
         </xs:annotation>
         <xs:complexType>
-            <xs:attributeGroup ref="attlist.map-to-map"/>
+            <xs:attribute type="xs:string" name="map" use="required">
+                <xs:annotation>
+                    <xs:documentation>
+                        The name of the map to copy from.
+                        &lt;br/&gt;&lt;br/&gt;
+                        Required. Attribute type: expression.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute type="xs:string" name="to-map">
+                <xs:annotation>
+                    <xs:documentation>
+                        The name of the map to copy to. If the target map does not exist, one will be created.
+                        If this attribute is empty, the source map will be copied to the current environment.
+                        &lt;br/&gt;&lt;br/&gt;
+                        Optional. Attribute type: expression.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
         </xs:complexType>
     </xs:element>
-    <xs:attributeGroup name="attlist.map-to-map">
-        <xs:attribute type="xs:string" name="map" use="required">
-            <xs:annotation><xs:documentation>The name of the map in the method environment the fields will come from.</xs:documentation></xs:annotation>
-        </xs:attribute>
-        <xs:attribute type="xs:string" name="to-map">
-            <xs:annotation>
-                <xs:documentation>
-                    The name of the map in the method environment the fields will go to.
-                    If empty the fields will be copied to the environment.
-                </xs:documentation>
-            </xs:annotation>
-        </xs:attribute>
-    </xs:attributeGroup>
     <xs:element name="field-to-list" substitutionGroup="EnvOperations">
-        <xs:annotation><xs:documentation>The field-to-list tag appends a field to the specified list.</xs:documentation></xs:annotation>
-        <xs:complexType><xs:attributeGroup ref="attlist.field-to-list"/></xs:complexType>
+        <xs:annotation>
+            <xs:documentation>
+                Appends an object to the specified list. Does nothing if the specified object does not exist.
+                &lt;br/&gt;&lt;br/&gt;
+                Deprecated - use the set element.
+            </xs:documentation>
+        </xs:annotation>
+        <xs:complexType>
+            <xs:attribute type="xs:token" name="field" use="required">
+                <xs:annotation>
+                    <xs:documentation>
+                        The field name of the object to append.
+                        &lt;br/&gt;&lt;br/&gt;
+                        Required. Attribute type: expression.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute type="xs:token" name="list" use="required">
+                <xs:annotation>
+                    <xs:documentation>
+                        The field name of the list that the object will be appended to.
+                        If the list does not exist, one will be created.
+                        &lt;br/&gt;&lt;br/&gt;
+                        Required. Attribute type: expression.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
+        </xs:complexType>
     </xs:element>
-    <xs:attributeGroup name="attlist.field-to-list">
-        <xs:attribute type="xs:string" name="field" use="required">
-            <xs:annotation><xs:documentation>The name (key) of the map field to use.</xs:documentation></xs:annotation>
-        </xs:attribute>
-        <xs:attribute type="xs:string" name="list" use="required">
-            <xs:annotation><xs:documentation>The name of the list in the method environment that the object will be appended to.</xs:documentation></xs:annotation>
-        </xs:attribute>
-    </xs:attributeGroup>
     <xs:element name="list-to-list" substitutionGroup="EnvOperations">
-        <xs:annotation><xs:documentation>Copy a list to another list.</xs:documentation></xs:annotation>
-        <xs:complexType><xs:attributeGroup ref="attlist.list-to-list"/></xs:complexType>
+        <xs:annotation>
+            <xs:documentation>
+                Copy a list to another list. Does nothing if the source list does not exist.
+            </xs:documentation>
+        </xs:annotation>
+        <xs:complexType>
+            <xs:attribute type="xs:string" name="list" use="required">
+                <xs:annotation>
+                    <xs:documentation>
+                        Name of the list to copy from.
+                        &lt;br/&gt;&lt;br/&gt;
+                        Required. Attribute type: expression.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute type="xs:string" name="to-list" use="required">
+                <xs:annotation>
+                    <xs:documentation>
+                        Name of the list to copy to. If the list does not exist, one will be created.
+                        &lt;br/&gt;&lt;br/&gt;
+                        Required. Attribute type: expression.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
+        </xs:complexType>
     </xs:element>
-    <xs:attributeGroup name="attlist.list-to-list">
-        <xs:attribute type="xs:string" name="list" use="required">
-            <xs:annotation><xs:documentation>Name of the list to copy from</xs:documentation></xs:annotation>
-        </xs:attribute>
-        <xs:attribute type="xs:string" name="to-list" use="required">
-            <xs:annotation><xs:documentation>Name of the list to copy to.</xs:documentation></xs:annotation>
-        </xs:attribute>
-    </xs:attributeGroup>
     <xs:element name="order-map-list" substitutionGroup="EnvOperations">
         <xs:annotation><xs:documentation>Sort a List containing Maps: order by fields names given in order-by sub-element.</xs:documentation>
         </xs:annotation>
@@ -1500,95 +1520,82 @@ under the License.
             </xs:documentation>
         </xs:annotation>
         <xs:complexType>
-            <xs:attributeGroup ref="attlist.set"/>
+            <xs:attribute ref="field" use="required" />
+            <xs:attribute type="xs:string" name="from-field">
+                <xs:annotation>
+                    <xs:documentation>
+                        Deprecated - use the from attribute.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute type="xs:string" name="from">
+                <xs:annotation>
+                    <xs:documentation>
+                        An expression or script that returns an object or null. The source of the assignment.
+                        &lt;br/&gt;&lt;br/&gt;
+                        A script must be prefixed with the script language followed by a colon (":").
+                        &lt;br/&gt;&lt;br/&gt;
+                        Required if the value attribute is empty. Attribute types: expression, script.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute type="xs:string" name="value">
+                <xs:annotation>
+                    <xs:documentation>
+                        A constant value, or a constant that includes an expression. The source of the assignment.
+                        &lt;br/&gt;&lt;br/&gt;
+                        Required if the from-field attribute is empty. Attribute type: constant+expr.
+                        Defaults to java.lang.String data type.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute type="xs:string" name="default-value">
+                <xs:annotation>
+                    <xs:documentation>
+                        Deprecated - use the default attribute.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute type="xs:string" name="default">
+                <xs:annotation>
+                    <xs:documentation>
+                        A default value that is used when the from-field attribute evaluates to null or empty.
+                        &lt;br/&gt;&lt;br/&gt;
+                        Optional. Attribute types: constant, ${expression}.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute type="xs:token" name="type">
+                <xs:annotation>
+                    <xs:documentation>
+                        The Java data type to convert to. "NewList" will create a new java.util.List, "NewMap" will create a new java.util.Map.
+                        &lt;br/&gt;&lt;br/&gt;
+                        Optional. Attribute type: constant. Attribute must contain a valid Java class name.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="set-if-null" type="booleanConst">
+                <xs:annotation>
+                    <xs:documentation>
+                        Controls if the target field can be set to null when the from-field attribute evaluates to null.
+                        Defaults to "false".
+                        &lt;br/&gt;&lt;br/&gt;
+                        Optional. Attribute type: constant.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute name="set-if-empty" type="booleanConst">
+                <xs:annotation>
+                    <xs:documentation>
+                        Controls if the target field can be set to an empty value. The meaning of "empty" depends on the Java data type.
+                        Defaults to "true".
+                        &lt;br/&gt;&lt;br/&gt;
+                        Optional. Attribute type: constant.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
         </xs:complexType>
     </xs:element>
-    <xs:attributeGroup name="attlist.set">
-        <xs:attribute ref="field" use="required" />
-        <xs:attribute type="xs:string" name="from-field">
-            <xs:annotation>
-                <xs:documentation>
-                    Deprecated - use &quot;from&quot;.
-                </xs:documentation>
-            </xs:annotation>
-        </xs:attribute>
-        <xs:attribute type="xs:string" name="from">
-            <xs:annotation>
-                <xs:documentation>
-                    An expression or script that returns an object or null. The source of the assignment.
-                    &lt;br/&gt;&lt;br/&gt;
-                    A script must be prefixed with the script language followed by a colon (&quot;:&quot;).
-                    &lt;br/&gt;&lt;br/&gt;
-                    Required if the value attribute is empty. Attribute types: expression, script.
-                </xs:documentation>
-            </xs:annotation>
-        </xs:attribute>
-        <xs:attribute type="xs:string" name="value">
-            <xs:annotation>
-                <xs:documentation>
-                    A constant value, or a constant that includes an expression. The source of the assignment.
-                    &lt;br/&gt;&lt;br/&gt;
-                    Required if the from-field attribute is empty. Attribute type: constant+expr.
-                    Defaults to java.lang.String data type.
-                </xs:documentation>
-            </xs:annotation>
-        </xs:attribute>
-        <xs:attribute type="xs:string" name="default-value">
-            <xs:annotation>
-                <xs:documentation>
-                    Deprecated - use &quot;default&quot;.
-                </xs:documentation>
-            </xs:annotation>
-        </xs:attribute>
-        <xs:attribute type="xs:string" name="default">
-            <xs:annotation>
-                <xs:documentation>
-                    A default value that is used if the from-field attribute evaluates to null or empty.
-                    &lt;br/&gt;&lt;br/&gt;
-                    Optional. Attribute types: constant+expr, expression. Expressions must be enclosed in ${}.
-                </xs:documentation>
-            </xs:annotation>
-        </xs:attribute>
-        <xs:attribute type="xs:string" name="type">
-            <xs:annotation>
-                <xs:documentation>
-                    The Java data type to convert to. &quot;NewList&quot; will create a new java.util.List, &quot;NewMap&quot; will create a new java.util.Map.
-                    &lt;br/&gt;&lt;br/&gt;
-                    Optional. Attribute type: constant. Attribute must contain a valid Java class name.
-                </xs:documentation>
-            </xs:annotation>
-        </xs:attribute>
-        <xs:attribute name="set-if-null">
-            <xs:annotation>
-                <xs:documentation>
-                    Controls if the target field can be set to null when the from-field attribute evaluates to null.
-                    &lt;br/&gt;&lt;br/&gt;
-                    Optional. Attribute type: constant. Defaults to &quot;false&quot;.
-                </xs:documentation>
-            </xs:annotation>
-            <xs:simpleType>
-                <xs:restriction base="xs:token">
-                    <xs:enumeration value="true"/>
-                    <xs:enumeration value="false"/>
-                </xs:restriction>
-            </xs:simpleType>
-        </xs:attribute>
-        <xs:attribute name="set-if-empty">
-            <xs:annotation>
-                <xs:documentation>
-                    Controls if the target field can be set to an empty value. The meaning of &quot;empty&quot; depends on the Java data type.
-                    &lt;br/&gt;&lt;br/&gt;
-                    Optional. Attribute type: constant. Defaults to &quot;true&quot;.
-                </xs:documentation>
-            </xs:annotation>
-            <xs:simpleType>
-                <xs:restriction base="xs:token">
-                    <xs:enumeration value="true"/>
-                    <xs:enumeration value="false"/>
-                </xs:restriction>
-            </xs:simpleType>
-        </xs:attribute>
-    </xs:attributeGroup>
     <xs:element name="string-append" substitutionGroup="EnvOperations">
         <xs:annotation>
             <xs:documentation>
@@ -1751,44 +1758,39 @@ under the License.
             </xs:documentation>
         </xs:annotation>
         <xs:complexType>
-            <xs:attributeGroup ref="attlist.clear-field"/>
+            <xs:attribute ref="field" />
         </xs:complexType>
     </xs:element>
-    <xs:attributeGroup name="attlist.clear-field">
-        <xs:attribute type="xs:string" name="field" use="required">
-            <xs:annotation>
-                <xs:documentation>
-                    The name (key) of the map field to use.
-                </xs:documentation>
-            </xs:annotation>
-        </xs:attribute>
-    </xs:attributeGroup>
     <xs:element name="first-from-list" substitutionGroup="EnvOperations">
         <xs:annotation>
             <xs:documentation>
-                The first-from-list tag will get the first entry from the given list and put it in the environment field with the given entry-name.
+                Assigns the first (lowest order) entry in the specified list to a field.
+                If the list does not exist or is empty, assigns null to a field.
+                &lt;br/&gt;&lt;br/&gt;
+                Deprecated - use the set element.
             </xs:documentation>
         </xs:annotation>
         <xs:complexType>
-            <xs:attributeGroup ref="attlist.first-from-list"/>
+            <xs:attribute type="xs:token" name="entry" use="required">
+                <xs:annotation>
+                    <xs:documentation>
+                        The name of the field to set. The target of the assignment.
+                        &lt;br/&gt;&lt;br/&gt;
+                        Required. Attribute type: expression.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
+            <xs:attribute type="xs:string" name="list" use="required">
+                <xs:annotation>
+                    <xs:documentation>
+                        The field name of the list that contains the object.
+                        &lt;br/&gt;&lt;br/&gt;
+                        Required. Attribute type: expression.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:attribute>
         </xs:complexType>
     </xs:element>
-    <xs:attributeGroup name="attlist.first-from-list">
-        <xs:attribute type="xs:string" name="entry" use="required">
-            <xs:annotation>
-                <xs:documentation>
-                    The name of the method environment field that will contain the first entry in the list.
-                </xs:documentation>
-            </xs:annotation>
-        </xs:attribute>
-        <xs:attribute type="xs:string" name="list" use="required">
-            <xs:annotation>
-                <xs:documentation>
-                    The name of the method environment field that contains the list to get the first entry from.
-                </xs:documentation>
-            </xs:annotation>
-        </xs:attribute>
-    </xs:attributeGroup>
     <!--
         These operations are used to interact with a data source through the entity
         engine and facilitate related operations.

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ClearField.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ClearField.java?rev=1349182&r1=1349181&r2=1349182&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ClearField.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ClearField.java Tue Jun 12 08:16:03 2012
@@ -18,70 +18,66 @@
  *******************************************************************************/
 package org.ofbiz.minilang.method.envops;
 
-import java.util.Map;
-
-import javolution.util.FastMap;
-
-import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.collections.FlexibleMapAccessor;
+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.ContextAccessor;
 import org.ofbiz.minilang.method.MethodContext;
 import org.ofbiz.minilang.method.MethodOperation;
 import org.w3c.dom.Element;
 
 /**
- * Clears the specified field
+ * Implements the &lt;clear-field&gt; element.
  */
-public class ClearField extends MethodOperation {
+public final class ClearField extends MethodOperation {
 
-    public static final String module = ClearField.class.getName();
-
-    ContextAccessor<Object> fieldAcsr;
-    ContextAccessor<Map<String, Object>> mapAcsr;
+    private final FlexibleMapAccessor<Object> fieldFma;
 
     public ClearField(Element element, SimpleMethod simpleMethod) throws MiniLangException {
         super(element, simpleMethod);
-        // the schema for this element now just has the "field" attribute, though the old "field-name" and "map-name" pair is still supported
-        fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field"), element.getAttribute("field-name"));
-        mapAcsr = new ContextAccessor<Map<String, Object>>(element.getAttribute("map-name"));
+        if (MiniLangValidate.validationOn()) {
+            MiniLangValidate.attributeNames(simpleMethod, element, "field");
+            MiniLangValidate.requiredAttributes(simpleMethod, element, "field");
+            MiniLangValidate.expressionAttributes(simpleMethod, element, "field");
+            MiniLangValidate.noChildElements(simpleMethod, element);
+        }
+        this.fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field"));
     }
 
     @Override
     public boolean exec(MethodContext methodContext) throws MiniLangException {
-        if (!mapAcsr.isEmpty()) {
-            Map<String, Object> toMap = mapAcsr.get(methodContext);
-            if (toMap == null) {
-                // it seems silly to create a new map, but necessary since whenever
-                // an env field like a Map or List is referenced it should be created, even if empty
-                if (Debug.verboseOn())
-                    Debug.logVerbose("Map not found with name " + mapAcsr + ", creating new map", module);
-                toMap = FastMap.newInstance();
-                mapAcsr.put(methodContext, toMap);
-            }
-            fieldAcsr.put(toMap, null, methodContext);
-        } else {
-            fieldAcsr.put(methodContext, null);
-        }
+        fieldFma.put(methodContext.getEnvMap(), null);
         return true;
     }
 
     @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() {
-        return "<clear-field field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>";
+        return toString();
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder("<set ");
+        sb.append("field=\"").append(this.fieldFma).append("\" />");
+        return sb.toString();
     }
 
+    /**
+     * A factory for the &lt;clear-field&gt; element.
+     */
     public static final class ClearFieldFactory implements Factory<ClearField> {
+        @Override
         public ClearField createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
             return new ClearField(element, simpleMethod);
         }
 
+        @Override
         public String getName() {
             return "clear-field";
         }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/CreateObject.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/CreateObject.java?rev=1349182&r1=1349181&r2=1349182&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/CreateObject.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/CreateObject.java Tue Jun 12 08:16:03 2012
@@ -19,19 +19,19 @@
 package org.ofbiz.minilang.method.envops;
 
 import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
-import java.util.Map;
-
-import javolution.util.FastList;
-import javolution.util.FastMap;
 
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.base.util.collections.FlexibleMapAccessor;
+import org.ofbiz.base.util.string.FlexibleStringExpander;
 import org.ofbiz.minilang.MiniLangException;
+import org.ofbiz.minilang.MiniLangRuntimeException;
+import org.ofbiz.minilang.MiniLangValidate;
 import org.ofbiz.minilang.SimpleMethod;
-import org.ofbiz.minilang.method.ContextAccessor;
 import org.ofbiz.minilang.method.FieldObject;
 import org.ofbiz.minilang.method.MethodContext;
 import org.ofbiz.minilang.method.MethodObject;
@@ -40,57 +40,54 @@ import org.ofbiz.minilang.method.StringO
 import org.w3c.dom.Element;
 
 /**
- * Creates a Java object using the given fields as parameters
+ * Implements the &lt;create-object&gt; element.
  */
-public class CreateObject extends MethodOperation {
+public final class CreateObject extends MethodOperation {
 
     public static final String module = CreateObject.class.getName();
 
-    String className;
-    ContextAccessor<Object> fieldAcsr;
-    ContextAccessor<Map<String, Object>> mapAcsr;
-    /** A list of MethodObject objects to use as the method call parameters */
-    List<MethodObject<?>> parameters;
+    private final String className;
+    private final Class<?> targetClass;
+    private final FlexibleMapAccessor<Object> fieldFma;
+    private final List<MethodObject<?>> parameters;
 
     public CreateObject(Element element, SimpleMethod simpleMethod) throws MiniLangException {
         super(element, simpleMethod);
+        if (MiniLangValidate.validationOn()) {
+            MiniLangValidate.handleError("<create-object> element is deprecated (use <script>)", simpleMethod, element);
+            MiniLangValidate.attributeNames(simpleMethod, element, "class-name", "field");
+            MiniLangValidate.expressionAttributes(simpleMethod, element, "field");
+            MiniLangValidate.requiredAttributes(simpleMethod, element, "class-name", "field");
+            MiniLangValidate.childElements(simpleMethod, element, "string", "field");
+        }
         className = element.getAttribute("class-name");
-        // the schema for this element now just has the "field" attribute, though the old
-        // "field-name" and "map-name" pair is still supported
-        fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field"), element.getAttribute("field-name"));
-        mapAcsr = new ContextAccessor<Map<String, Object>>(element.getAttribute("map-name"));
+        Class<?> targetClass = null;
+        try {
+            targetClass = ObjectType.loadClass(this.className);
+        } catch (ClassNotFoundException e) {
+            MiniLangValidate.handleError("Class not found with name " + this.className, simpleMethod, element);
+        }
+        this.targetClass = targetClass;
+        fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field"));
         List<? extends Element> parameterElements = UtilXml.childElementList(element);
         if (parameterElements.size() > 0) {
-            parameters = FastList.newInstance();
+            ArrayList<MethodObject<?>> parameterList = new ArrayList<MethodObject<?>>(parameterElements.size());
             for (Element parameterElement : parameterElements) {
-                MethodObject<?> methodObject = null;
                 if ("string".equals(parameterElement.getNodeName())) {
-                    methodObject = new StringObject(parameterElement, simpleMethod);
+                    parameterList.add(new StringObject(parameterElement, simpleMethod));
                 } else if ("field".equals(parameterElement.getNodeName())) {
-                    methodObject = new FieldObject<Object>(parameterElement, simpleMethod);
-                } else {
-                    // whoops, invalid tag here, print warning
-                    Debug.logWarning("Found an unsupported tag under the call-object-method tag: " + parameterElement.getNodeName() + "; ignoring", module);
-                }
-                if (methodObject != null) {
-                    parameters.add(methodObject);
+                    parameterList.add(new FieldObject<Object>(parameterElement, simpleMethod));
                 }
             }
+            parameterList.trimToSize();
+            this.parameters = Collections.unmodifiableList(parameterList);
+        } else {
+            this.parameters = null;
         }
     }
 
     @Override
     public boolean exec(MethodContext methodContext) throws MiniLangException {
-        String className = methodContext.expandString(this.className);
-        Class<?> methodClass = null;
-        try {
-            methodClass = ObjectType.loadClass(className, methodContext.getLoader());
-        } catch (ClassNotFoundException e) {
-            Debug.logError(e, "Class to create not found with name " + className + " in create-object operation", module);
-            String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Class to create not found with name " + className + ": " + e.toString() + "]";
-            methodContext.setErrorReturn(errMsg, simpleMethod);
-            return false;
-        }
         Object[] args = null;
         Class<?>[] parameterTypes = null;
         if (parameters != null) {
@@ -113,75 +110,42 @@ public class CreateObject extends Method
             }
         }
         try {
-            Constructor<?> constructor = methodClass.getConstructor(parameterTypes);
-            try {
-                Object newObject = constructor.newInstance(args);
-                // if fieldAcsr is empty, ignore return value
-                if (!fieldAcsr.isEmpty()) {
-                    if (!mapAcsr.isEmpty()) {
-                        Map<String, Object> retMap = mapAcsr.get(methodContext);
-                        if (retMap == null) {
-                            retMap = FastMap.newInstance();
-                            mapAcsr.put(methodContext, retMap);
-                        }
-                        fieldAcsr.put(retMap, newObject, methodContext);
-                    } else {
-                        // no map name, use the env
-                        fieldAcsr.put(methodContext, newObject);
-                    }
-                }
-            } catch (InstantiationException e) {
-                Debug.logError(e, "Could not instantiate object in create-object operation", module);
-                String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Could not instantiate object: " + e.toString() + "]";
-                methodContext.setErrorReturn(errMsg, simpleMethod);
-                return false;
-            } catch (IllegalAccessException e) {
-                Debug.logError(e, "Illegal access constructing object in create-object operation", module);
-                String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Illegal access constructing object: " + e.toString() + "]";
-                methodContext.setErrorReturn(errMsg, simpleMethod);
-                return false;
-            } catch (IllegalArgumentException e) {
-                Debug.logError(e, "Illegal argument calling method in create-object operation", module);
-                String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Illegal argument calling constructor: " + e.toString() + "]";
-                methodContext.setErrorReturn(errMsg, simpleMethod);
-                return false;
-            } catch (InvocationTargetException e) {
-                Debug.logError(e.getTargetException(), "Constructor in create-object operation threw an exception", module);
-                String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Constructor in create-object threw an exception: " + e.getTargetException() + "]";
-                methodContext.setErrorReturn(errMsg, simpleMethod);
-                return false;
-            }
-        } catch (NoSuchMethodException e) {
-            Debug.logError(e, "Could not find constructor to execute in simple-method create-object operation", module);
-            String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Could not find constructor to execute: " + e.toString() + "]";
-            methodContext.setErrorReturn(errMsg, simpleMethod);
-            return false;
-        } catch (SecurityException e) {
-            Debug.logError(e, "Security exception finding constructor to execute in simple-method create-object operation", module);
-            String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Security exception finding constructor to execute: " + e.toString() + "]";
-            methodContext.setErrorReturn(errMsg, simpleMethod);
-            return false;
+            Constructor<?> constructor = targetClass.getConstructor(parameterTypes);
+            fieldFma.put(methodContext.getEnvMap(),constructor.newInstance(args));
+        } catch (Exception e) {
+            throw new MiniLangRuntimeException(e, this);
         }
         return true;
     }
 
     @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 "<create-object/>";
+        return toString();
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder("<create-object ");
+        sb.append("class-name=\"").append(this.className).append("\" ");
+        sb.append("field=\"").append(this.fieldFma).append("\" />");
+        return sb.toString();
     }
 
+    /**
+     * A factory for the &lt;create-object&gt; element.
+     */
     public static final class CreateObjectFactory implements Factory<CreateObject> {
+        @Override
         public CreateObject createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
             return new CreateObject(element, simpleMethod);
         }
 
+        @Override
         public String getName() {
             return "create-object";
         }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/FieldToList.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/FieldToList.java?rev=1349182&r1=1349181&r2=1349182&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/FieldToList.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/FieldToList.java Tue Jun 12 08:16:03 2012
@@ -19,82 +19,81 @@
 package org.ofbiz.minilang.method.envops;
 
 import java.util.List;
-import java.util.Map;
 
 import javolution.util.FastList;
 
-import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.collections.FlexibleMapAccessor;
+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.ContextAccessor;
 import org.ofbiz.minilang.method.MethodContext;
 import org.ofbiz.minilang.method.MethodOperation;
 import org.w3c.dom.Element;
 
 /**
- * Copies an environment field to a list
+ * Implements the &lt;field-to-list&gt; element.
  */
-public class FieldToList extends MethodOperation {
+public final class FieldToList extends MethodOperation {
 
-    public static final String module = FieldToList.class.getName();
-
-    ContextAccessor<Object> fieldAcsr;
-    ContextAccessor<List<Object>> listAcsr;
-    ContextAccessor<Map<String, ? extends Object>> mapAcsr;
+    private final FlexibleMapAccessor<Object> fieldFma;
+    private final FlexibleMapAccessor<List<Object>> listFma;
 
     public FieldToList(Element element, SimpleMethod simpleMethod) throws MiniLangException {
         super(element, simpleMethod);
-        // the schema for this element now just has the "field" attribute, though the old "field-name" and "map-name" pair is still supported
-        mapAcsr = new ContextAccessor<Map<String, ? extends Object>>(element.getAttribute("map-name"));
-        fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field"), element.getAttribute("field-name"));
-        listAcsr = new ContextAccessor<List<Object>>(element.getAttribute("list"), element.getAttribute("list-name"));
+        if (MiniLangValidate.validationOn()) {
+            MiniLangValidate.handleError("<field-to-list> element is deprecated (use <set>)", simpleMethod, element);
+            MiniLangValidate.attributeNames(simpleMethod, element, "field", "list");
+            MiniLangValidate.requiredAttributes(simpleMethod, element, "field", "list");
+            MiniLangValidate.expressionAttributes(simpleMethod, element, "field", "list");
+            MiniLangValidate.noChildElements(simpleMethod, element);
+        }
+        fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field"));
+        listFma = FlexibleMapAccessor.getInstance(element.getAttribute("list"));
     }
 
     @Override
     public boolean exec(MethodContext methodContext) throws MiniLangException {
-        Object fieldVal = null;
-        if (!mapAcsr.isEmpty()) {
-            Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext);
-            if (fromMap == null) {
-                Debug.logWarning("Map not found with name " + mapAcsr + ", Not copying to list", module);
-                return true;
+        Object fieldVal = fieldFma.get(methodContext.getEnvMap());
+        if (fieldVal != null) {
+            List<Object> toList = listFma.get(methodContext.getEnvMap());
+            if (toList == null) {
+                toList = FastList.newInstance();
+                listFma.put(methodContext.getEnvMap(), toList);
             }
-            fieldVal = fieldAcsr.get(fromMap, methodContext);
-        } else {
-            // no map name, try the env
-            fieldVal = fieldAcsr.get(methodContext);
-        }
-        if (fieldVal == null) {
-            Debug.logWarning("Field value not found with name " + fieldAcsr + " in Map with name " + mapAcsr + ", Not copying to list", module);
-            return true;
-        }
-        List<Object> toList = listAcsr.get(methodContext);
-        if (toList == null) {
-            if (Debug.verboseOn())
-                Debug.logVerbose("List not found with name " + listAcsr + ", creating new list", module);
-            toList = FastList.newInstance();
-            listAcsr.put(methodContext, toList);
+            toList.add(fieldVal);
         }
-        toList.add(fieldVal);
         return true;
     }
 
     @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() {
-        return "<field-to-list list-name=\"" + this.listAcsr + "\" field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>";
+        return toString();
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder("<field-to-list ");
+        sb.append("field=\"").append(this.fieldFma).append("\" ");
+        sb.append("list=\"").append(this.listFma).append("\" />");
+        return sb.toString();
     }
 
+    /**
+     * A factory for the &lt;field-to-list&gt; element.
+     */
     public static final class FieldToListFactory implements Factory<FieldToList> {
+        @Override
         public FieldToList createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
             return new FieldToList(element, simpleMethod);
         }
 
+        @Override
         public String getName() {
             return "field-to-list";
         }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/FirstFromList.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/FirstFromList.java?rev=1349182&r1=1349181&r2=1349182&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/FirstFromList.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/FirstFromList.java Tue Jun 12 08:16:03 2012
@@ -20,62 +20,76 @@ package org.ofbiz.minilang.method.envops
 
 import java.util.List;
 
-import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.collections.FlexibleMapAccessor;
+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.ContextAccessor;
 import org.ofbiz.minilang.method.MethodContext;
 import org.ofbiz.minilang.method.MethodOperation;
 import org.w3c.dom.Element;
 
 /**
- * Get the first entry from the list
+ * Implements the &lt;first-from-list&gt; element.
  */
-public class FirstFromList extends MethodOperation {
+public final class FirstFromList extends MethodOperation {
 
-    public static final String module = FirstFromList.class.getName();
-
-    ContextAccessor<Object> entryAcsr;
-    ContextAccessor<List<? extends Object>> listAcsr;
+    private final FlexibleMapAccessor<Object> entryFma;
+    private final FlexibleMapAccessor<List<Object>> listFma;
 
     public FirstFromList(Element element, SimpleMethod simpleMethod) throws MiniLangException {
         super(element, simpleMethod);
-        this.entryAcsr = new ContextAccessor<Object>(element.getAttribute("entry"), element.getAttribute("entry-name"));
-        this.listAcsr = new ContextAccessor<List<? extends Object>>(element.getAttribute("list"), element.getAttribute("list-name"));
+        if (MiniLangValidate.validationOn()) {
+            MiniLangValidate.handleError("<first-from-list> element is deprecated (use <set>)", simpleMethod, element);
+            MiniLangValidate.attributeNames(simpleMethod, element, "entry", "list");
+            MiniLangValidate.requiredAttributes(simpleMethod, element, "entry", "list");
+            MiniLangValidate.expressionAttributes(simpleMethod, element, "entry", "list");
+            MiniLangValidate.noChildElements(simpleMethod, element);
+        }
+        entryFma = FlexibleMapAccessor.getInstance(element.getAttribute("entry"));
+        listFma = FlexibleMapAccessor.getInstance(element.getAttribute("list"));
     }
 
     @Override
     public boolean exec(MethodContext methodContext) throws MiniLangException {
-        if (listAcsr.isEmpty()) {
-            Debug.logWarning("No list-name specified in iterate tag, doing nothing", module);
-            return true;
-        }
-        List<? extends Object> theList = listAcsr.get(methodContext);
+        List<? extends Object> theList = listFma.get(methodContext.getEnvMap());
         if (UtilValidate.isEmpty(theList)) {
-            entryAcsr.put(methodContext, null);
-            return true;
+            entryFma.put(methodContext.getEnvMap(), null);
+        } else {
+            entryFma.put(methodContext.getEnvMap(), theList.get(0));
         }
-        entryAcsr.put(methodContext, theList.get(0));
         return true;
     }
 
     @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() {
-        return "<first-from-list list-name=\"" + this.listAcsr + "\" entry-name=\"" + this.entryAcsr + "\"/>";
+        return toString();
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder("<first-from-list ");
+        sb.append("entry=\"").append(this.entryFma).append("\" ");
+        sb.append("list=\"").append(this.listFma).append("\" />");
+        return sb.toString();
     }
 
+    /**
+     * A factory for the &lt;first-from-list&gt; element.
+     */
     public static final class FirstFromListFactory implements Factory<FirstFromList> {
+        @Override
         public FirstFromList createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
             return new FirstFromList(element, simpleMethod);
         }
 
+        @Override
         public String getName() {
             return "first-from-list";
         }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ListToList.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ListToList.java?rev=1349182&r1=1349181&r2=1349182&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ListToList.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ListToList.java Tue Jun 12 08:16:03 2012
@@ -22,66 +22,77 @@ import java.util.List;
 
 import javolution.util.FastList;
 
-import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.collections.FlexibleMapAccessor;
+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.ContextAccessor;
 import org.ofbiz.minilang.method.MethodContext;
 import org.ofbiz.minilang.method.MethodOperation;
 import org.w3c.dom.Element;
 
 /**
- * Copies an environment field to a list
+ * Implements the &lt;list-to-list&gt; element.
  */
-public class ListToList extends MethodOperation {
+public final class ListToList extends MethodOperation {
 
-    public static final String module = ListToList.class.getName();
-
-    ContextAccessor<List<Object>> listAcsr;
-    ContextAccessor<List<Object>> toListAcsr;
+    private final FlexibleMapAccessor<List<Object>> listFma;
+    private final FlexibleMapAccessor<List<Object>> toListFma;
 
     public ListToList(Element element, SimpleMethod simpleMethod) throws MiniLangException {
         super(element, simpleMethod);
-        listAcsr = new ContextAccessor<List<Object>>(element.getAttribute("list"), element.getAttribute("list-name"));
-        toListAcsr = new ContextAccessor<List<Object>>(element.getAttribute("to-list"), element.getAttribute("to-list-name"));
+        if (MiniLangValidate.validationOn()) {
+            MiniLangValidate.attributeNames(simpleMethod, element, "to-list", "list");
+            MiniLangValidate.requiredAttributes(simpleMethod, element, "to-list", "list");
+            MiniLangValidate.expressionAttributes(simpleMethod, element, "to-list", "list");
+            MiniLangValidate.noChildElements(simpleMethod, element);
+        }
+        toListFma = FlexibleMapAccessor.getInstance(element.getAttribute("to-list"));
+        listFma = FlexibleMapAccessor.getInstance(element.getAttribute("list"));
     }
 
     @Override
     public boolean exec(MethodContext methodContext) throws MiniLangException {
-        List<Object> fromList = listAcsr.get(methodContext);
-        List<Object> toList = toListAcsr.get(methodContext);
-        if (fromList == null) {
-            if (Debug.infoOn())
-                Debug.logInfo("List not found with name " + listAcsr + ", not copying list", module);
-            return true;
-        }
-        if (toList == null) {
-            if (Debug.verboseOn())
-                Debug.logVerbose("List not found with name " + toListAcsr + ", creating new list", module);
-            toList = FastList.newInstance();
-            toListAcsr.put(methodContext, toList);
+        List<Object> fromList = listFma.get(methodContext.getEnvMap());
+        if (fromList != null) {
+            List<Object> toList = toListFma.get(methodContext.getEnvMap());
+            if (toList == null) {
+                toList = FastList.newInstance();
+                toListFma.put(methodContext.getEnvMap(), toList);
+            }
+            toList.addAll(fromList);
         }
-        toList.addAll(fromList);
         return true;
     }
 
     @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 "<list-to-list/>";
+        return toString();
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder("<list-to-list ");
+        sb.append("to-list=\"").append(this.toListFma).append("\" ");
+        sb.append("list=\"").append(this.listFma).append("\" />");
+        return sb.toString();
     }
 
+    /**
+     * A factory for the &lt;list-to-list&gt; element.
+     */
     public static final class ListToListFactory implements Factory<ListToList> {
+        @Override
         public ListToList createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
             return new ListToList(element, simpleMethod);
         }
 
+        @Override
         public String getName() {
             return "list-to-list";
         }

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/MapToMap.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/MapToMap.java?rev=1349182&r1=1349181&r2=1349182&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/MapToMap.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/MapToMap.java Tue Jun 12 08:16:03 2012
@@ -22,74 +22,84 @@ import java.util.Map;
 
 import javolution.util.FastMap;
 
-import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.collections.FlexibleMapAccessor;
+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.ContextAccessor;
 import org.ofbiz.minilang.method.MethodContext;
 import org.ofbiz.minilang.method.MethodOperation;
 import org.w3c.dom.Element;
 
 /**
- * Copies a map field to a map field
+ * Implements the &lt;map-to-map&gt; element.
  */
-public class MapToMap extends MethodOperation {
+public final class MapToMap extends MethodOperation {
 
-    public static final String module = MapToMap.class.getName();
-
-    ContextAccessor<Map<String, Object>> mapAcsr;
-    ContextAccessor<Map<String, Object>> toMapAcsr;
+    private final FlexibleMapAccessor<Map<String, Object>> mapFma;
+    private final FlexibleMapAccessor<Map<String, Object>> toMapFma;
 
     public MapToMap(Element element, SimpleMethod simpleMethod) throws MiniLangException {
         super(element, simpleMethod);
-        mapAcsr = new ContextAccessor<Map<String, Object>>(element.getAttribute("map"), element.getAttribute("map-name"));
-        toMapAcsr = new ContextAccessor<Map<String, Object>>(element.getAttribute("to-map"), element.getAttribute("to-map-name"));
+        if (MiniLangValidate.validationOn()) {
+            MiniLangValidate.attributeNames(simpleMethod, element, "to-map", "map");
+            MiniLangValidate.requiredAttributes(simpleMethod, element, "map");
+            MiniLangValidate.expressionAttributes(simpleMethod, element, "to-map", "map");
+            MiniLangValidate.noChildElements(simpleMethod, element);
+        }
+        mapFma = FlexibleMapAccessor.getInstance(element.getAttribute("map"));
+        toMapFma = FlexibleMapAccessor.getInstance(element.getAttribute("to-map"));
     }
 
     @Override
     public boolean exec(MethodContext methodContext) throws MiniLangException {
-        Map<String, Object> fromMap = null;
-        if (!mapAcsr.isEmpty()) {
-            fromMap = mapAcsr.get(methodContext);
-            if (fromMap == null) {
-                if (Debug.infoOn())
-                    Debug.logInfo("Map not found with name " + mapAcsr + ", not copying from this map", module);
-                fromMap = FastMap.newInstance();
-                mapAcsr.put(methodContext, fromMap);
-            }
-        }
-        if (!toMapAcsr.isEmpty()) {
-            Map<String, Object> toMap = toMapAcsr.get(methodContext);
-            if (toMap == null) {
-                if (Debug.verboseOn())
-                    Debug.logVerbose("Map not found with name " + toMapAcsr + ", creating new map", module);
-                toMap = FastMap.newInstance();
-                toMapAcsr.put(methodContext, toMap);
+        Map<String, Object> fromMap = mapFma.get(methodContext.getEnvMap());
+        if (fromMap != null) {
+            if (!toMapFma.isEmpty()) {
+                Map<String, Object> toMap = toMapFma.get(methodContext.getEnvMap());
+                if (toMap == null) {
+                    toMap = FastMap.newInstance();
+                    toMapFma.put(methodContext.getEnvMap(), toMap);
+                    toMap.putAll(fromMap);
+                }
+            } else {
+                methodContext.putAllEnv(fromMap);
             }
-            toMap.putAll(fromMap);
-        } else {
-            methodContext.putAllEnv(fromMap);
         }
         return true;
     }
 
     @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 "<map-to-map/>";
+        return toString();
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder("<map-to-map ");
+        sb.append("map=\"").append(this.mapFma).append("\" ");
+        if (!toMapFma.isEmpty()) {
+            sb.append("to-map=\"").append(this.toMapFma).append("\" ");
+        }
+        sb.append("/>");
+        return sb.toString();
     }
 
+    /**
+     * A factory for the &lt;map-to-map&gt; element.
+     */
     public static final class MapToMapFactory implements Factory<MapToMap> {
+        @Override
         public MapToMap createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
             return new MapToMap(element, simpleMethod);
         }
 
+        @Override
         public String getName() {
             return "map-to-map";
         }