net.xoetrope.xui.evaluator
Class XDefaultAttributeEvaluator

java.lang.Object
  extended by net.xoetrope.xui.evaluator.XDefaultAttributeEvaluator
All Implemented Interfaces:
XAttributeEvaluator

public class XDefaultAttributeEvaluator
extends java.lang.Object
implements XAttributeEvaluator

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 XPage. 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) Xoetrope Ltd., 2002-2004

$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  XProject currentProject
           
protected  XExceptionHandler exceptionHandler
           
protected  java.lang.Object provider
           
protected  java.lang.Object result
           
 
Constructor Summary
XDefaultAttributeEvaluator(XProject 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.
 XMethodReference getMethodReference(java.lang.Object instance, java.lang.String attributeValue)
          Get the value of an attribute by evaluating a method reference
 XMethodReference 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.
 void setCurrentProject(XProject project)
          Set the current project and complete any initialization that depends on the project reference/instance.
 void setExceptionHandler(XExceptionHandler 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 XProject currentProject

exceptionHandler

protected XExceptionHandler exceptionHandler

result

protected java.lang.Object result
Constructor Detail

XDefaultAttributeEvaluator

public XDefaultAttributeEvaluator(XProject project)
Create a new evaluator

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

setCurrentProject

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

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

setExceptionHandler

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

Specified by:
setExceptionHandler in interface XAttributeEvaluator
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 XAttributeEvaluator
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 XAttributeEvaluator
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 XAttributeEvaluator
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 XMethodReference getMethodReference(java.lang.String attributeValue)
Get the method reference for the methods named in the attribute

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

getMethodReference

public XMethodReference 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 XAttributeEvaluator
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

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