org.spicefactory.pimento.property
Class AbstractCollectionHandler

java.lang.Object
  extended by org.spicefactory.pimento.property.AbstractAssociationHandler
      extended by org.spicefactory.pimento.property.AbstractCollectionHandler
All Implemented Interfaces:
PropertyHandler
Direct Known Subclasses:
AbstractUnindexedCollectionHandler, ListHandler

public abstract class AbstractCollectionHandler
extends AbstractAssociationHandler

Base class for property handlers that manage collections.

Author:
Jens Halm

Field Summary
 
Fields inherited from class org.spicefactory.pimento.property.AbstractAssociationHandler
property
 
Constructor Summary
AbstractCollectionHandler()
           
 
Method Summary
protected
<T> void
addSupportedInterface(Class<T> collectionInterface, Class<? extends T> implementation)
          Adds an interface type supported by this property handler.
protected  Object createCollection()
          Creates an instance for the collection type of the managed property.
protected  Object createFullCollectionFromSnapshots(List<EntitySnapshot> snapshots, SnapshotDecoder decoder)
          Creates and returns a collection of entities from the specified list of snapshots.
protected  Collection<?> getCollection(Object value)
          Returns the collection that should be used for creating a collection snapshot.
 Object getValueForSnapshot(Object entity, SnapshotEncoder encoder, FetchMode fetchMode)
          Reads the specified property from the given entity and returns it in a form suitable for inclusion in an entity snapshot.
 
Methods inherited from class org.spicefactory.pimento.property.AbstractAssociationHandler
entityForInstance, entityForSnapshot, equals, getAssociationModel, getFetchPlan, init, setAssociationModel, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.spicefactory.pimento.property.PropertyHandler
prepareValueFromSnapshot
 

Constructor Detail

AbstractCollectionHandler

public AbstractCollectionHandler()
Method Detail

addSupportedInterface

protected <T> void addSupportedInterface(Class<T> collectionInterface,
                                         Class<? extends T> implementation)
Adds an interface type supported by this property handler.

Parameters:
collectionInterface - the supported interface type to add
implementation - the default implementation to use when creating instances of the supported type

getValueForSnapshot

public Object getValueForSnapshot(Object entity,
                                  SnapshotEncoder encoder,
                                  FetchMode fetchMode)
Description copied from interface: PropertyHandler
Reads the specified property from the given entity and returns it in a form suitable for inclusion in an entity snapshot. For associations this means that non-null values should be converted to snapshots themselves, using the provided SnapshotEncoder instance. Simple values could be returned as-is in most cases.

Parameters:
entity - the entity to extract the property value from
encoder - the encoder to use for encoding associations
fetchMode - the fetchMode to use if the property type is an association
Returns:
the current value of the property as a simple value, an entity snapshot or an instance of PropertyState

createFullCollectionFromSnapshots

protected Object createFullCollectionFromSnapshots(List<EntitySnapshot> snapshots,
                                                   SnapshotDecoder decoder)
Creates and returns a collection of entities from the specified list of snapshots. The type of the returned collection may vary between different subclasses.

Parameters:
snapshots - the list of snapshots to assemble to entities
decoder - the decoder to use for the specified snapshots
Returns:
a collection of entities created from the specified list of snapshots

createCollection

protected Object createCollection()
Creates an instance for the collection type of the managed property. The type might be an interface type, in that case it should be mapped to the default implementation as specified with addSupportedInterface.

Returns:
an instance for the collection type of the managed property

getCollection

protected Collection<?> getCollection(Object value)
Returns the collection that should be used for creating a collection snapshot.

Parameters:
value - the original collection value
Returns:
the collection value the snapshot should be created from.