com.sun.data.provider.impl
Class ObjectArrayDataProvider

java.lang.Object
  extended by com.sun.data.provider.impl.AbstractDataProvider
      extended by com.sun.data.provider.impl.AbstractTableDataProvider
          extended by com.sun.data.provider.impl.ObjectArrayDataProvider
All Implemented Interfaces:
DataProvider, TableDataProvider, java.io.Serializable

public class ObjectArrayDataProvider
extends AbstractTableDataProvider
implements java.io.Serializable

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

Note that this TableDataProvider determines which fields are available by examining the underlying component data type of the array. If you pass in an array that is of type Object[], then, perhaps with initialization code like this:

   Map map = ...;
   return new ObjectArrayDataProvider(map.values().toArray());
 

the fields of your actual object type will not be available. If you know that your data is all of type Foo, do this instead:

   Map map = ...;
   return new ObjectArrayDataProvider
     ((Foo[]) map.values().toArray(new Foo[0]));
 

Since this TableDataProvider wraps an array, and arrays in Java are not intrinsically resizeable, this implementation will return false for any call to canAppendRow(), canInsertRow(), or canRemoveRow(). It will throw UnsupportedOperationException if you attempt to call appendRow(), insertRow(), or removeRow().

WARNING - Until you call setArray() or setObjectType() with a non-null parameter, or use a constructor variant that accepts an non-null array, 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 an array of any Java Objects. For this class to remain Serializable, the contained Objects must also be Serializable.

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
ObjectArrayDataProvider()
          Construct a new ObjectArrayDataProvider with no known data.
ObjectArrayDataProvider(java.lang.Object[] array)
          Constructs a new ObjectArraytDataProvider wrapping the specified array.
ObjectArrayDataProvider(java.lang.Object[] array, boolean includeFields)
          Constructs a new ObjectArraytDataProvider wrapping the specified array and value of the includeFields property.
 
Method Summary
 RowKey appendRow()
          

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.

 boolean canAppendRow()
          

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.

 boolean canInsertRow(RowKey beforeRow)
          

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)
 boolean canRemoveRow(RowKey row)
          

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.

 java.lang.Object[] getArray()
          Return the array that we are wrapping.
 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.lang.Class getObjectType()
          Return the object type that this data provider contains.
 int getRowCount()
          
 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)
          

Inserts a new row at the specified row.

NOTE: The method should only be called after testing the canInsertRow(RowKey beforeRow) to see if this TableDataProvider supports resizing.

 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.

 void removeRow(RowKey row)
          Remove the object at the specified row from the list.
 void setArray(java.lang.Object[] array)
          Replace the array that we are wrapping.
 void setIncludeFields(boolean includeFields)
          Set the includeFields property.
 void setObjectType(java.lang.Class objectType)
          Set the object type contained in this ObjectListDataProvider.
 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, isRowAvailable, 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

ObjectArrayDataProvider

public ObjectArrayDataProvider()

Construct a new ObjectArrayDataProvider with no known data. The setArray() method can be used to set the contained array.


ObjectArrayDataProvider

public ObjectArrayDataProvider(java.lang.Object[] array)

Constructs a new ObjectArraytDataProvider wrapping the specified array.

Parameters:
array - Array to be wrapped

ObjectArrayDataProvider

public ObjectArrayDataProvider(java.lang.Object[] array,
                               boolean includeFields)

Constructs a new ObjectArraytDataProvider wrapping the specified array and value of the includeFields property.

Parameters:
array - Array to be wrapped
includeFields - Desired includeFields property
Method Detail

getArray

public java.lang.Object[] getArray()
Return the array that we are wrapping.


setArray

public void setArray(java.lang.Object[] array)

Replace the array that we are wrapping. In addition, the objectType property will be reset based on the class of the underlying element type.

Parameters:
array - The new array 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

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

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
Parameters:
fieldId - Canonical id of the requested FieldKey
Returns:
the FieldKey associated with the specified data element canonical id, if any; otherwise, return null
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException) rather than simply returning null. A DPE may also indicate that the passed fieldId is not valid. Consult the documentation of the specific DataProvider implementation for details on what exceptions might be wrapped by a DPE.

getFieldKeys

public FieldKey[] getFieldKeys()
                        throws DataProviderException

