com.sun.data.provider.impl
Class ObjectDataProvider

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

public class ObjectDataProvider
extends AbstractDataProvider

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

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

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.sun.data.provider.impl.AbstractDataProvider
dpListeners, fieldKeys
 
Constructor Summary
ObjectDataProvider()
          Constructs a new ObjectDataProvider with default settings, and no contained Object.
ObjectDataProvider(java.lang.Object object)
          Constructs a new ObjectDataProvider to wrap the specified Object.
ObjectDataProvider(java.lang.Object object, boolean includeFields)
          Creates a new ObjectDataProvider to wrap the specified Object.
 
Method Summary
 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.Object getObject()
           
 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.

 boolean isIncludeFields()
           
 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 setIncludeFields(boolean includeFields)
          Sets the includeFields property.
 void setObject(java.lang.Object object)
          Sets the Object to be wrapped by this DataProvider.
 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.

 
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
 

Constructor Detail

ObjectDataProvider

public ObjectDataProvider()
Constructs a new ObjectDataProvider with default settings, and no contained Object. Use setObject to set the contained Object.


ObjectDataProvider

public ObjectDataProvider(java.lang.Object object)
Constructs a new ObjectDataProvider to wrap the specified Object.

Parameters:
object - The Object to wrap as a DataProvider

ObjectDataProvider

public ObjectDataProvider(java.lang.Object object,
                          boolean includeFields)
Creates a new ObjectDataProvider to wrap the specified Object. The public fields will be included if 'includeFields' is set to true.

Parameters:
object - The Object to wrap as a DataProvider
includeFields - true to include the public fields, false to only surface the public properties as FieldKeys.
Method Detail

getObject

public java.lang.Object getObject()
Returns:
The Object being represented by this DataProvider

setObject

public void setObject(java.lang.Object object)
Sets the Object to be wrapped by this DataProvider. Calling this method will result in the passed object being introspected to populate the list of public properties and fields to make up the list of FieldKeys.

Parameters:
object - The Object to be wrapped by this DataProvider

isIncludeFields

public boolean isIncludeFields()
Returns:
The boolean state of the includeFields property

setIncludeFields

public void setIncludeFields(boolean includeFields)

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

Parameters:
includeFields - true to include the public fields, or false to exclude them (and only show public properties)

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 AbstractDataProvider
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
Specified by:
getValue in class AbstractDataProvider
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
Specified by:
setValue in class AbstractDataProvider
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 AbstractDataProvider
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.