This is an automated email from the ASF dual-hosted git repository.
mridulpathak pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push:
new 87239a9df0 Remove this-escape warnings in the minilang simple-map
operations
87239a9df0 is described below
commit 87239a9df00b4069ec9a72327b49d43a00670d60
Author: Mridul Pathak <[email protected]>
AuthorDate: Fri Oct 30 12:46:00 2026 +0530
Remove this-escape warnings in the minilang simple-map operations
SimpleMapProcess passed itself to each operation it built, and Copy and
Convert called the overridable getFieldName() from their constructors. The
operations now take the field name through package-private constructors, and
SimpleMapProcess builds its operation list in a static method. The public
constructors that took a SimpleMapProcess are removed, and the concrete
operations are final, since SimpleMapProcess is the only place that builds them.
---
.../ofbiz/minilang/operation/BaseCompare.java | 4 +--
.../apache/ofbiz/minilang/operation/Compare.java | 6 ++---
.../ofbiz/minilang/operation/CompareField.java | 6 ++---
.../apache/ofbiz/minilang/operation/Convert.java | 14 +++++------
.../org/apache/ofbiz/minilang/operation/Copy.java | 14 +++++------
.../apache/ofbiz/minilang/operation/NotEmpty.java | 6 ++---
.../apache/ofbiz/minilang/operation/Regexp.java | 6 ++---
.../minilang/operation/SimpleMapOperation.java | 6 ++---
.../ofbiz/minilang/operation/SimpleMapProcess.java | 29 +++++++++++++---------
.../ofbiz/minilang/operation/ValidateMethod.java | 6 ++---
10 files changed, 49 insertions(+), 48 deletions(-)
diff --git
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/BaseCompare.java
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/BaseCompare.java
index 0df4e9cf2a..d2cbd5c960 100644
---
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/BaseCompare.java
+++
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/BaseCompare.java
@@ -39,8 +39,8 @@ public abstract class BaseCompare extends SimpleMapOperation {
private String operator;
private String type;
- public BaseCompare(Element element, SimpleMapProcess simpleMapProcess) {
- super(element, simpleMapProcess);
+ BaseCompare(Element element, String fieldName) {
+ super(element, fieldName);
this.operator = element.getAttribute("operator");
this.type = element.getAttribute("type");
this.format = element.getAttribute("format");
diff --git
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Compare.java
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Compare.java
index 1db9c47f0b..2afab087bb 100644
---
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Compare.java
+++
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Compare.java
@@ -27,12 +27,12 @@ import org.w3c.dom.Element;
/**
* Compares an in-field to the specified value
*/
-public class Compare extends BaseCompare {
+public final class Compare extends BaseCompare {
private String value;
- public Compare(Element element, SimpleMapProcess simpleMapProcess) {
- super(element, simpleMapProcess);
+ Compare(Element element, String fieldName) {
+ super(element, fieldName);
this.value = element.getAttribute("value");
}
diff --git
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/CompareField.java
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/CompareField.java
index 58a952cd66..e3c1bd855d 100644
---
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/CompareField.java
+++
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/CompareField.java
@@ -27,12 +27,12 @@ import org.w3c.dom.Element;
/**
* Compares the current field to another field
*/
-public class CompareField extends BaseCompare {
+public final class CompareField extends BaseCompare {
private String compareName;
- public CompareField(Element element, SimpleMapProcess simpleMapProcess) {
- super(element, simpleMapProcess);
+ CompareField(Element element, String fieldName) {
+ super(element, fieldName);
this.compareName = element.getAttribute("field");
}
diff --git
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Convert.java
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Convert.java
index 8eeadb8dff..845b4b4ad0 100644
---
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Convert.java
+++
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Convert.java
@@ -31,22 +31,20 @@ import org.w3c.dom.Element;
/**
* Convert the current field from the in-map and place it in the out-map
*/
-public class Convert extends SimpleMapOperation {
+public final class Convert extends SimpleMapOperation {
private static final String MODULE = Convert.class.getName();
private String format;
private boolean replace = true;
private boolean setIfNull = true;
- private String toField;
+ private final String toField;
private String type;
- public Convert(Element element, SimpleMapProcess simpleMapProcess) {
- super(element, simpleMapProcess);
- this.toField = element.getAttribute("to-field");
- if (UtilValidate.isEmpty(this.toField)) {
- this.toField = this.getFieldName();
- }
+ Convert(Element element, String fieldName) {
+ super(element, fieldName);
+ String toFieldAttr = element.getAttribute("to-field");
+ this.toField = UtilValidate.isEmpty(toFieldAttr) ? fieldName :
toFieldAttr;
type = element.getAttribute("type");
// if anything but false it will be true
replace = !"false".equals(element.getAttribute("replace"));
diff --git
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Copy.java
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Copy.java
index 3eb5c093a5..8710880f51 100644
---
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Copy.java
+++
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Copy.java
@@ -28,18 +28,16 @@ import org.w3c.dom.Element;
/**
* Copies a field in the in-map to the out-map
*/
-public class Copy extends SimpleMapOperation {
+public final class Copy extends SimpleMapOperation {
private boolean replace = true;
private boolean setIfNull = true;
- private String toField;
+ private final String toField;
- public Copy(Element element, SimpleMapProcess simpleMapProcess) {
- super(element, simpleMapProcess);
- toField = element.getAttribute("to-field");
- if (UtilValidate.isEmpty(this.toField)) {
- this.toField = this.getFieldName();
- }
+ Copy(Element element, String fieldName) {
+ super(element, fieldName);
+ String toFieldAttr = element.getAttribute("to-field");
+ this.toField = UtilValidate.isEmpty(toFieldAttr) ? fieldName :
toFieldAttr;
// if anything but false it will be true
replace = !"false".equals(element.getAttribute("replace"));
// if anything but false it will be true
diff --git
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/NotEmpty.java
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/NotEmpty.java
index 6a9d8ef726..59e40896d0 100644
---
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/NotEmpty.java
+++
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/NotEmpty.java
@@ -28,10 +28,10 @@ import org.w3c.dom.Element;
/**
* Checks to see if the current field is empty (null or zero length)
*/
-public class NotEmpty extends SimpleMapOperation {
+public final class NotEmpty extends SimpleMapOperation {
- public NotEmpty(Element element, SimpleMapProcess simpleMapProcess) {
- super(element, simpleMapProcess);
+ NotEmpty(Element element, String fieldName) {
+ super(element, fieldName);
}
@Override
diff --git
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Regexp.java
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Regexp.java
index d7db872c4e..ef14b968a9 100644
---
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Regexp.java
+++
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/Regexp.java
@@ -35,14 +35,14 @@ import org.w3c.dom.Element;
/**
* Validates the current field using a regular expression
*/
-public class Regexp extends SimpleMapOperation {
+public final class Regexp extends SimpleMapOperation {
private static final String MODULE = Regexp.class.getName();
private Pattern pattern = null;
private String expr;
- public Regexp(Element element, SimpleMapProcess simpleMapProcess) {
- super(element, simpleMapProcess);
+ Regexp(Element element, String fieldName) {
+ super(element, fieldName);
expr = element.getAttribute("expr");
try {
pattern = PatternFactory.createOrGetPerl5CompiledPattern(expr,
true);
diff --git
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/SimpleMapOperation.java
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/SimpleMapOperation.java
index c60043320c..e5b97fdb60 100644
---
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/SimpleMapOperation.java
+++
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/SimpleMapOperation.java
@@ -33,12 +33,12 @@ import org.w3c.dom.Element;
*/
public abstract class SimpleMapOperation {
- private String fieldName;
+ private final String fieldName;
private boolean isProperty = false;
private String message = null;
private String propertyResource = null;
- public SimpleMapOperation(Element element, SimpleMapProcess
simpleMapProcess) {
+ SimpleMapOperation(Element element, String fieldName) {
Element failMessage = UtilXml.firstChildElement(element,
"fail-message");
Element failProperty = UtilXml.firstChildElement(element,
"fail-property");
if (failMessage != null) {
@@ -49,7 +49,7 @@ public abstract class SimpleMapOperation {
this.message = failProperty.getAttribute("property");
this.isProperty = true;
}
- this.fieldName = simpleMapProcess.getFieldName();
+ this.fieldName = fieldName;
}
/**
diff --git
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/SimpleMapProcess.java
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/SimpleMapProcess.java
index 3f1e538c31..f6e0e50e3e 100644
---
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/SimpleMapProcess.java
+++
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/SimpleMapProcess.java
@@ -19,6 +19,7 @@
package org.apache.ofbiz.minilang.operation;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -35,12 +36,12 @@ public class SimpleMapProcess {
private static final String MODULE = SimpleMapProcess.class.getName();
- private String field = "";
- private List<SimpleMapOperation> simpleMapOperations = new ArrayList<>();
+ private final String field;
+ private final List<SimpleMapOperation> simpleMapOperations;
public SimpleMapProcess(Element simpleMapProcessElement) {
this.field = simpleMapProcessElement.getAttribute("field");
- readOperations(simpleMapProcessElement);
+ this.simpleMapOperations = readOperations(simpleMapProcessElement,
field);
}
/**
@@ -66,33 +67,37 @@ public class SimpleMapProcess {
}
/**
- * Read operations.
+ * Builds the operations of a process from its child elements.
* @param simpleMapProcessElement the simple map process element
+ * @param fieldName the name of the field the operations work on
+ * @return the operations, in document order
*/
- void readOperations(Element simpleMapProcessElement) {
+ private static List<SimpleMapOperation> readOperations(Element
simpleMapProcessElement, String fieldName) {
+ List<SimpleMapOperation> simpleMapOperations = new ArrayList<>();
List<? extends Element> operationElements =
UtilXml.childElementList(simpleMapProcessElement);
if (UtilValidate.isNotEmpty(operationElements)) {
for (Element curOperElem : operationElements) {
String nodeName = curOperElem.getNodeName();
if ("validate-method".equals(nodeName)) {
- simpleMapOperations.add(new ValidateMethod(curOperElem,
this));
+ simpleMapOperations.add(new ValidateMethod(curOperElem,
fieldName));
} else if ("compare".equals(nodeName)) {
- simpleMapOperations.add(new Compare(curOperElem, this));
+ simpleMapOperations.add(new Compare(curOperElem,
fieldName));
} else if ("compare-field".equals(nodeName)) {
- simpleMapOperations.add(new CompareField(curOperElem,
this));
+ simpleMapOperations.add(new CompareField(curOperElem,
fieldName));
} else if ("regexp".equals(nodeName)) {
- simpleMapOperations.add(new Regexp(curOperElem, this));
+ simpleMapOperations.add(new Regexp(curOperElem,
fieldName));
} else if ("not-empty".equals(nodeName)) {
- simpleMapOperations.add(new NotEmpty(curOperElem, this));
+ simpleMapOperations.add(new NotEmpty(curOperElem,
fieldName));
} else if ("copy".equals(nodeName)) {
- simpleMapOperations.add(new Copy(curOperElem, this));
+ simpleMapOperations.add(new Copy(curOperElem, fieldName));
} else if ("convert".equals(nodeName)) {
- simpleMapOperations.add(new Convert(curOperElem, this));
+ simpleMapOperations.add(new Convert(curOperElem,
fieldName));
} else {
Debug.logWarning("[SimpleMapProcessor.SimpleMapProcess.readOperations]
Operation element \"" + nodeName
+ "\" not recognized", MODULE);
}
}
}
+ return Collections.unmodifiableList(simpleMapOperations);
}
}
diff --git
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/ValidateMethod.java
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/ValidateMethod.java
index d283bc54f2..79b440844a 100644
---
a/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/ValidateMethod.java
+++
b/framework/minilang/src/main/java/org/apache/ofbiz/minilang/operation/ValidateMethod.java
@@ -32,15 +32,15 @@ import org.w3c.dom.Element;
/**
* A string operation that calls a validation method
*/
-public class ValidateMethod extends SimpleMapOperation {
+public final class ValidateMethod extends SimpleMapOperation {
private static final String MODULE = ValidateMethod.class.getName();
private String className;
private String methodName;
- public ValidateMethod(Element element, SimpleMapProcess simpleMapProcess) {
- super(element, simpleMapProcess);
+ ValidateMethod(Element element, String fieldName) {
+ super(element, fieldName);
this.methodName = element.getAttribute("method");
this.className =
MiniLangValidate.checkAttribute(element.getAttribute("class"),
"org.apache.ofbiz.base.util.UtilValidate");
}