You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2006/11/10 14:21:46 UTC
svn commit: r473334 - in /incubator/ofbiz/trunk/framework/minilang:
dtd/simple-methods.xsd src/org/ofbiz/minilang/SimpleMethod.java
src/org/ofbiz/minilang/method/envops/WhileCompare.java
Author: jleroux
Date: Fri Nov 10 05:21:45 2006
New Revision: 473334
URL: http://svn.apache.org/viewvc?view=rev&rev=473334
Log:
Changes from a Scott Gray's patch : "Add a while-compare operation to minilang" (https://issues.apache.org/jira/browse/OFBIZ-444)
Thanks Scott
Added:
incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/WhileCompare.java (with props)
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=473334&r1=473333&r2=473334
==============================================================================
--- incubator/ofbiz/trunk/framework/minilang/dtd/simple-methods.xsd (original)
+++ incubator/ofbiz/trunk/framework/minilang/dtd/simple-methods.xsd Fri Nov 10 05:21:45 2006
@@ -1760,6 +1760,22 @@
<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=473334&r1=473333&r2=473334
==============================================================================
--- incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java (original)
+++ incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java Fri Nov 10 05:21:45 2006
@@ -802,6 +802,8 @@
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));
@@ -906,7 +908,6 @@
methodOperations.add(new org.ofbiz.minilang.method.otherops.Calculate(curOperElem, simpleMethod));
} else if ("log".equals(nodeName)) {
methodOperations.add(new org.ofbiz.minilang.method.otherops.Log(curOperElem, simpleMethod));
-
} else {
Debug.logWarning("Operation element \"" + nodeName + "\" no recognized", module);
}
Added: incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/WhileCompare.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/WhileCompare.java?view=auto&rev=473334
==============================================================================
--- incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/WhileCompare.java (added)
+++ incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/WhileCompare.java Fri Nov 10 05:21:45 2006
@@ -0,0 +1,126 @@
+/*
+ * 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.envops;
+
+import java.util.*;
+
+import javolution.util.FastList;
+
+import org.w3c.dom.*;
+import org.ofbiz.base.util.*;
+import org.ofbiz.minilang.*;
+import org.ofbiz.minilang.method.*;
+
+import org.ofbiz.minilang.operation.*;
+
+/**
+ * Continually processes sub-ops while the comparison between the constant and the specified field is true
+ *
+ */
+public class WhileCompare extends MethodOperation {
+
+ public static final String module = WhileCompare.class.getName();
+
+ List subOps = new LinkedList();
+
+ ContextAccessor mapAcsr;
+ ContextAccessor fieldAcsr;
+ String value;
+
+ String operator;
+ String type;
+ String format;
+
+ public WhileCompare(Element element, SimpleMethod simpleMethod) {
+ super(element, simpleMethod);
+ this.mapAcsr = new ContextAccessor(element.getAttribute("map-name"));
+ this.fieldAcsr = new ContextAccessor(element.getAttribute("field-name"));
+ this.value = element.getAttribute("value");
+
+ this.operator = element.getAttribute("operator");
+ this.type = element.getAttribute("type");
+ this.format = element.getAttribute("format");
+
+ SimpleMethod.readOperations(element, subOps, simpleMethod);
+ }
+
+ public boolean exec(MethodContext methodContext) {
+ String value = methodContext.expandString(this.value);
+ String operator = methodContext.expandString(this.operator);
+ String type = methodContext.expandString(this.type);
+ String format = methodContext.expandString(this.format);
+
+ while (true) {
+ Object fieldVal = null;
+ if (!mapAcsr.isEmpty()) {
+ Map fromMap = (Map) mapAcsr.get(methodContext);
+ if (fromMap == null) {
+ if (Debug.infoOn()) Debug.logInfo("Map not found with name " + mapAcsr + ", using empty string for comparison", module);
+ } else {
+ fieldVal = fieldAcsr.get(fromMap, methodContext);
+ }
+ } else {
+ // no map name, try the env
+ fieldVal = fieldAcsr.get(methodContext);
+ }
+
+ // always use an empty string by default
+ if (fieldVal == null) {
+ fieldVal = "";
+ }
+
+ List messages = FastList.newInstance();
+ Boolean resultBool = BaseCompare.doRealCompare(fieldVal, value, operator, type, format, messages, null, methodContext.getLoader(), true);
+ if (messages.size() > 0) {
+ messages.add(0, "Error with comparison in while-compare between field [" + mapAcsr.toString() + "." + fieldAcsr.toString() + "] with value [" + fieldVal + "] and value [" + value + "] with operator [" + operator + "] and type [" + type + "]: ");
+ if (methodContext.getMethodType() == MethodContext.EVENT) {
+ StringBuffer fullString = new StringBuffer();
+
+ Iterator miter = messages.iterator();
+ while (miter.hasNext()) {
+ fullString.append((String) miter.next());
+ }
+ Debug.logWarning(fullString.toString(), module);
+
+ methodContext.putEnv(simpleMethod.getEventErrorMessageName(), fullString.toString());
+ methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode());
+ } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
+ methodContext.putEnv(simpleMethod.getServiceErrorMessageListName(), messages);
+ methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode());
+ }
+ return false;
+ }
+
+ if (resultBool != null && resultBool.booleanValue()) {
+ boolean subOpResultBool = SimpleMethod.runSubOps(subOps, methodContext);
+ if (!subOpResultBool) {
+ return false;
+ }
+ } else {
+ return true;
+ }
+ }
+ }
+
+ public String rawString() {
+ // TODO: add all attributes and other info
+ return "<while-compare field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\" value=\"" + value + "\"/>";
+ }
+ public String expandedString(MethodContext methodContext) {
+ // TODO: something more than a stub/dummy
+ return this.rawString();
+ }
+}
Propchange: incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/WhileCompare.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/WhileCompare.java
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author URL Id"
Propchange: incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/WhileCompare.java
------------------------------------------------------------------------------
svn:mime-type = text/plain