net.xoetrope.optional.scripts
Class ScriptAttributeEvaluator

java.lang.Object
  extended by net.xoetrope.optional.scripts.ScriptAttributeEvaluator
All Implemented Interfaces:
XAttributeEvaluator

public class ScriptAttributeEvaluator
extends java.lang.Object
implements XAttributeEvaluator

Evaluates a script attribute by passing the scripts following the prefix 'script:' to the ScriptEngine. The scripts can be an a function that was predifined in the page Scripts tag or a script that is just being defined. eg. script:myFunction(); given that myFunction was define in the page Scripts tag. eg. script:out.println('Hello World'); the script is just being defined.

Copyright (c) Xoetrope Ltd., 2002-2007

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 instance
           
protected  java.lang.Object result
           
protected  ScriptEngine scriptEngine
           
 
Constructor Summary
ScriptAttributeEvaluator()
          Create a new instance of the 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 value of an attribute by evaluating a method reference
 java.lang.Object getObject()
          Get the current page.
 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


instance

protected java.lang.Object instance

exceptionHandler

protected XExceptionHandler exceptionHandler

result

protected java.lang.Object result

currentProject

protected XProject currentProject

scriptEngine

protected ScriptEngine scriptEngine
Constructor Detail

ScriptAttributeEvaluator

public ScriptAttributeEvaluator()
Create a new instance of the evaluator

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

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:
page - the page being loaded
attributeValue - the raw value of the attribute
Returns:
the evaluated value of the attribute

getMethodReference

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

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:
instance - the current page or object that provides the methods or fields used in the evaluation
attributeValue - the method name
Returns:
the method reference or null if the referenced/named method cannot be found

getObject

public java.lang.Object getObject()
Get the current page. 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 page object

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