com.sun.data.provider.impl
Class ObjectListDataProvider

java.lang.Object
  extended bycom.sun.data.provider.impl.AbstractDataProvider
      extended bycom.sun.data.provider.impl.AbstractTableDataProvider
          extended bycom.sun.data.provider.impl.ObjectListDataProvider
All Implemented Interfaces:
DataProvider, java.io.Serializable, TableDataProvider, TransactionalDataProvider

public class ObjectListDataProvider
extends AbstractTableDataProvider
implements java.io.Serializable, TransactionalDataProvider

This TableDataProvider wraps access to a list of Java Objects. The FieldKeys correspond to the JavaBean properties and optionally the public member fields of the Java Object.

This class implements TransactionalDataProvider semantics, meaning that all updates to existing fields, as well as inserted and deleted rows, are cached until commitChanges() is called. Once that call is made, any RowKey you have retrieved from this instance is invalid, and must be reacquired.

WARNING - Until you call setList() or setObjectType() with a non-null parameter, or use a constructor variant that accepts an non-null non-empty list, no information about field keys will be available. Therefore, any attempt to reference a FieldKey or field identifier in a method call will throw IllegalArgumentException.

NOTE about Serializable: This class wraps access to a list of any Java Objects. The Objects can be swapped out using the setObject(Object) method. For this class to remain Serializable, the contained Objects must also be Serializable.

Author:
Joe Nuxoll Winston Prakash (bug fixes)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.sun.data.provider.impl.AbstractTableDataProvider
cursorRow, rowKeyList, rowKeyMap, tcListeners
 
Fields inherited from class com.sun.data.provider.impl.AbstractDataProvider
dpListeners, fieldKeys
 
Constructor Summary
ObjectListDataProvider()
          Construct a new ObjectListDataProvider with no known object type.
ObjectListDataProvider(java.lang.Class objectType)
          Constructs a new ObjectListDataProvider for the specified object type.
ObjectListDataProvider(java.lang.Class objectType, boolean includeFields)
          Constructs a new ObjectListDataProvider for the specified object type and includeFields property value.
ObjectListDataProvider(java.util.List list)
          Constructs a new ObjectListDataProvider wrapping the specified list.
ObjectListDataProvider(java.util.List list, boolean includeFields)
          Constructs a new ObjectListDataProvider wrapping the specified list with the specified include fields flag.
 
Method Summary
 void addObject(java.lang.Object object)
          Append the specified object to the list of contained objects.
 void addTransactionalDataListener(TransactionalDataListener listener)
          

Register a new TransactionalDataListener to this TransactionalDataProvider instance.

 RowKey appendRow()
          Construct a new instance of the specified object type and append it to the end of the list.
 RowKey appendRow(java.lang.Object object)
          Append the specified object to the end of the list.
 boolean canAppendRow()
          Return true if the userResizable property is set to true, and there is a public zero-args constructor for the class specified by the objectType property.
 boolean canInsertRow(RowKey beforeRow)
          Return true if the userResizable property is set to true, and there is a public zero-args constructor for the class specified by the objectType property.
 boolean canRemoveRow(RowKey row)
          Return true if the userResizable property is set to true.
 void clearObjectList()
          Clear the list of contained objects.
 void commitChanges()
          Cause any cached updates to existing field values, as well as inserted and deleted rows, to be flowed through to the underlying List wrapped by this DataProvider.
 FieldKey getFieldKey(java.lang.String fieldId)
          

Returns the FieldKey associated with the specified data element canonical id, if any; otherwise, return null.

 FieldKey[] getFieldKeys()
          
 java.util.List getList()
          Return the List that we are wrapping.
 java.lang.Object getObject(RowKey row)
          Returns the object stored at the specified row.
 java.lang.Object[] getObjects()
          Return the contained objects as an array.
 java.lang.Class getObjectType()
          Return the object type that this data provider contains.
 int getRowCount()
          
 TransactionalDataListener[] getTransactionalDataListeners()
          
 java.lang.Class getType(FieldKey fieldKey)
          

Returns the data type of the data element referenced by the specified data key.

 java.lang.Object getValue(FieldKey fieldKey)
          

Returns value of the data element referenced by the specified FieldKey.

 java.lang.Object getValue(FieldKey fieldKey, RowKey rowKey)
          

Return value of the data element referenced by the specified FieldKey and RowKey.

 RowKey insertRow(RowKey beforeRow)
          Construct a new instance of the specified object type and insert it at the specified position in the list.
 boolean isIncludeFields()
          Return the state of the includeFields property.
 boolean isReadOnly(FieldKey fieldKey)
          

