com.jaxfront.core.rule
Class FormulaExpression

java.lang.Object
  extended by com.jaxfront.core.rule.FormulaExpression
All Implemented Interfaces:
DOMChangeListener, java.io.Serializable, java.util.EventListener

public class FormulaExpression
extends java.lang.Object
implements DOMChangeListener, java.io.Serializable

The FormulaExpression encapsulates a JAXFront formula defined in the xui definition. A FormulaExpression consists of a expression defined in the xui, an sourceType the formula will run against of and some variables defined in xui too. For performance reasons a formula can be marked as preprocessable, this means if a formula has a static content it's not necesarry to calculate it again and again. In this case simly the result is returned without any processing effort. With the update method it's possible to tell the formula to set the internal state from preprossed to not preprossed!

Version:
1.60
See Also:
MathEvaluator, Variable, Serialized Form

Field Summary
static java.lang.String TRUE
           
 
Constructor Summary
FormulaExpression(Type source, java.lang.String expression)
          FormulaExpression constructor.
FormulaExpression(Type source, java.lang.String expression, boolean includeOnlySerializable)
          FormulaExpression constructor.
FormulaExpression(Type source, java.lang.String expression, boolean includeOnlySerializable, boolean registerFormula)
          FormulaExpression constructor.
FormulaExpression(Type source, java.lang.String expression, TableCell cell)
          FormulaExpression constructor.
 
