com.sun.data.provider.impl
Class MethodResultDataProvider

java.lang.Object
  extended bycom.sun.data.provider.impl.MethodResultDataProvider
All Implemented Interfaces:
DataProvider, RefreshableDataProvider, java.io.Serializable

public class MethodResultDataProvider
extends java.lang.Object
implements RefreshableDataProvider, java.io.Serializable

A DataProvider implementation to wrap the singleton (non-array) return value from a method. Set the dataClassInstance, dataMethod, and dataMethodArguments properties to point to a method on a class instance. The result from that method call will be wrapped as a DataProvider.

Author:
cao, Joe Nuxoll
See Also:
Serialized Form

Constructor Summary
MethodResultDataProvider()
          Constructs a new MethodResultDataProvider with no dataClassInstance or dataMethod specified.
MethodResultDataProvider(java.lang.Object dataClassInstance, java.lang.reflect.Method dataMethod)
          Constructs a new MethodResultDataProvider using the specified dataClassInstance and dataMethod.
 
Method Summary
 void addDataListener(DataListener listener)
          

Register a new DataListener to this DataProvider instance.

 void addRefreshableDataListener(RefreshableDataListener l)
          

Register a new RefreshableDataListener to this RefreshableDataProvider instance.

protected  void fireRefreshed()
          Fires a refreshed event to each registered RefreshableDataListener
 java.lang.Object getDataClassInstance()
          Returns the dataClassInstance that contains the dataMethod to be invoked.
 DataListener[] getDataListeners()
          
 java.lang.reflect.Method getDataMethod()
          Returns the currently set dataMethod
 java.lang.Object[] getDataMethodArguments()
          Returns the dataMethodArguments
 FieldKey getFieldKey(java.lang.String fieldId)
          

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

 FieldKey[] getFieldKeys()
          
 RefreshableDataListener[] getRefreshableDataListeners()
          
 java.lang.Object getResultObject()
          Read-only access to the result object from the invokation of the dataMethod
 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.

 void invokeDataMethod()
          Invokes the dataMethod using the arguments specified by the dataMethodArguments property.
 void invokeDataMethod(java.lang.Object[] args)
          Invokes the dataMethod using the specified arguments.
 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 refresh()
          Invokes the dataMethod on the dataClassInstance to refresh the data provider's contets
protected  void refreshFieldKeys()
          Refreshes the list of available fieldKeys (based on the return type of the dataMethod)
 void removeDataListener(DataListener listener)
          

Deregister an existing DataListener from this DataProvider instance.

 void removeRefreshableDataListener(RefreshableDataListener l)
          

Deregister an existing RefreshableDataListener from RefreshableDataProvider instance.

 void setDataClassInstance(java.lang.Object instance)
          Sets the dataClassInstance that contains the dataMethod to be invoked.
 void setDataMethod(java.lang.reflect.Method method)
          Sets the dataMethod that will be invoked
 void setDataMethodArguments(java.lang.Object[] methodArgs)
          Sets the dataMethodArguments, which will be passed to the dataMethod when it is invoked.
 void setIncludeFields(boolean includeFields)
          Sets the includeFields 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.

protected  void testInvokeDataMethod()
          Tests to see if the dataMethod has been invoked, and invokes it if it has not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MethodResultDataProvider

public MethodResultDataProvider()
Constructs a new MethodResultDataProvider with no dataClassInstance or dataMethod specified.


MethodResultDataProvider

public MethodResultDataProvider(java.lang.Object dataClassInstance,
                                java.lang.reflect.Method dataMethod)
Constructs a new MethodResultDataProvider using the specified dataClassInstance and dataMethod.

Parameters:
dataClassInstance - The class instance where the method is invoked
dataMethod - The method where the data is from
Method Detail

getDataClassInstance

public java.lang.Object getDataClassInstance()
Returns the dataClassInstance that contains the dataMethod to be invoked.

Returns:
Object

setDataClassInstance

public void setDataClassInstance(java.lang.Object instance)
Sets the dataClassInstance that contains the dataMethod to be invoked.

Parameters:
instance - Object

getDataMethod

public java.lang.reflect.Method getDataMethod()
Returns the currently set dataMethod

Returns:
Method

setDataMethod

public void setDataMethod(java.lang.reflect.Method method)
Sets the dataMethod that will be invoked

Parameters:
method - Method

getResultObject

public java.lang.Object getResultObject()
                                 throws DataProviderException
Read-only access to the result object from the invokation of the dataMethod

Returns:
Object
Throws:
DataProviderException

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)

isIncludeFields

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

refreshFieldKeys

protected void refreshFieldKeys()
Refreshes the list of available fieldKeys (based on the return type of the dataMethod)


setDataMethodArguments

public void setDataMethodArguments(java.lang.Object[] methodArgs)
Sets the dataMethodArguments, which will be passed to the dataMethod when it is invoked.

Parameters:
methodArgs - Object[]

getDataMethodArguments

public java.lang.Object[] getDataMethodArguments()
Returns the dataMethodArguments

Returns:
Object[]

invokeDataMethod

public void invokeDataMethod()
                      throws DataProviderException
Invokes the dataMethod using the arguments specified by the dataMethodArguments property.

Throws:
DataProviderException

invokeDataMethod

public void invokeDataMethod(java.lang.Object[] args)
                      throws DataProviderException
Invokes the dataMethod using the specified arguments.

Parameters:
args - Object[]
Throws:
DataProviderException

testInvokeDataMethod

protected void testInvokeDataMethod()
                             throws DataProviderException
Tests to see if the dataMethod has been invoked, and invokes it if it has not.

Throws:
DataProviderException

refresh

public void refresh()
             throws DataProviderException
Invokes the dataMethod on the dataClassInstance to refresh the data provider's contets

Specified by:
refresh in interface RefreshableDataProvider
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.

addRefreshableDataListener

public void addRefreshableDataListener(RefreshableDataListener l)

Register a new RefreshableDataListener to this RefreshableDataProvider instance.

Specified by:
addRefreshableDataListener in interface RefreshableDataProvider
Parameters:
l - New RefreshableDataListener to register

removeRefreshableDataListener

public void removeRefreshableDataListener(RefreshableDataListener l)

Deregister an existing RefreshableDataListener from RefreshableDataProvider instance.

Specified by:
removeRefreshableDataListener in interface RefreshableDataProvider
Parameters:
l - Old RefreshableDataListener to remove

getRefreshableDataListeners

public RefreshableDataListener[] getRefreshableDataListeners()

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

fireRefreshed

protected void fireRefreshed()
Fires a refreshed event to each registered RefreshableDataListener

See Also:
RefreshableDataListener.refreshed(RefreshableDataProvider)

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.

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

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

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

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.