You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2012/07/03 16:40:13 UTC
svn commit: r1356759 - in
/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops:
Assert.java CheckErrors.java
Author: adrianc
Date: Tue Jul 3 14:40:12 2012
New Revision: 1356759
URL: http://svn.apache.org/viewvc?rev=1356759&view=rev
Log:
Added trace support to Mini-language <assert> and <check-errors> elements. Also fixed a bug in the <assert> element where it created an error list when there were no errors.
Modified:
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/CheckErrors.java
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=1356759&r1=1356758&r2=1356759&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 Tue Jul 3 14:40:12 2012
@@ -37,7 +37,9 @@ import org.ofbiz.minilang.method.conditi
import org.w3c.dom.Element;
/**
- * Adds an error to the error list for each condition that evaluates to false.
+ * Implements the <assert> element.
+ *
+ * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Cassert%3E}}">Mini-language Reference</a>
*/
public final class Assert extends MethodOperation {
@@ -68,11 +70,10 @@ public final class Assert extends Method
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
- List<Object> messages = errorListFma.get(methodContext.getEnvMap());
- if (messages == null) {
- messages = FastList.newInstance();
- errorListFma.put(methodContext.getEnvMap(), messages);
+ if (methodContext.isTraceOn()) {
+ outputTraceMessage(methodContext, "Begin assert.");
}
+ List<Object> messages = errorListFma.get(methodContext.getEnvMap());
String title = titleExdr.expandString(methodContext.getEnvMap());
for (Conditional condition : conditionalList) {
if (!condition.checkCondition(methodContext)) {
@@ -84,9 +85,19 @@ public final class Assert extends Method
}
messageBuffer.append("failed: ");
condition.prettyPrint(messageBuffer, methodContext);
+ if (messages == null) {
+ messages = FastList.newInstance();
+ errorListFma.put(methodContext.getEnvMap(), messages);
+ }
messages.add(messageBuffer.toString());
+ if (methodContext.isTraceOn()) {
+ outputTraceMessage(methodContext, "Condition evaluated to false: " + condition + ", adding error message.");
+ }
}
}
+ if (methodContext.isTraceOn()) {
+ outputTraceMessage(methodContext, "End assert.");
+ }
return true;
}
@@ -106,11 +117,16 @@ public final class Assert extends Method
return messageBuf.toString();
}
+ /**
+ * A factory for the <assert> element.
+ */
public static final class AssertFactory implements Factory<Assert> {
+ @Override
public Assert createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
return new Assert(element, simpleMethod);
}
+ @Override
public String getName() {
return "assert";
}
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/CheckErrors.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/CheckErrors.java?rev=1356759&r1=1356758&r2=1356759&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/CheckErrors.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/CheckErrors.java Tue Jul 3 14:40:12 2012
@@ -29,7 +29,9 @@ import org.ofbiz.minilang.method.MethodO
import org.w3c.dom.Element;
/**
- * Halts script execution if the error message list contains any messages.
+ * Implements the <check-errors> element.
+ *
+ * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Ccheckerrors%3E}}">Mini-language Reference</a>
*/
public final class CheckErrors extends MethodOperation {
@@ -40,7 +42,6 @@ public final class CheckErrors extends M
super(element, simpleMethod);
if (MiniLangValidate.validationOn()) {
MiniLangValidate.attributeNames(simpleMethod, element, "error-code", "error-list-name");
- MiniLangValidate.constantPlusExpressionAttributes(simpleMethod, element, "error-code");
MiniLangValidate.noChildElements(simpleMethod, element);
}
this.errorCodeFse = FlexibleStringExpander.getInstance(element.getAttribute("error-code"));
@@ -49,6 +50,9 @@ public final class CheckErrors extends M
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
+ if (methodContext.isTraceOn()) {
+ outputTraceMessage(methodContext, "Begin check-errors.");
+ }
List<Object> messages = methodContext.getEnv(this.errorListNameFse.expandString(methodContext.getEnvMap()));
if (messages != null && messages.size() > 0) {
if (methodContext.getMethodType() == MethodContext.EVENT) {
@@ -58,14 +62,22 @@ public final class CheckErrors extends M
methodContext.putEnv(simpleMethod.getServiceErrorMessageListName(), messages);
methodContext.putEnv(this.simpleMethod.getServiceResponseMessageName(), getErrorCode(methodContext));
}
+ if (methodContext.isTraceOn()) {
+ outputTraceMessage(methodContext, "Found error messages. Setting error status and halting script execution.");
+ outputTraceMessage(methodContext, "End check-errors.");
+ }
return false;
}
+ if (methodContext.isTraceOn()) {
+ outputTraceMessage(methodContext, "No error messages found. Continuing script execution.");
+ outputTraceMessage(methodContext, "End check-errors.");
+ }
return true;
}
private String getErrorCode(MethodContext methodContext) {
String errorCode = this.errorCodeFse.expandString(methodContext.getEnvMap());
- if (errorCode.length() == 0) {
+ if (errorCode.isEmpty()) {
errorCode = this.simpleMethod.getDefaultErrorCode();
}
return errorCode;
@@ -84,11 +96,16 @@ public final class CheckErrors extends M
return sb.toString();
}
+ /**
+ * A factory for the <check-errors> element.
+ */
public static final class CheckErrorsFactory implements Factory<CheckErrors> {
+ @Override
public CheckErrors createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
return new CheckErrors(element, simpleMethod);
}
+ @Override
public String getName() {
return "check-errors";
}