org.directwebremoting.datasync
Class MapStoreProvider<T>

java.lang.Object
  extended by org.directwebremoting.datasync.AbstractStoreProvider<T>
      extended by org.directwebremoting.datasync.MapStoreProvider<T>
All Implemented Interfaces:
StoreProvider<T>

public class MapStoreProvider<T>
extends AbstractStoreProvider<T>
implements StoreProvider<T>

A simple implementation of StoreProvider that uses a Map.

Author:
Joe Walker [joe at getahead dot ltd dot uk]

Constructor Summary
MapStoreProvider(java.lang.Class<T> type)
          Initialize an empty MapStoreProvider from the specified type.
MapStoreProvider(java.util.Map<java.lang.String,T> datamap, java.lang.Class<T> type)
          Initialize the MapStoreProvider from an existing map + specified type.
MapStoreProvider(java.util.Map<java.lang.String,T> datamap, java.lang.Class<T> type, ComparatorFactory<T> comparatorFactory)
          Initialize the MapStoreProvider from an existing map + specified type.
MapStoreProvider(java.util.Map<java.lang.String,T> map, java.lang.Class<T> type, java.util.List<SortCriterion> defaultCriteria, ComparatorFactory<T> comparatorFactory)
          Initialize the MapStoreProvider from an existing map + specified type along with some sort criteria to be used when the client does not specify sorting.
 
Method Summary
 java.util.Map<java.lang.String,T> asMap()
          Get access to the contained data as a Map.
 void put(java.lang.String itemId, T value)
          Similar to Map.put(K, V) in adding items to a Store.
 void put(java.lang.String itemId, T value, boolean notify)
           
 java.lang.String toString()
           
 void unsubscribe(StoreChangeListener<T> listener)
          Remove the declaration of interest previously expressed.
 void update(java.util.List<ItemUpdate> changes)
          Make a series of updates to items in the store.
 Item viewItem(java.lang.String itemId, StoreChangeListener<T> listener)
          Similar to Map.get(java.lang.Object) in fetching items from a Store, and request to stay updated to changes in the region.
 MatchedItems viewRegion(StoreRegion region)
          Extract the data referred to by the given region.
 MatchedItems viewRegion(StoreRegion region, StoreChangeListener<T> listener)
          Extract the data referred to by the given region, and request to stay updated to changes in the region.
 
Methods inherited from class org.directwebremoting.datasync.AbstractStoreProvider
put, viewItem
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.directwebremoting.datasync.StoreProvider
put, viewItem
 

Constructor Detail

MapStoreProvider

public MapStoreProvider(java.util.Map<java.lang.String,T> datamap,
                        java.lang.Class<T> type)
Initialize the MapStoreProvider from an existing map + specified type.


MapStoreProvider

public MapStoreProvider(java.util.Map<java.lang.String,T> datamap,
                        java.lang.Class<T> type,
                        ComparatorFactory<T> comparatorFactory)
Initialize the MapStoreProvider from an existing map + specified type.


MapStoreProvider

public MapStoreProvider(java.lang.Class<T> type)
Initialize an empty MapStoreProvider from the specified type.


MapStoreProvider

public MapStoreProvider(java.util.Map<java.lang.String,T> map,
                        java.lang.Class<T> type,
                        java.util.List<SortCriterion> defaultCriteria,
                        ComparatorFactory<T> comparatorFactory)
Initialize the MapStoreProvider from an existing map + specified type along with some sort criteria to be used when the client does not specify sorting.

Method Detail

viewRegion

public MatchedItems viewRegion(StoreRegion region)
Description copied from interface: StoreProvider
Extract the data referred to by the given region.

Specified by:
viewRegion in interface StoreProvider<T>
Parameters:
region - A set of filter and sort criteria to restrict the fetched data

viewRegion

public MatchedItems viewRegion(StoreRegion region,
                               StoreChangeListener<T> listener)
Description copied from interface: StoreProvider
Extract the data referred to by the given region, and request to stay updated to changes in the region.

Specified by:
viewRegion in interface StoreProvider<T>
Parameters:
region - A set of filter and sort criteria to restrict the fetched data
listener - The listener to be notified of changes
Returns:
Data that matches the filtering specified in the region.

viewItem

public Item viewItem(java.lang.String itemId,
                     StoreChangeListener<T> listener)
Description copied from interface: StoreProvider
Similar to Map.get(java.lang.Object) in fetching items from a Store, and request to stay updated to changes in the region.

Specified by:
viewItem in interface StoreProvider<T>
Parameters:
itemId - The ID of the item to fetch
listener - The listener to be notified of changes
Returns:
The matched item, or null if it was not found

unsubscribe

public void unsubscribe(StoreChangeListener<T> listener)
Description copied from interface: StoreProvider
Remove the declaration of interest previously expressed.

Specified by:
unsubscribe in interface StoreProvider<T>
Parameters:
listener - The listener that should no longer be notified

put

public void put(java.lang.String itemId,
                T value)
Description copied from interface: StoreProvider
Similar to Map.put(K, V) in adding items to a Store. A value of null is equivalent to removing the item from the store.

Specified by:
put in interface StoreProvider<T>
Parameters:
itemId - The key (or some mapping) to it.
value - The new object to be added to the store

put

public void put(java.lang.String itemId,
                T value,
                boolean notify)

update

public void update(java.util.List<ItemUpdate> changes)
            throws java.lang.SecurityException
Description copied from interface: StoreProvider
Make a series of updates to items in the store.

Specified by:
update in interface StoreProvider<T>
Parameters:
changes - A list of item IDs along with the attributes to change and the values to change to
Throws:
java.lang.SecurityException

asMap

public java.util.Map<java.lang.String,T> asMap()
Get access to the contained data as a Map.

Returns:
An implementation of Map that affects this StoreProvider

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

Copyright 2008