Author: jonesde
Date: Sun Nov 12 13:24:52 2006 New Revision: 474048 URL: http://svn.apache.org/viewvc?view=rev&rev=474048 Log: Applied patch from Scott Gray to add while operation; it looks good but I made a small change to the java code in While.java to simplify how the while loop is managed, ie to be more direct; from Jira #OFBIZ-444 Added: incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/While.java (with props) Removed: incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/WhileCompare.java Modified: incubator/ofbiz/trunk/framework/minilang/dtd/simple-methods.xsd incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java Modified: incubator/ofbiz/trunk/framework/minilang/dtd/simple-methods.xsd URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/minilang/dtd/simple-methods.xsd?view=diff&rev=474048&r1=474047&r2=474048 ============================================================================== --- incubator/ofbiz/trunk/framework/minilang/dtd/simple-methods.xsd (original) +++ incubator/ofbiz/trunk/framework/minilang/dtd/simple-methods.xsd Sun Nov 12 13:24:52 2006 @@ -1401,6 +1401,15 @@ </xs:sequence> </xs:complexType> </xs:element> + <xs:element name="while" substitutionGroup="IfOtherOperations"> + <xs:annotation><xs:documentation>While loop operation, uses the same condition element as the if operation.</xs:documentation></xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element ref="condition"/> + <xs:element ref="then"/> + </xs:sequence> + </xs:complexType> + </xs:element> <xs:element name="condition"> <xs:complexType> <xs:group ref="IfConditions"/> @@ -1760,22 +1769,6 @@ <xs:attributeGroup name="attlist.number"> <xs:attribute type="xs:string" name="value" use="required"/> </xs:attributeGroup> - <xs:element name="while-compare" substitutionGroup="ControlOperations"> - <xs:complexType> - <xs:sequence> - <xs:group minOccurs="0" maxOccurs="unbounded" ref="AllOperations"/> - </xs:sequence> - <xs:attributeGroup ref="attlist.while-compare"/> - <xs:attributeGroup ref="attlist.operatorRequired"/> - <xs:attributeGroup ref="attlist.typeDefaultString"/> - </xs:complexType> - </xs:element> - <xs:attributeGroup name="attlist.while-compare"> - <xs:attribute type="xs:string" name="map-name"/> - <xs:attribute type="xs:string" name="field-name" use="required"/> - <xs:attribute type="xs:string" name="value" use="required"/> - <xs:attribute type="xs:string" name="format"/> - </xs:attributeGroup> <!-- ====================================================== ========== The Simple Map Processor Section ========== Modified: incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java?view=diff&rev=474048&r1=474047&r2=474048 ============================================================================== --- incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java (original) +++ incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java Sun Nov 12 13:24:52 2006 @@ -802,8 +802,6 @@ methodOperations.add(new org.ofbiz.minilang.method.envops.Loop(curOperElem, simpleMethod)); } else if ("first-from-list".equals(nodeName)) { methodOperations.add(new org.ofbiz.minilang.method.envops.FirstFromList(curOperElem, simpleMethod)); - } else if ("while-compare".equals(nodeName)) { - methodOperations.add(new org.ofbiz.minilang.method.envops.WhileCompare(curOperElem, simpleMethod)); } else if ("transaction-begin".equals(nodeName)) { methodOperations.add(new org.ofbiz.minilang.method.entityops.TransactionBegin(curOperElem, simpleMethod)); @@ -880,6 +878,8 @@ methodOperations.add(new org.ofbiz.minilang.method.conditional.Assert(curOperElem, simpleMethod)); } else if ("if".equals(nodeName)) { methodOperations.add(new org.ofbiz.minilang.method.conditional.MasterIf(curOperElem, simpleMethod)); + } else if ("while".equals(nodeName)) { + methodOperations.add(new org.ofbiz.minilang.method.conditional.While(curOperElem, simpleMethod)); } else if ("if-validate-method".equals(nodeName)) { methodOperations.add(new org.ofbiz.minilang.method.ifops.IfValidateMethod(curOperElem, simpleMethod)); } else if ("if-instance-of".equals(nodeName)) { Added: incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/While.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/While.java?view=auto&rev=474048 ============================================================================== --- incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/While.java (added) +++ incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/While.java Sun Nov 12 13:24:52 2006 @@ -0,0 +1,69 @@ +/* + * Copyright 2001-2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package org.ofbiz.minilang.method.conditional; + +import java.util.*; + +import org.w3c.dom.*; +import org.ofbiz.base.util.*; +import org.ofbiz.minilang.*; +import org.ofbiz.minilang.method.*; +import org.ofbiz.minilang.method.conditional.Conditional; +import org.ofbiz.minilang.method.conditional.ConditionalFactory; + +/** + * Continually processes sub-ops while the condition remains true + */ +public class While extends MethodOperation { + + Conditional condition; + + List thenSubOps = new LinkedList(); + + public While(Element element, SimpleMethod simpleMethod) { + super(element, simpleMethod); + + Element conditionElement = UtilXml.firstChildElement(element, "condition"); + Element conditionChildElement = UtilXml.firstChildElement(conditionElement); + this.condition = ConditionalFactory.makeConditional(conditionChildElement, simpleMethod); + + Element thenElement = UtilXml.firstChildElement(element, "then"); + SimpleMethod.readOperations(thenElement, thenSubOps, simpleMethod); + } + + public boolean exec(MethodContext methodContext) { + // if conditions fails, always return true; + // if a sub-op returns false return false and stop, otherwise drop though loop and return true + while (condition.checkCondition(methodContext)) { + boolean runSubOpsResult = SimpleMethod.runSubOps(thenSubOps, methodContext); + if (!runSubOpsResult) { + return false; + } + } + return true; + } + + public String rawString() { + return expandedString(null); + } + + public String expandedString(MethodContext methodContext) { + // TODO: fill in missing details, if needed + StringBuffer messageBuf = new StringBuffer(); + this.condition.prettyPrint(messageBuf, methodContext); + return "<while><condition>" + messageBuf + "</condition></while>"; + } +} Propchange: incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/While.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/While.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/While.java ------------------------------------------------------------------------------ svn:mime-type = text/plain |
Free forum by Nabble | Edit this page |