com.primix.tapestry.binding
Class PropertyBinding

java.lang.Object
  |
  +--com.primix.tapestry.binding.AbstractBinding
        |
        +--com.primix.tapestry.binding.PropertyBinding
All Implemented Interfaces:
IBinding

public class PropertyBinding
extends AbstractBinding

Implements a dynamic binding, based on getting and fetching values using JavaBeans property access.

Version:
$Id: PropertyBinding.java,v 1.14 2001/08/23 20:19:32 hship Exp $
Author:
Howard Ship

Constructor Summary
PropertyBinding(IComponent root, java.lang.String propertyPath)
          Creates a PropertyBinding from the root object and a nested property name.
 
Method Summary
 java.lang.Object getObject()
          Gets the value of the property path, with the assistance of a PropertyHelper.
 java.lang.String getPropertyPath()
           
 IComponent getRoot()
           
 java.lang.Class getType()
          Follows the property path to determine the type.
 boolean isStatic()
          Returns false.
 void setBoolean(boolean value)
          Constructs a Boolean and invokes setObject(Object).
 void setDouble(double value)
          Constructs an Double and invokes setObject(Object).
 void setInt(int value)
          Constructs an Integer and invokes setObject(Object).
 void setObject(java.lang.Object value)
          Updates the property for the binding to the given value.
 void setString(java.lang.String value)
          Invokes setObject(Object).
 java.lang.String toString()
          Returns the a String representing the property path.
 
Methods inherited from class com.primix.tapestry.binding.AbstractBinding
getBoolean, getDouble, getInt, getObject, getString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PropertyBinding

public PropertyBinding(IComponent root,
                       java.lang.String propertyPath)
Creates a PropertyBinding from the root object and a nested property name.

There's a lot of room for optimization here because we can count on some portions of the nested property name 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 a PropertyBinding has been triggered, the toString() method may return different values for the root component and the property path than was originally set.

Another option (much more involved) is to replace the dynamic property access, which depends upon reflection (i.e., the Method class), with dynamically generated bytecodes. This has been done before, to create dynamic adapter classes.

These operate orders-of-magnitude faster, though there is the question of building the bytecodes (non trivial!) and all the other classloader and security issues.

In the meantime, no optimization is done.

Method Detail

getPropertyPath

public java.lang.String getPropertyPath()

getRoot

public IComponent getRoot()

getObject

public java.lang.Object getObject()
Gets the value of the property path, with the assistance of a PropertyHelper.
Throws:
BindingException - if an exception is thrown accessing the property.

isStatic

public boolean isStatic()
Returns false.
Overrides:
isStatic in class AbstractBinding

setBoolean

public void setBoolean(boolean value)
Description copied from interface: IBinding
Constructs a Boolean and invokes IBinding.setObject(Object).
Overrides:
setBoolean in class AbstractBinding
Following copied from class: com.primix.tapestry.binding.AbstractBinding
Throws:
ReadOnlyBindingException - always.

setInt

public void setInt(int value)
Description copied from interface: IBinding
Constructs an Integer and invokes IBinding.setObject(Object).
Overrides:
setInt in class AbstractBinding
Following copied from class: com.primix.tapestry.binding.AbstractBinding
Throws:
ReadOnlyBindingException - always.

setDouble

public void setDouble(double value)
Description copied from interface: IBinding
Constructs an Double and invokes IBinding.setObject(Object).
Overrides:
setDouble in class AbstractBinding
Following copied from class: com.primix.tapestry.binding.AbstractBinding
Throws:
ReadOnlyBindingException - always.

setString

public void setString(java.lang.String value)
Description copied from interface: IBinding
Invokes IBinding.setObject(Object).
Overrides:
setString in class AbstractBinding
Following copied from class: com.primix.tapestry.binding.AbstractBinding
Throws:
ReadOnlyBindingException - always.

setObject

public void setObject(java.lang.Object value)
Updates the property for the binding to the given value.
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).

getType

public java.lang.Class getType()
Follows the property path to determine the type.
Since:
1.0.5

toString

public java.lang.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 java.lang.Object