Sie zeigen eine alte Version dieser Seite an. Zeigen Sie die aktuelle Version an.

Unterschiede anzeigen Seitenhistorie anzeigen

Version 1 Nächste Version anzeigen »


A function can be used everywhere within the rule engine (condition expression, nls text). A predefined set of functions already exists.
To register the own function, open the "Preferences" dialog in the XUI Editor ("View" menu) and add a new function. After adding/modifying the functions, the XUI Edtior needs to be closed and started again.

Implementing an own function means to extend the "com.jaxfront.core.jep.JaxfrontMathCommand" class . In the field "Implementation Class" enter the class name which extends this class. In the field "Category" add an existing category name or a new one. You will see all categories when using the formula engine.


The class needs to extend the "com.jaxfront.core.jep.JaxfrontMathCommand" class:

Name

Description

run(Stack)

Each function should use it's own run() method for evaluating the function. This includes popping off the parameters from the stack, and pushing the result back on the stack.


See class com.jaxfront.demo.api.OwnFunction
This function checks if the passed node values is a future date.
public class OwnFunction extends SuperTypeNode {
public void run(Stack stack) throws ParseException {
// Check if stack is null
checkStack(stack);
Object param = null;
String xPath = null;
boolean isFutureDate = false;
if (curNumberOfParameters == 1) {
Type baseType = getCommunicator().getRootType();
param = stack.pop();
if (param == NULL._null) {
stack.push(NULL._null);
return;
} else if (param instanceof Type) {
baseType = (Type) param;
} else if (param instanceof String) {
xPath = (String) param;
}
Type resultType = null;
if (xPath != null && xPath.length() > 0) {
resultType =
TypePathExecuter.getInstance().getTypeForXPath(
baseType,
xPath.trim(),
true,
true);
} else
resultType = baseType;
if (resultType != null) {
if (resultType.isSimple()) {
SimpleType simpleType = (SimpleType)resultType;
String dateString = simpleType.getValue();
if (dateString != null) {
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date inputDate = format.parse(dateString);
Date currentDate = new Date();
isFutureDate = inputDate.compareTo(currentDate) > 0;
}
catch (java.text.ParseException ex) {
//do nothing
}
}
} else {
throw new ParseException(this.getClass() + " Invalid target type (must be simple)");
}
}
if (isFutureDate) {
stack.push(SuperTypeNode.isTrue);
}
else {
stack.push(SuperTypeNode.isFalse);
}
} else {
throw new ParseException(this.getClass() + " Invalid parameter type");
}
}
}

  • Keine Stichwörter