com.iplanet.jato.model
Class BeanAdapterModel

java.lang.Object
  |
  +--com.iplanet.jato.model.BeanAdapterModel
All Implemented Interfaces:
DatasetModel, Model, java.io.Serializable

public class BeanAdapterModel
extends java.lang.Object
implements Model, DatasetModel, java.io.Serializable

A simple model that obtains its values from one or more JavaBeans, using reflection to read and write bean properties. This class can be used to directly bind local business objects or EJBs to a view.

Version:
JATO/1.2.2 $Id: BeanAdapterModel.java,v 1.9 2002/03/16 03:26:30 todd Exp $
See Also:
Serialized Form

Field Summary
static int UNDEFINED_ROW_INDEX
           
 
Constructor Summary
BeanAdapterModel()
          Default constructor
BeanAdapterModel(java.lang.Object bean)
          Construct an instance using the target bean as the backing data store
BeanAdapterModel(java.lang.Object[] beans)
          Construct an instance using the set of target beans as the backing data store.
 
Method Summary
 void beforeFirst()
          Moves the internal location iterator to a special position such that a call to next() will position the location at the first dataset (if available).
protected  boolean checkIndex()
           
 boolean first()
          Moves the internal location iterator to the first available dataset.
 java.lang.Object getBean()
          Returns the backing bean object
 java.lang.Object[] getBeans()
          Returns the set of backing bean objects
 java.lang.Object getCurrentBean()
          Returns the bean at the current dataset location
protected  int getIndex()
           
 int getLocation()
          Get the relative location of the current data within the dataset.
 int getLocationOffset()
          Returns the offset of this dataset from some implementation- or context-dependent reference location.
 java.lang.String getName()
          Returns the logical instance name of this model.
protected  java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.Object bean, java.lang.String property)
           
 int getSize()
          Return the number of available datasets.
 java.lang.Object getValue(java.lang.String name)
          Returns a named value from this model
 java.lang.Object[] getValues(java.lang.String name)
          Returns a named set of values from this model
 boolean last()
          Moves the internal location iterator to the last available dataset.
 boolean next()
          Moves the internal location iterator to the next available dataset
 boolean previous()
          Moves the internal location iterator to the previous available dataset
 void setBean(java.lang.Object value)
          Sets the backing bean object and resets the dataset location to the "before first" state.
 void setBeans(java.lang.Object[] value)
          Sets the backing bean objects and resets the dataset location to the "before first" state.
protected  void setIndex(int value)
           
 void setLocation(int location)
          Set the relative location of the current dataset.
 void setName(java.lang.String value)
          Sets the logical name of this model
 void setSize(int value)
          Sets the number of available datasets.
 void setValue(java.lang.String name, java.lang.Object value)
          Sets a named value in this model.
 void setValues(java.lang.String name, java.lang.Object[] value)
          Sets a named set of values in this model
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNDEFINED_ROW_INDEX

public static final int UNDEFINED_ROW_INDEX
Constructor Detail

BeanAdapterModel

public BeanAdapterModel()
Default constructor

BeanAdapterModel

public BeanAdapterModel(java.lang.Object bean)
Construct an instance using the target bean as the backing data store

BeanAdapterModel

public BeanAdapterModel(java.lang.Object[] beans)
Construct an instance using the set of target beans as the backing data store. This resulting instance will have as many items in the dataset as the size of the provided bean array.
Method Detail

getName

public java.lang.String getName()
Description copied from interface: Model
Returns the logical instance name of this model. This name can be any arbitrary string. This name may only be useful at certain times; for example, the ModelManager may assign a name to a model based on user request.
Specified by:
getName in interface Model
Following copied from interface: com.iplanet.jato.model.Model
Returns:
The opaque, arbitrary name of this model

setName

public void setName(java.lang.String value)
Description copied from interface: Model
Sets the logical name of this model
Specified by:
setName in interface Model
Following copied from interface: com.iplanet.jato.model.Model
Parameters:
name - The new name of this model

