org.apache.tapestry.binding
Class ExpressionBinding

java.lang.Object
  extended by org.apache.tapestry.binding.AbstractBinding
      extended by org.apache.tapestry.binding.ExpressionBinding
All Implemented Interfaces:
IBinding, ILocatable

public class ExpressionBinding
extends AbstractBinding

Implements a dynamic binding, based on getting and fetching values using JavaBeans property access. This is built upon the OGNL library.

Optimization of the Expression

There's a lot of room for optimization here because we can count on some portions of the expression to be effectively static. Note that we type the root object as IComponent. We have some expectations that certain properties of the root (and properties reachable from the root) will be constant for the lifetime of the binding. For example, components never change thier page or container. This means that certain property prefixes can be optimized:

This means that once an ExpressionBinding has been triggered, the toString() method may return different values for the root component and the expression than was originally set.

Identifying Invariants

Most expressions are fully dynamic; they must be resolved each time they are accessed. This can be somewhat inefficient. Tapestry can identify certain paths as invariant:

These optimizations have some inherent dangers; they assume that the components have not overidden the specified properties; the last one (concerning helper beans) assumes that the component does inherit from AbstractComponent. If this becomes a problem in the future, it may be necessary to have the component itself involved in these determinations.

Since:
2.2
Version:
$Id: ExpressionBinding.java 243862 2004-03-30 22:40:25Z hlship $
Author:
Howard Lewis Ship

Constructor Summary
ExpressionBinding(IResourceResolver resolver, IComponent root, String expression, ILocation location)
          Creates a ExpressionBinding from the root object and an OGNL expression.
 
Method Summary
 String getExpression()
           
 Object getObject()
          Gets the value of the property path, with the assistance of a OGNL.
 IComponent getRoot()
           
 boolean isInvariant()
          Returns true if the binding is expected to always return the same value.
 void setBoolean(boolean value)
          Constructs a Boolean and invokes IBinding.setObject(Object).
 void setDouble(double value)
          Constructs an Double and invokes IBinding.setObject(Object).
 void setInt(int value)
          Constructs an Integer and invokes IBinding.setObject(Object).
 void setObject(Object value)
          Updates the property for the binding to the given value.
 void setString(String value)
          Invokes IBinding.setObject(Object).
 String toString()
          Returns the a String representing the property path.
 
Methods inherited from class org.apache.tapestry.binding.AbstractBinding
createReadOnlyBindingException, getBoolean, getDouble, getInt, getLocation, getObject, getString, isWrapper
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExpressionBinding

public ExpressionBinding(IResourceResolver resolver,
                         IComponent root,
                         String expression,
                         ILocation location)
Creates a ExpressionBinding from the root object and an OGNL expression.

Method Detail

getExpression

public String getExpression()

getRoot

public IComponent getRoot()

getObject

public Object getObject()
Gets the value of the property path, with the assistance of a OGNL.

Throws:
BindingException - if an exception is thrown accessing the property.

isInvariant

public boolean isInvariant()
Returns true if the binding is expected to always return the same value.

Specified by:
isInvariant in interface IBinding
Overrides:
isInvariant in class AbstractBinding

setBoolean

public void setBoolean(boolean value)
Description copied from interface: IBinding
Constructs a Boolean and invokes IBinding.setObject(Object).

Specified by:
setBoolean in interface IBinding
Overrides:
setBoolean in class AbstractBinding

setInt

public void setInt(int value)
Description copied from interface: IBinding
Constructs an Integer and invokes IBinding.setObject(Object).

Specified by:
setInt in interface IBinding
Overrides:
setInt in class AbstractBinding

setDouble

public void setDouble(double value)
Description copied from interface: IBinding
Constructs an Double and invokes IBinding.setObject(Object).

Specified by:
setDouble in interface IBinding
Overrides:
setDouble in class AbstractBinding

setString

public void setString(String value)
Description copied from interface: IBinding
Invokes IBinding.setObject(Object).

Specified by:
setString in interface IBinding
Overrides:
setString in class AbstractBinding

setObject

public void setObject(Object value)
Updates the property for the binding to the given value.

Specified by:
setObject in interface IBinding
Overrides:
setObject in class AbstractBinding
Throws:
BindingException - if the property can't be updated (typically due to an security problem, or a missing mutator method).
BindingException - if the binding is invariant.

toString

public String toString()
Returns the a String representing the property path. This includes the extended id of the root component and the property path ... once the binding is used, these may change due to optimization of the property path.

Overrides:
toString in class Object