Return a flag indicating whether the value of the data element represented by the specified FieldKey can be modified via the setValue() method.

 boolean isRemoved(RowKey row)
          Return true if the specified row has been marked for removal on the next call to commitChanges().
 boolean isRowAvailable(RowKey row)
          Return true if the specified RowKey represents a row in the original list, or a row that has been appended.
 boolean isUserResizable()
          Return the current state of the userResizable property.
 void removeObject(java.lang.Object object)
          Remove the specified object from the list of contained objects.
 void removeObject(RowKey row)
          Remove the object at the specified row from the list of contained objects.
 void removeRow(RowKey row)
          Remove the object at the specified row from the list.
 void removeTransactionalDataListener(TransactionalDataListener listener)
          

Deregister an existing TransactionalDataListener from TransactionalDataProvider instance.

 void revertChanges()
          

Cause any cached changes to values of data elements supported by this DataProvider to be thrown away, so that the initial values are again visible.

 void setIncludeFields(boolean includeFields)
          Set the includeFields property.
 void setList(java.util.List list)
          Replace the List that we are wrapping.
 void setObject(RowKey row, java.lang.Object object)
          Replace the object at the specified row.
 void setObjectType(java.lang.Class objectType)
          Set the object type contained in this ObjectListDataProvider.
 void setUserResizable(boolean resizable)
          Set the user resizable property.
 void setValue(FieldKey fieldKey, java.lang.Object value)
          

Set the value of the data element represented by the specified FieldKey to the specified new value.

 void setValue(FieldKey fieldKey, RowKey rowKey, java.lang.Object value)
          

Sets the value of the data element represented by the specified FieldKey and RowKey to the specified new value.

 
Methods inherited from class com.sun.data.provider.impl.AbstractTableDataProvider
addTableCursorListener, addTableDataListener, cursorFirst, cursorLast, cursorNext, cursorPrevious, findAll, findAll, findAll, findAll, findFirst, findFirst, findFirst, findFirst, fireCursorChanged, fireCursorChanging, fireRowAdded, fireRowRemoved, fireValueChanged, getAllRows, getCursorIndex, getCursorRow, getRowKey, getRowKeys, getTableCursorListeners, getTableDataListeners, getValue, removeTableCursorListener, removeTableDataListener, setCursorIndex, setCursorRow, setValue
 
Methods inherited from class com.sun.data.provider.impl.AbstractDataProvider
addDataListener, addFieldKey, addFieldKeys, clearFieldKeys, fireProviderChanged, fireValueChanged, getDataListeners, getFakeData, getFakeData, getType, getValue, isReadOnly, removeDataListener, removeFieldKey, removeFieldKeys, setValue, sortFieldKeys
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.data.provider.DataProvider
addDataListener, getDataListeners, removeDataListener
 

Constructor Detail

ObjectListDataProvider

public ObjectListDataProvider()

Construct a new ObjectListDataProvider with no known object type. The setObjectType() method can be used to set the object type. If not set, the first added object will automatically define the object type.


ObjectListDataProvider

public ObjectListDataProvider(java.util.List list)

Constructs a new ObjectListDataProvider wrapping the specified list.

Parameters:
list - List to be wrapped

ObjectListDataProvider

public ObjectListDataProvider(java.util.List list,
                              boolean includeFields)

Constructs a new ObjectListDataProvider wrapping the specified list with the specified include fields flag.

Parameters:
list - List to be wrapped
includeFields - Desired include fields property setting

ObjectListDataProvider

public ObjectListDataProvider(java.lang.Class objectType)

Constructs a new ObjectListDataProvider for the specified object type.

Parameters:
objectType - Desired object type Class

ObjectListDataProvider

public ObjectListDataProvider(java.lang.Class objectType,
                              boolean includeFields)

Constructs a new ObjectListDataProvider for the specified object type and includeFields property value.

Parameters:
objectType - Desired object type Class
includeFields - Desired include fields property setting
Method Detail

isIncludeFields

public boolean isIncludeFields()

Return the state of the includeFields property.


setIncludeFields

public void setIncludeFields(boolean includeFields)

Set the includeFields property. This affects the set of FieldKeys that this DataProvider emits. If the property is set to true (the default), then public fields will be included in the list of available keys (intermixed with the public properties). Otherwise, only the public properties will be available.

Parameters:
includeFields - The new include fields value

getList

public java.util.List getList()
Return the List that we are wrapping.


setList

public void setList(java.util.List list)

Replace the List that we are wrapping. In addition, the objectType property will be reset based on the class of the first element in the list (if any). If the list is empty, objectType will be set to null.

Parameters:
list - The new list to be wrapped

getObjectType

public java.lang.Class getObjectType()

Return the object type that this data provider contains. This determines the list of FieldKeys that this provider supplies.


setObjectType

public void setObjectType(java.lang.Class objectType)

Set the object type contained in this ObjectListDataProvider. This type determines the list of public properties and fields to expose as FieldKeys. If no object type is specified, the first added object's class will be used as the object type.

Parameters:
objectType - The desired Class type to be contained in this ObjectDataProvider