Specified by:
getFieldKeys in interface DataProvider
Overrides:
getFieldKeys in class AbstractDataProvider
Returns:
An array of all FieldKeys supported by this DataProvider. If the set of valid FieldKeys cannot be determined, return null instead.
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException) rather than simply returning null or an empty array. Consult the documentation of the specific DataProvider implementation for details on what exceptions might be wrapped by a DPE.

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
Parameters:
fieldKey - FieldKey identifying the data element whose type is to be returned
Returns:
the data type of the data element referenced by the specified data key
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException) rather than simply returning null. A DPE may also indicate that the passed fieldKey is not valid. Consult the documentation of the specific DataProvider implementation for details on what exceptions might be wrapped by a DPE.

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
Parameters:
fieldKey - FieldKey identifying the data element whose value is to be returned
Returns:
value of the data element referenced by the specified FieldKey
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException) rather than simply returning null. A DPE may also indicate that the passed fieldKey is not valid. Consult the documentation of the specific DataProvider implementation for details on what exceptions might be wrapped by a DPE.

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
Parameters:
fieldKey - FieldKey identifying the data element whose value is to be modified
value - New value for this data element
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException) rather than simply returning null. A DPE may also indicate that the passed fieldKey is not valid. Consult the documentation of the specific DataProvider implementation for details on what exceptions might be wrapped by a DPE.

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
Parameters:
fieldKey - FieldKey identifying the data element whose settable status is to be returned
Returns:
a flag indicating whether the value of the data element represented by the specified FieldKey can be modified via the setValue() method
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException) rather than simply returning true. A DPE may also indicate that the passed fieldKey is not valid. Consult the documentation of the specific DataProvider implementation for details on what exceptions might be wrapped by a DPE.

getRowCount

public int getRowCount()
                throws DataProviderException

Specified by:
getRowCount in interface TableDataProvider
Specified by:
getRowCount in class AbstractTableDataProvider
Returns:
the number of rows represented by this TableDataProvider if this information is available; otherwise, return -1 (indicating unknown row count)
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException) rather than simply returning -1. Consult the documentation of the specific TableDataProvider implementation for details on what exceptions might be wrapped by a DPE.

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
Parameters:
fieldKey - FieldKey identifying the data element whose value is to be returned
rowKey - RowKey identifying the data row whose value is to be returned
Returns:
value of the data element referenced by the specified FieldKey and RowKey
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException) rather than simply returning null. A DPE may also indicate that this FieldKey or RowKey does not represent a data element provided by this TableDataProvider. Consult the documentation of the specific TableDataProvider implementation for details on what exceptions might be wrapped by a DPE.

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
Parameters:
fieldKey - FieldKey identifying the data element whose value is to be modified
rowKey - RowKey indentifying the data row whose value is to be modified
value - New value for this data element
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException). A DPE may also indicate that this FieldKey or RowKey does not represent a data element provided by this TableDataProvider. Consult the documentation of the specific TableDataProvider implementation for details on what exceptions might be wrapped by a DPE.

canAppendRow

public boolean canAppendRow()
                     throws DataProviderException

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
Returns:
true if the data provider supports the append operation, or false if not.
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException). A DPE may also indicate that this RowKey does not represent a row provided by this TableDataProvider. Consult the documentation of the specific TableDataProvider implementation for details on what exceptions might be wrapped by a DPE.
See Also:
TableDataProvider.appendRow()

appendRow

public RowKey appendRow()
                 throws DataProviderException

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
Returns:
The row key for the newly appended row
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException). Consult the documentation of the specific TableDataProvider implementation for details on what exceptions might be wrapped by a DPE.
See Also:
TableDataProvider.canAppendRow()

canInsertRow

public boolean canInsertRow(RowKey beforeRow)
                     throws DataProviderException

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
Parameters:
beforeRow - The desired location to insert the new row in front of
Returns:
true if the data provider is resizable, or false if not.
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException) rather than simply returning false. A DPE may also indicate that this RowKey does not represent a row provided by this TableDataProvider. Consult the documentation of the specific TableDataProvider implementation for details on what exceptions might be wrapped by a DPE.
See Also:
TableDataProvider.insertRow(RowKey)

insertRow

public RowKey insertRow(RowKey beforeRow)
                 throws DataProviderException

Inserts a new row at the specified row.

NOTE: The method should only be called after testing the canInsertRow(RowKey beforeRow) to see if this TableDataProvider supports resizing.

Specified by:
insertRow in interface TableDataProvider
Specified by:
insertRow in class AbstractTableDataProvider
Parameters:
beforeRow - The desired location to insert the new row in front of
Returns:
A RowKey representing the address of the newly inserted row
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException). A DPE may also indicate that this RowKey does not represent a row provided by this TableDataProvider. Consult the documentation of the specific TableDataProvider implementation for details on what exceptions might be wrapped by a DPE.
See Also:
TableDataProvider.canInsertRow(RowKey)

canRemoveRow

public boolean canRemoveRow(RowKey row)
                     throws DataProviderException

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
Parameters:
row - The desired row to remove
Returns:
true if the data provider supports removing rows, or false if not.
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException). A DPE may also indicate that this RowKey does not represent a row provided by this TableDataProvider. Consult the documentation of the specific TableDataProvider implementation for details on what exceptions might be wrapped by a DPE.
See Also:
TableDataProvider.removeRow(RowKey)

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
Parameters:
row - The desired row key to remove
Throws:
DataProviderException - Implementations may wish to surface internal exceptions (nested in DataProviderException). A DPE may also indicate that this RowKey does not represent a row provided by this TableDataProvider. Consult the documentation of the specific TableDataProvider implementation for details on what exceptions might be wrapped by a DPE.
See Also:
TableDataProvider.canRemoveRow(RowKey)