Method Summary
 void checkSyntax()
           
 boolean doesConcern(Type sourceType)
          Returns true if any change in the submitted sourceType concerns a defined variable result.
 boolean doesIncludeOnlySerializableNodes()
           
 void domChanged(DOMChangeEvent event)
          Respond method for a DOM state changed (DOMChangeEvent).
 boolean equals(java.lang.Object obj)
           
 java.lang.String evaluate()
          Evaluate the formula by doing a XPath eval() operation.
 java.lang.String evaluate(Type target, java.lang.Object eventSource, java.lang.Object event)
          Evaluate the formula by doing a XPath eval() operation.
 java.lang.Object evaluateObject()
           
 java.lang.Object evaluateObject(Type target)
           
 java.lang.Object getCachedResult()
           
 java.lang.String getErrorInfo()
          Sets the ability to be preprocessable
 java.lang.String getExpression()
          Returns the expression string.
 java.util.Vector getReferencedExpressionNodes()
           
 java.lang.Class getResultClassForSort()
           
 Type getSource()
          Returns the holder of this expression.
 TableCell getTableCell()
           
 int hashCode()
           
 boolean isReleased()
           
 boolean isTrue(Type sourceType)
          Evaluate the formula based on a source type, expecting a boolean as return value e.g. count( .
 boolean isTrue(Type source, java.lang.Object event, boolean useEventSourceAsBase)
          Evaluate the formula, expecting a boolean as return value e.g. count( .
static FormulaExpression lookup(Type source, java.lang.String expression)
           
static FormulaExpression lookup(Type source, java.lang.String expression, boolean includeOnlySerializable)
           
 void release()
          Releases all allocated resources for this formulaExpression.
 void setCachedResult(java.lang.Object cachedResult)
           
 void setDoesIncludeOnlySerializableNodes(boolean doesInclude)
           
 void setExpression(java.lang.String expression)
          Sets an expression string
 void setSource(Type newSource)
          Sets the holder of this expression.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRUE

public static final java.lang.String TRUE
See Also:
Constant Field Values
Constructor Detail

FormulaExpression

public FormulaExpression(Type source,
                         java.lang.String expression)
FormulaExpression constructor.

Parameters:
source - The source Type to apply expression on
expression - the formula expression

FormulaExpression

public FormulaExpression(Type source,
                         java.lang.String expression,
                         TableCell cell)
FormulaExpression constructor.

Parameters:
source - The source Type to apply expression on
expression - the formula expression

FormulaExpression

public FormulaExpression(Type source,
                         java.lang.String expression,
                         boolean includeOnlySerializable)
FormulaExpression constructor.

Parameters:
source - The source Type to apply expression on
expression - the formula expression
includeNoneSerializable - indicates if none serializable nodes are includes in the nodes functions

FormulaExpression

public FormulaExpression(Type source,
                         java.lang.String expression,
                         boolean includeOnlySerializable,
                         boolean registerFormula)
FormulaExpression constructor.

Parameters:
source - The source Type to apply expression on
expression - the formula expression
includeNoneSerializable - indicates if none serializable nodes are includes in the nodes functions
Method Detail

evaluate

public java.lang.String evaluate()
                          throws FormulaException
Evaluate the formula by doing a XPath eval() operation. If the expression contains more than one variable, after all the separate variables have been evaluated, the whole expression will be sent through XPath eval() once more, e.g. expression="concat($A,$B)" and $A="./@value" and $B="./@value2", then the resulting String will be a concatenation of both.

Throws:
FormulaException

evaluate

public java.lang.String evaluate(Type target,
                                 java.lang.Object eventSource,
                                 java.lang.Object event)
                          throws FormulaException
Evaluate the formula by doing a XPath eval() operation. If the expression contains more than one variable, after all the separate variables have been evaluated, the whole expression will be sent through XPath eval() once more, e.g. expression="concat($A,$B)" and $A="./@value" and $B="./@value2", then the resulting String will be a concatenation of both.

Parameters:
eventSource - TODO
event - TODO
Throws:
FormulaException

evaluateObject

public java.lang.Object evaluateObject()
                                throws FormulaException
Throws:
FormulaException

evaluateObject

public java.lang.Object evaluateObject(Type target)
                                throws FormulaException
Throws:
FormulaException

getSource

public Type getSource()
Returns the holder of this expression. Usually the definition is the holder. This may be changed in the XUI definition.


setSource

public void setSource(Type newSource)
Sets the holder of this expression. Usually the definition is the holder. This may be changed in the XUI definition.


isTrue

public boolean isTrue(Type source,
                      java.lang.Object event,
                      boolean useEventSourceAsBase)
               throws FormulaException
Evaluate the formula, expecting a boolean as return value e.g. count( ./Timestamp ) > 0

Parameters:
event - TODO
Returns:
whether the formula is true or false
Throws:
thrown - if the expression could not be parsed
FormulaException

isTrue

public boolean isTrue(Type sourceType)
               throws FormulaException
Evaluate the formula based on a source type, expecting a boolean as return value e.g. count( ./Timestamp ) > 0

Parameters:
sourceType - source type to evaluate expression on
Returns:
whether the formula is true or false
Throws:
thrown - if the expression could not be parsed
FormulaException

getErrorInfo

public java.lang.String getErrorInfo()
Sets the ability to be preprocessable

Parameters:
isPreProcessable - indicates if this expression is preprocessable

doesConcern

public boolean doesConcern(Type sourceType)
Returns true if any change in the submitted sourceType concerns a defined variable result.

Parameters:
sourceType - type which may concern this condition

checkSyntax

public void checkSyntax()
                 throws org.nfunk.jep.ParseException
Throws:
org.nfunk.jep.ParseException

getReferencedExpressionNodes

public java.util.Vector getReferencedExpressionNodes()

release

public void release()
Releases all allocated resources for this formulaExpression.


isReleased

public boolean isReleased()

setExpression

public void setExpression(java.lang.String expression)
Sets an expression string

Parameters:
expression -

getExpression

public java.lang.String getExpression()
Returns the expression string.


setCachedResult

public void setCachedResult(java.lang.Object cachedResult)
Parameters:
_cachedResult - The _cachedResult to set.

getCachedResult

public java.lang.Object getCachedResult()
Returns:
Returns the _cachedResult.
Throws:
FormulaException

getResultClassForSort

public java.lang.Class getResultClassForSort()

domChanged

public void domChanged(DOMChangeEvent event)
Description copied from interface: DOMChangeListener
Respond method for a DOM state changed (DOMChangeEvent).

Specified by:
domChanged in interface DOMChangeListener
Parameters:
event - occured DOMChangeEvent

doesIncludeOnlySerializableNodes

public boolean doesIncludeOnlySerializableNodes()

setDoesIncludeOnlySerializableNodes

public void setDoesIncludeOnlySerializableNodes(boolean doesInclude)

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

lookup

public static FormulaExpression lookup(Type source,
                                       java.lang.String expression)

lookup

public static FormulaExpression lookup(Type source,
                                       java.lang.String expression,
                                       boolean includeOnlySerializable)

getTableCell

public TableCell getTableCell()