com.sun.data.provider.impl
Class AbstractDataProvider

java.lang.Object
  extended bycom.sun.data.provider.impl.AbstractDataProvider
All Implemented Interfaces:
DataProvider, java.io.Serializable
Direct Known Subclasses:
AbstractTableDataProvider, BasicTransactionalDataProvider, MapDataProvider, ObjectDataProvider, TableRowDataProvider

public abstract class AbstractDataProvider
extends java.lang.Object
implements DataProvider, java.io.Serializable

Abstract base implementation of DataProvider. This class is a convenient base class to use when creating a new DataProvider implementation.

Author:
Joe Nuxoll
See Also:
Serialized Form

Field Summary
protected  DataListener[] dpListeners
          Array of DataListener instances registered for this DataProvider.
protected  FieldKey[] fieldKeys
          storage for the list of FieldKeys in this DataProvider
 
Constructor Summary
AbstractDataProvider()
           
 
Method Summary
 void addDataListener(DataListener listener)
          

Register a new DataListener to this DataProvider instance.

protected  void addFieldKey(FieldKey fieldKey)
          Adds a FieldKey to the list of keys
protected  void addFieldKeys(FieldKey[] fieldKeys)
          Adds a list of FieldKeys to the list of keys
protected  void clearFieldKeys()
          Empties the list of FieldKeys
protected  void fireProviderChanged()
          Fires a providerChanged event to each registered DataListener
protected  void fireValueChanged(FieldKey fieldKey, java.lang.Object oldValue, java.lang.Object newValue)
          Fires a valueChanged event to each registered DataListener
 DataListener[] getDataListeners()
          
static java.lang.Object getFakeData(java.lang.Class dataType)
          This helper method defers to getFakeData(Class, Class) passing null as the collectionElementType.
static java.lang.Object getFakeData(java.lang.Class dataType, java.lang.Class collectionElementType)
          This helper method produces fake data for use during design-time.
 FieldKey getFieldKey(java.lang.String fieldId)
          

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

 FieldKey[] getFieldKeys()
          
abstract  java.lang.Class getType(FieldKey fieldKey)
          

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

 java.lang.Class getType(java.lang.String fieldId)
           
abstract  java.lang.Object getValue(FieldKey fieldKey)
          

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

 java.lang.Object getValue(java.lang.String fieldId)
           
abstract  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 isReadOnly(java.lang.String fieldId)
           
 void removeDataListener(DataListener listener)
          

Deregister an existing DataListener from this DataProvider instance.

protected  void removeFieldKey(FieldKey fieldKey)
          Removes a FieldKey from the list of keys
protected  void removeFieldKeys(FieldKey[] fieldKeys)
          Removes an array of FieldKeys from the list
abstract  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(java.lang.String fieldId, java.lang.Object value)
           
protected  void sortFieldKeys()
          Sorts the FieldKeys (using Arrays.sort)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fieldKeys

protected FieldKey[] fieldKeys
storage for the list of FieldKeys in this DataProvider


dpListeners

protected DataListener[] dpListeners

Array of DataListener instances registered for this DataProvider.

Constructor Detail

AbstractDataProvider

public AbstractDataProvider()
Method Detail

getType

public abstract 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
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.

isReadOnly

public abstract 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
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.

getValue

public abstract 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
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 abstract 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
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.

getType

public java.lang.Class getType(java.lang.String fieldId)
                        throws DataProviderException
Throws:
DataProviderException

isReadOnly

public boolean isReadOnly(java.lang.String fieldId)
                   throws DataProviderException
Throws:
DataProviderException

getValue

public java.lang.Object getValue(java.lang.String fieldId)
                          throws DataProviderException
Throws:
DataProviderException

setValue

public void setValue(java.lang.String fieldId,
                     java.lang.Object value)
              throws DataProviderException
Throws:
DataProviderException

addFieldKey

protected void addFieldKey(FieldKey fieldKey)
Adds a FieldKey to the list of keys

Parameters:
fieldKey - FieldKey to add to the list of keys

addFieldKeys

protected void addFieldKeys(FieldKey[] fieldKeys)
Adds a list of FieldKeys to the list of keys

Parameters:
fieldKeys - FieldKey[] to add to the list of keys

sortFieldKeys

protected void sortFieldKeys()
Sorts the FieldKeys (using Arrays.sort)


removeFieldKey

protected void removeFieldKey(FieldKey fieldKey)
Removes a FieldKey from the list of keys

Parameters:
fieldKey - FieldKey to remove from the list

removeFieldKeys

protected void removeFieldKeys(FieldKey[] fieldKeys)
Removes an array of FieldKeys from the list

Parameters:
fieldKeys - FieldKey[] to remove from the list

clearFieldKeys

protected void clearFieldKeys()
Empties the list of FieldKeys


getFieldKeys

public FieldKey[] getFieldKeys()
                        throws DataProviderException

Specified by:
getFieldKeys in interface DataProvider
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.

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
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.

getFakeData

public static java.lang.Object getFakeData(java.lang.Class dataType)
This helper method defers to getFakeData(Class, Class) passing null as the collectionElementType. This is used for design-time only rendering of fake data.

Parameters:
dataType - The Class representing the type of data to fake
Returns:
The fake data object

getFakeData

public static java.lang.Object getFakeData(java.lang.Class dataType,
                                           java.lang.Class collectionElementType)

This helper method produces fake data for use during design-time. This allows a DataProvider implementation class to avoid a costly call to a database, web service, or EJB method at design-time. This will handle array and collection types as well as object types.

If the underlying type is other than a primitive type or java.lang common type, it is constructed by attempting to use the default constructor for the class, if it exists. The method will then recurse to populate the properties and fields of the nested object (avoiding recursion). If no default constructor exists, this method will return null for the value.

Parameters:
dataType - The Class representing the type of data to fake. This might be a native array, Collection, or any Object subtype
collectionElementType - If the 'dataType' is a Collection type, this parameter specifies the type of element stored in the Collection
Returns:
The fake data object

addDataListener

public void addDataListener(DataListener listener)

Register a new DataListener to this DataProvider instance.

Specified by:
addDataListener in interface DataProvider
Parameters:
listener - New DataListener to register

removeDataListener

public void removeDataListener(DataListener listener)

Deregister an existing DataListener from this DataProvider instance.

Specified by:
removeDataListener in interface DataProvider
Parameters:
listener - Old DataListener to deregister

getDataListeners

public DataListener[] getDataListeners()

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

fireValueChanged

protected void fireValueChanged(FieldKey fieldKey,
                                java.lang.Object oldValue,
                                java.lang.Object newValue)
Fires a valueChanged event to each registered DataListener

Parameters:
fieldKey - FieldKey identifying the changed value
oldValue - The old value (before the change)
newValue - The new value (after the change)
See Also:
DataListener.valueChanged(DataProvider, FieldKey, Object, Object)

fireProviderChanged

protected void fireProviderChanged()
Fires a providerChanged event to each registered DataListener

See Also:
DataListener.providerChanged(DataProvider)