org.formaria.aria.evaluator
Class DefaultAttributeEvaluator

java.lang.Object
  extended by org.formaria.aria.evaluator.DefaultAttributeEvaluator
All Implemented Interfaces:
AttributeEvaluator
Direct Known Subclasses:
GenericBuilderAttributeEvaluator

public class DefaultAttributeEvaluator
extends java.lang.Object
implements AttributeEvaluator

An attribute evaluator

An evaluated attribute's implementing method is by default in the owner page such that a reference like

${myMethod()}

would evaluate to a method in the current page with a signature like:

public void myMethod();

The attributes can also be defined in classes other than the current page or classes derived from Page. The syntax for such expressions is as follows:

where mypackage is the name of the Java package containing the class MyClass. The value of referenceName is a user defined value that identifies the instance of the class. The application instantiates an instance of the class when the expression is first encountered and thereafter maintains the instance with each subsequent call retrieving the same instance of the class.

The method call can contain zero or more arguments

Copyright (c) Formaria Ltd., 2008

$Revision: 2.8 $

License: see License.txt


Field Summary
protected  java.util.Hashtable classInstances
          The collection of class instances that are known to implement the methods of evaluated attributes
protected  Project currentProject
           
protected  ExceptionHandler exceptionHandler
           
protected  java.lang.Object provider
           
protected  java.lang.Object result
           
 
Constructor Summary
DefaultAttributeEvaluator(Project project)
          Create a new evaluator
 
Method Summary
 java.lang.Object evaluateAttribute(java.lang.Object instance, java.lang.String attributeValue)
          Get the value of an attribute.
 MethodReference getMethodReference(java.lang.Object instance, java.lang.String attributeValue)
          Get the value of an attribute by evaluating a method reference
 MethodReference getMethodReference(java.lang.String attributeValue)
          Get the method reference for the methods named in the attribute
 java.lang.Object getObject()
          Get the current provider object.
 java.lang.Object getResult()
          Explicitly get the result of an evaluation.
protected  java.lang.Object lookupReference(java.lang.String reference)
          Lookup a reference
 void setCurrentProject(Project project)
          Set the current project and complete any initialization that depends on the project reference/instance.
 void setExceptionHandler(ExceptionHandler eh)
          Set an exception handler for processing exceptions
 void setResult(java.lang.Object value)
          Explicitly set the result of an evaluation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classInstances

protected java.util.Hashtable classInstances
The collection of class instances that are known to implement the methods of evaluated attributes


provider

protected java.lang.Object provider

currentProject

protected Project currentProject

exceptionHandler

protected ExceptionHandler exceptionHandler

result

protected java.lang.Object result
Constructor Detail

DefaultAttributeEvaluator

public DefaultAttributeEvaluator(Project project)
Create a new evaluator

Parameters:
currentProject - the current project
project - the current or owning project
Method Detail

setCurrentProject

public void setCurrentProject(Project project)
Set the current project and complete any initialization that depends on the project reference/instance.

Specified by:
setCurrentProject in interface AttributeEvaluator
Parameters:
project - the current or owning project

setExceptionHandler

public void setExceptionHandler(ExceptionHandler eh)
Set an exception handler for processing exceptions

Specified by:
setExceptionHandler in interface AttributeEvaluator
Parameters:
eh - the exception handler

setResult

public void setResult(java.lang.Object value)
Explicitly set the result of an evaluation. This method may be used by an exception handler to override the result and set a sensible value in case of an exception

Specified by:
setResult in interface AttributeEvaluator
Parameters:
the - new result value

getResult

public java.lang.Object getResult()
Explicitly get the result of an evaluation. This method may be used by an exception handler to determine the result and set a sensible value in case of an exception

Specified by:
getResult in interface AttributeEvaluator
Returns:
the current/intermediate result value

evaluateAttribute

public java.lang.Object evaluateAttribute(java.lang.Object instance,
                                          java.lang.String attributeValue)
Get the value of an attribute.

Specified by:
evaluateAttribute in interface AttributeEvaluator
Parameters:
instance - the page or instance that provides the methods/field for the evaluator
attributeValue - the raw value of the attribute
Returns:
the evaluated value of the attribute

getMethodReference

public MethodReference getMethodReference(java.lang.String attributeValue)
Get the method reference for the methods named in the attribute

Specified by:
getMethodReference in interface AttributeEvaluator
Parameters:
attributeValue - the method name
Returns:
the method reference or null if the referenced/named method cannot be found

getMethodReference

public MethodReference getMethodReference(java.lang.Object instance,
                                          java.lang.String attributeValue)
Get the value of an attribute by evaluating a method reference

Specified by:
getMethodReference in interface AttributeEvaluator
Parameters:
instnace - the page or object from that provides the methods or fields referenced in the evaluation
attributeValue - the attribute to be evaluated
Returns:
the method reference or null if the referenced/named method cannot be found

lookupReference

protected java.lang.Object lookupReference(java.lang.String reference)
Lookup a reference

Parameters:
reference - a stripped reference e.g. values - which would have been specified as ${values}
Returns:
the reference object(s) or null

getObject

public java.lang.Object getObject()
Get the current provider object. In most cases this should correspond to the active page at the time the evaluator was last used, but no guarantees can be provided that multiple threads are not updating the value. The value should be retrieved and cached as soon as the evaluated method is entered as other method calls could have the side effect of reseting the value.

Returns:
the current object used for evaluation of method and field references