isUserResizable

public boolean isUserResizable()

Return the current state of the userResizable property. Note that the wrapped list will not be actually resizable unless there is a public no-args constructor on the objectType class.


setUserResizable

public void setUserResizable(boolean resizable)

Set the user resizable property. If set to true (the default), the resizability of this ObjectListDataProvider is based on wether or not a public default constructor exists in the object type. If the userResizable propert is set to false, then this ObjectListDataProvider will not be resizable, regardless of the existence of a public default constructor on the object type.

Parameters:
resizable - true to make this ObjectListDataProvider resizable, pending the existence of a public default constructor on the contained object type, or false to make it non-resizable.
See Also:
TableDataProvider.canInsertRow(RowKey beforeRow)

addObject

public void addObject(java.lang.Object object)

Append the specified object to the list of contained objects.

Parameters:
object - The Object to store in the list

clearObjectList

public void clearObjectList()

Clear the list of contained objects.


getObject

public java.lang.Object getObject(RowKey row)

Returns the object stored at the specified row.

Parameters:
row - The desired row to retrieve the contained object from

getObjects

public java.lang.Object[] getObjects()

Return the contained objects as an array.


isRemoved

public boolean isRemoved(RowKey row)

Return true if the specified row has been marked for removal on the next call to commitChanges().

Parameters:
row - The RowKey of the row to check

removeObject

public void removeObject(java.lang.Object object)

Remove the specified object from the list of contained objects.

Parameters:
object - The Object to remove from the list

removeObject

public void removeObject(RowKey row)

Remove the object at the specified row from the list of contained objects.

Parameters:
row - The desired Object row to remove from the list

setObject

public void setObject(RowKey row,
                      java.lang.Object object)

Replace the object at the specified row.

Parameters:
row - The desired row to set the contained object
object - The new object to set at the specified row

getFieldKey

public FieldKey getFieldKey(java.lang.String fieldId)
                     throws DataProviderException

Returns the FieldKey associated with the specified data element canonical id, if any; otherwise, return null.

Specified by:
getFieldKey in interface DataProvider
Overrides:
getFieldKey in class AbstractDataProvider
Throws:
DataProviderException

getFieldKeys

public FieldKey[] getFieldKeys()
                        throws DataProviderException

Specified by:
getFieldKeys in interface DataProvider
Overrides:
getFieldKeys in class AbstractDataProvider
Throws:
DataProviderException

getType

public java.lang.Class getType(FieldKey fieldKey)
                        throws DataProviderException

Returns the data type of the data element referenced by the specified data key.

Specified by:
getType in interface DataProvider
Specified by:
getType in class AbstractTableDataProvider
Throws:
DataProviderException

getValue

public java.lang.Object getValue(FieldKey fieldKey)
                          throws DataProviderException

Returns value of the data element referenced by the specified FieldKey.

Specified by:
getValue in interface DataProvider
Overrides:
getValue in class AbstractTableDataProvider
Throws:
DataProviderException

setValue

public void setValue(FieldKey fieldKey,
                     java.lang.Object value)
              throws DataProviderException

Set the value of the data element represented by the specified FieldKey to the specified new value.

Specified by:
setValue in interface DataProvider
Overrides:
setValue in class AbstractTableDataProvider
Throws:
DataProviderException

isReadOnly

public boolean isReadOnly(FieldKey fieldKey)
                   throws DataProviderException

Return a flag indicating whether the value of the data element represented by the specified FieldKey can be modified via the setValue() method.

Specified by:
isReadOnly in interface DataProvider
Specified by:
isReadOnly in class AbstractTableDataProvider
Throws:
DataProviderException

getRowCount

public int getRowCount()
                throws DataProviderException

Specified by:
getRowCount in interface TableDataProvider
Specified by:
getRowCount in class AbstractTableDataProvider
Throws:
DataProviderException

getValue

public java.lang.Object getValue(FieldKey fieldKey,
                                 RowKey rowKey)
                          throws DataProviderException

Return value of the data element referenced by the specified FieldKey and RowKey.

Specified by:
getValue in interface TableDataProvider
Specified by:
getValue in class AbstractTableDataProvider
Throws:
DataProviderException

isRowAvailable

public boolean isRowAvailable(RowKey row)
                       throws DataProviderException

Return true if the specified RowKey represents a row in the original list, or a row that has been appended. FIXME - deal with RowKeys for inserted rows too, when inserts are supported.

Specified by:
isRowAvailable in interface TableDataProvider
Overrides:
isRowAvailable in class AbstractTableDataProvider
Parameters:
row - RowKey to test for availability
Throws:
DataProviderException

setValue

public void setValue(FieldKey fieldKey,
                     RowKey rowKey,
                     java.lang.Object value)
              throws DataProviderException