getBean

public java.lang.Object getBean()
Returns the backing bean object
Returns:
The single bean instance if only one bean was set, or the first element of the bean set if more than one bean was used to create this instance

getBeans

public java.lang.Object[] getBeans()
Returns the set of backing bean objects
Returns:
The set of beans wrapped by this model

setBean

public void setBean(java.lang.Object value)
Sets the backing bean object and resets the dataset location to the "before first" state.
Parameters:
value - The new bean to wrap in this model

setBeans

public void setBeans(java.lang.Object[] value)
Sets the backing bean objects and resets the dataset location to the "before first" state.
Parameters:
value - The new set of beans to wrap in this model

getPropertyDescriptor

protected java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.Object bean,
                                                              java.lang.String property)
                                                       throws java.beans.IntrospectionException

getValue

public java.lang.Object getValue(java.lang.String name)
Description copied from interface: Model
Returns a named value from this model
Specified by:
getValue in interface Model
Following copied from interface: com.iplanet.jato.model.Model
Parameters:
name - The name of the value to return
Returns:
The specified value. If the model has multiple values for the specified name, the first value is returned. If there is no value for the specified name, this method returns null.

setValue

public void setValue(java.lang.String name,
                     java.lang.Object value)
Description copied from interface: Model
Sets a named value in this model. This method overwrites any current value or values. If multiple values were present previously, they are all discarded.
Specified by:
setValue in interface Model
Following copied from interface: com.iplanet.jato.model.Model
Parameters:
name - The name of the value to set
value - The value to set in this model

getValues

public java.lang.Object[] getValues(java.lang.String name)
Description copied from interface: Model
Returns a named set of values from this model
Specified by:
getValues in interface Model
Following copied from interface: com.iplanet.jato.model.Model
Parameters:
name - The name of the value set to return
Returns:
The specified set of values. If there is no value for the specified name, this method returns an array of zero length.

setValues

public void setValues(java.lang.String name,
                      java.lang.Object[] value)
Description copied from interface: Model
Sets a named set of values in this model
Specified by:
setValues in interface Model
Following copied from interface: com.iplanet.jato.model.Model
Parameters:
name - The name of the value set to set in the model
values - The set of values to set in this model

getSize

public int getSize()
            throws ModelControlException
Description copied from interface: DatasetModel
Return the number of available datasets. This value may be fixed or change over time depending on the implementation. In most cases, this value will remain fixed for each data retrieval operation ("execution").
Specified by:
getSize in interface DatasetModel
Following copied from interface: com.iplanet.jato.model.DatasetModel
Returns:
The number of available datasets
Throws:
ModelControlException - Thrown if an error occurrs determining the number of datasets

setSize

public void setSize(int value)
             throws ModelControlException
Description copied from interface: DatasetModel
Sets the number of available datasets. Setting the number of datasets may not be supported by all model control implementations.
Specified by:
setSize in interface DatasetModel
Following copied from interface: com.iplanet.jato.model.DatasetModel
Throws:
ModelControlException - Thrown if an error occurrs setting the number of datasets. Not all model control implementations will allow the number of datasets to be directly changed.

getLocationOffset

public int getLocationOffset()
Description copied from interface: DatasetModel
Returns the offset of this dataset from some implementation- or context-dependent reference location. In most cases, this value will indicate the absolute offset from this reference. Such information may be useful in some classes of manipulation of dataset models. For example, this value could indicate the offset of the current "window" within a query result set, so that that absolute location could be located again later. Note that this control object is under no obligation or burden to allow setting the location to obtain datasets outside of the current window defined by the boundaries of the first() and last() locations--this information is informational only.
Specified by:
getLocationOffset in interface DatasetModel
Following copied from interface: com.iplanet.jato.model.DatasetModel
Throws:
ModelControlException - Thrown if an error occurrs determining the location offset, or if the notion of location offset is not supported. However, if the latter is the case, implementors are encouraged instead to return a value indicating the situation, such as zero or negative one (0 or -1).

