com.sun.data.provider.impl
Class MapDataProvider

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

public class MapDataProvider
extends AbstractDataProvider

This DataProvider wraps access to a standard Map. This class can use regular MapDataProvider.MapFieldKey objects as keys (Map key will be the FieldKey's fieldId), or can use MapDataProvider.MapFieldKey objects if a non-string key is desired.

NOTE about Serializable: By default, this class uses a HashMap as its internal data storage, which is a Serializable implementation of Map. The internal storage can be swapped out using the setMap(Map) method. For this class to remain Serializable, the contained Map must be a Serializable implementation. Also, and more importantly, the contents of the storage Map must be Serializable as well for this class to successfully be serialized.

Author:
Joe Nuxoll
See Also:
Serialized Form

Nested Class Summary
 class MapDataProvider.MapFieldKey
          MapFieldKey is a FieldKey that contains an untyped Object to use as a key for a map value.
 
Field Summary
protected  java.util.Map map
          The internal storage Map, initially a HashMap
 
Fields inherited from class com.sun.data.provider.impl.AbstractDataProvider
dpListeners, fieldKeys
 
Constructor Summary
MapDataProvider()
          Constructs a new MapDataProvider using a default HashMap as the internal storage.
MapDataProvider(java.util.Map map)
          Constructs a new MapDataProvider using the specified Map as the internal storage.
 
Method Summary
 FieldKey getFieldKey(java.lang.String fieldId)
          Returns a MapDataProvider.MapFieldKey corresponding to the specified id.
 FieldKey[] getFieldKeys()
          
 java.util.Map getMap()
           
 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 the value stored under the specified FieldKey in the Map.
 boolean isReadOnly(FieldKey fieldKey)
          None of the Map entries are read-only, so this method always returns false.
protected  void refreshFieldKeys()
          Refreshes the list of FieldKeys to reflect the current contents of the Map.
 void setMap(java.util.Map map)
          Sets the Map to use as internal storage.
 void setValue(FieldKey fieldKey, java.lang.Object value)
          Puts the specified value in the Map under the specified FieldKey.
 
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
 

Field Detail

map

protected java.util.Map map
The internal storage Map, initially a HashMap

Constructor Detail

MapDataProvider

public MapDataProvider()
Constructs a new MapDataProvider using a default HashMap as the internal storage.


MapDataProvider

public MapDataProvider(java.util.Map map)

Constructs a new MapDataProvider using the specified Map as the internal storage.

NOTE about Serializable: By default, this class uses a HashMap as its internal data storage, which is a Serializable implementation of Map. The internal storage can be swapped out using the setMap(Map) method. For this class to remain Serializable, the contained Map must be a Serializable implementation. Also, and more importantly, the contents of the storage Map must be Serializable as well for this class to successfully be serialized.

Parameters:
map - The Map to use as internal storage
Method Detail

getMap

public java.util.Map getMap()
Returns:
Map being used as internal storage.

setMap

public void setMap(java.util.Map map)

Sets the Map to use as internal storage.

NOTE about Serializable: By default, this class uses a HashMap as its internal data storage, which is a Serializable implementation of Map. The internal storage can be swapped out using the setMap(Map) method. For this class to remain Serializable, the contained Map must be a Serializable implementation. Also, and more importantly, the contents of the storage Map must be Serializable as well for this class to successfully be serialized.

Parameters:
map - Map to use as internal storage

refreshFieldKeys

protected void refreshFieldKeys()
Refreshes the list of FieldKeys to reflect the current contents of the Map. This is necessary because the storage Map could be manipulated at any time by external means.


getFieldKeys

public FieldKey[] getFieldKeys()
                        throws DataProviderException
Description copied from class: AbstractDataProvider

Specified by:
getFieldKeys in interface DataProvider
Overrides:
getFieldKeys in class AbstractDataProvider
Returns:
FieldKey[] The current set of FieldKeys in the Map (after completing a refresh)
Throws:
DataProviderException

getFieldKey

public FieldKey getFieldKey(java.lang.String fieldId)
                     throws DataProviderException
Returns a MapDataProvider.MapFieldKey corresponding to the specified id.

Specified by:
getFieldKey in interface DataProvider
Overrides:
getFieldKey in class AbstractDataProvider
Parameters:
fieldId - The desired id to retrieve a FieldKey for
Returns:
FieldKey The FieldKey for the specified id (after completing a refresh)
Throws:
DataProviderException

getValue

public java.lang.Object getValue(FieldKey fieldKey)
                          throws DataProviderException
Returns the value stored under the specified FieldKey in the Map. The passed FieldKey may be a MapDataProvider.MapFieldKey or a MapDataProvider.MapFieldKey.

Specified by:
getValue in interface DataProvider
Specified by:
getValue in class AbstractDataProvider
Parameters:
fieldKey - The desired FieldKey to retieve the value for
Returns:
Object The object stored in the Map under the specified FieldKey
Throws:
DataProviderException

getType

public java.lang.Class getType(FieldKey fieldKey)
                        throws DataProviderException
Description copied from class: AbstractDataProvider

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
Returns:
Class
Throws:
DataProviderException

isReadOnly

public boolean isReadOnly(FieldKey fieldKey)
                   throws DataProviderException
None of the Map entries are read-only, so this method always returns false.

Specified by:
isReadOnly in interface DataProvider
Specified by:
isReadOnly in class AbstractDataProvider
Parameters:
fieldKey - The specified FieldKey (ignored)
Returns:
This method will always return false, as none of the Map entries are read-only.
Throws:
DataProviderException

setValue

public void setValue(FieldKey fieldKey,
                     java.lang.Object value)
              throws DataProviderException
Puts the specified value in the Map under the specified FieldKey. If the passed FieldKey is a MapDataProvider.MapFieldKey, the MapFieldKey.mapKey will be used as the key, otherwise the FieldKey.id will be used as the key in the underlying Map. This method will result in a valueChanged event being fired to all DataListener that are listening to this DataProvider.

Specified by:
setValue in interface DataProvider
Specified by:
setValue in class AbstractDataProvider
Parameters:
fieldKey - The desired FieldKey to store the value under
value - The desired Object to store in the Map
Throws:
DataProviderException