Sets the value of the data element represented by the specified FieldKey and RowKey to the specified new value.

Specified by:
setValue in interface TableDataProvider
Specified by:
setValue in class AbstractTableDataProvider
Throws:
DataProviderException

canAppendRow

public boolean canAppendRow()
                     throws DataProviderException

Return true if the userResizable property is set to true, and there is a public zero-args constructor for the class specified by the objectType property.

This method is called to test if this TableDataProvider supports the append operation. If rows can be appended to the list, this method should return true. If the data provider is not resizable, or cannot support an append operation, this method should return false.

Specified by:
canAppendRow in interface TableDataProvider
Specified by:
canAppendRow in class AbstractTableDataProvider
Throws:
DataProviderException

appendRow

public RowKey appendRow()
                 throws DataProviderException

Construct a new instance of the specified object type and append it to the end of the list.

Appends a new row at the end of the list and returns the row key for the newly appended row.

NOTE: The method should only be called after testing the canAppendRow() method to see if this TableDataProvider supports the append operation.

Specified by:
appendRow in interface TableDataProvider
Specified by:
appendRow in class AbstractTableDataProvider
Throws:
DataProviderException

appendRow

public RowKey appendRow(java.lang.Object object)
                 throws DataProviderException

Append the specified object to the end of the list.

Parameters:
object - Object to be appended
Throws:
DataProviderException

canInsertRow

public boolean canInsertRow(RowKey beforeRow)
                     throws DataProviderException

Return true if the userResizable property is set to true, and there is a public zero-args constructor for the class specified by the objectType property.

This method is called to test if this TableDataProvider supports resizability. If objects can be inserted and removed from the list, this method should return true. If the data provider is not resizable, this method should return false.

The following methods will only be called if this method returns true:

  • insertRow(RowKey beforeRow)
  • appendRow()
  • removeRow(RowKey rowKey)

Specified by:
canInsertRow in interface TableDataProvider
Specified by:
canInsertRow in class AbstractTableDataProvider
Throws:
DataProviderException

insertRow

public RowKey insertRow(RowKey beforeRow)
                 throws DataProviderException

Construct a new instance of the specified object type and insert it at the specified position in the list.

Specified by:
insertRow in interface TableDataProvider
Specified by:
insertRow in class AbstractTableDataProvider
Parameters:
beforeRow - Row before which to insert the new row
Throws:
DataProviderException

canRemoveRow

public boolean canRemoveRow(RowKey row)
                     throws DataProviderException

Return true if the userResizable property is set to true.

This method is called to test if this TableDataProvider supports the removeRow operation. If rows can be removed from the table, this method should return true. If the data provider is does not support removing rows, this method should return false.

Specified by:
canRemoveRow in interface TableDataProvider
Specified by:
canRemoveRow in class AbstractTableDataProvider
Throws:
DataProviderException

removeRow

public void removeRow(RowKey row)
               throws DataProviderException

Remove the object at the specified row from the list.

Removes the specified row.

NOTE: The method should only be called after testing the canRemoveRow(RowKey) method to see if this TableDataProvider supports removing rows.

Specified by:
removeRow in interface TableDataProvider
Specified by:
removeRow in class AbstractTableDataProvider
Throws:
DataProviderException

commitChanges

public void commitChanges()
                   throws DataProviderException

Cause any cached updates to existing field values, as well as inserted and deleted rows, to be flowed through to the underlying List wrapped by this DataProvider.

Specified by:
commitChanges in interface TransactionalDataProvider
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException). Consult the documentation of the specific DataProvider implementation for details on what exceptions might be wrapped by a DPE.

revertChanges

public void revertChanges()
                   throws DataProviderException

Cause any cached changes to values of data elements supported by this DataProvider to be thrown away, so that the initial values are again visible.

Specified by:
revertChanges in interface TransactionalDataProvider
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException). Consult the documentation of the specific DataProvider implementation for details on what exceptions might be wrapped by a DPE.

addTransactionalDataListener

public void addTransactionalDataListener(TransactionalDataListener listener)

Register a new TransactionalDataListener to this TransactionalDataProvider instance.

Specified by:
addTransactionalDataListener in interface TransactionalDataProvider
Parameters:
listener - New TransactionalDataListener to register

getTransactionalDataListeners

public TransactionalDataListener[] getTransactionalDataListeners()

Specified by:
getTransactionalDataListeners in interface TransactionalDataProvider
Returns:
An array of the TransactionalDataListeners currently registered on this TransactionalDataProvider. If there are no registered listeners, a zero-length array is returned.

removeTransactionalDataListener

public void removeTransactionalDataListener(TransactionalDataListener listener)

Deregister an existing TransactionalDataListener from TransactionalDataProvider instance.

Specified by:
removeTransactionalDataListener in interface TransactionalDataProvider
Parameters:
listener - Old TransactionalDataListener to remove