getLocation

public int getLocation()
                throws ModelControlException
Description copied from interface: DatasetModel
Get the relative location of the current data within the dataset. This method should normally return zero after the first() method is called. In addition, this method will typically return negative one (-1) after the beforeFirst() method is called.
Specified by:
getLocation in interface DatasetModel
Following copied from interface: com.iplanet.jato.model.DatasetModel
Throws:
ModelControlException - Thrown if an error occurrs determining the current location, or if the current location is undefined. However, if the latter is the case, implementors are encouraged instead to return a value indicating this situation, like negative one (-1).

setLocation

public void setLocation(int location)
                 throws ModelControlException
Description copied from interface: DatasetModel
Set the relative location of the current dataset. A call to this method with a parameter of zero (0) should be equivalent to calling the first() method. Normally, a call to this method with a parameter of negative one (-1) should be equivalent to calling the beforeFirst() method. However, neither of these situations are guaranteed depending on the implementation.
Specified by:
setLocation in interface DatasetModel
Following copied from interface: com.iplanet.jato.model.DatasetModel
Throws:
ModelControlException - Thrown if an error occurrs setting the current location. Not all model control implementations support setting the current location.

getIndex

protected int getIndex()

setIndex

protected void setIndex(int value)

checkIndex

protected boolean checkIndex()

getCurrentBean

public java.lang.Object getCurrentBean()
Returns the bean at the current dataset location
Returns:
The bean in use

beforeFirst

public void beforeFirst()
                 throws ModelControlException
Description copied from interface: DatasetModel
Moves the internal location iterator to a special position such that a call to next() will position the location at the first dataset (if available). Normally, a call to getLocation() after this method is called should return negative one (-1).
Specified by:
beforeFirst in interface DatasetModel
Following copied from interface: com.iplanet.jato.model.DatasetModel
Throws:
ModelControlException - Thrown if an error occurrs setting the location to this special position

first

public boolean first()
              throws ModelControlException
Description copied from interface: DatasetModel
Moves the internal location iterator to the first available dataset. Normally, a call to getLocation() after this method is called should return zero (0). The offset of this dataset from some implementation- or context-dependent reference location is given by getLocationOffset(). However, this control object is under no obligation or burden to allow setting the location to obtain datasets outside of the "window" defined by the boundaries of the first() and last() locations.
Specified by:
first in interface DatasetModel
Following copied from interface: com.iplanet.jato.model.DatasetModel
Returns:
True if now positioned at a valid dataset, false if there is no available dataset
Throws:
ModelControlException - Thrown if an error occurrs moving to the first dataset

last

public boolean last()
             throws ModelControlException
Description copied from interface: DatasetModel
Moves the internal location iterator to the last available dataset. Normally, a call to getLocation() after this method is called should return getSize()-1.
Specified by:
last in interface DatasetModel
Following copied from interface: com.iplanet.jato.model.DatasetModel
Returns:
True if now positioned at a valid dataset, false if there is no available dataset
Throws:
ModelControlException - Thrown if an error occurrs moving to the last dataset

next

public boolean next()
             throws ModelControlException
Description copied from interface: DatasetModel
Moves the internal location iterator to the next available dataset
Specified by:
next in interface DatasetModel
Following copied from interface: com.iplanet.jato.model.DatasetModel
Returns:
True if now positioned at a valid dataset, false if there are no more datasets
Throws:
ModelControlException - Thrown if an error occurrs positioning at the next dataset

previous

public boolean previous()
                 throws ModelControlException
Description copied from interface: DatasetModel
Moves the internal location iterator to the previous available dataset
Specified by:
previous in interface DatasetModel
Following copied from interface: com.iplanet.jato.model.DatasetModel
Returns:
True if now positioned at a valid dataset, false if there are no more datasets
Throws:
ModelControlException - Thrown if an error occurrs positioning at the previous dataset