org.spicefactory.pimento.property
Class EmbeddedHandler

java.lang.Object
  extended by org.spicefactory.pimento.property.EmbeddedHandler
All Implemented Interfaces:
PropertyHandler

public class EmbeddedHandler
extends Object
implements PropertyHandler

Manages an embedded type.

Author:
Jens Halm

Constructor Summary
EmbeddedHandler(Embeddable embeddable)
          Creates a new instance.
 
Method Summary
 Embeddable getEmbeddable()
          Returns the embeddable metamodel.
 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.
 void init(Property property)
           
 Object prepareValueFromSnapshot(Object entity, Object value, SnapshotDecoder decoder, EntityState state)
          Prepares the specified property value, performing all necessary conversions, but without actually applying it to the specified entity.
 void setEmbeddable(Embeddable embeddable)
          Sets the embeddable metamodel.
 void setValue(Object entity, Object value)
          Sets the specified property value of the given entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmbeddedHandler

public EmbeddedHandler(Embeddable embeddable)
Creates a new instance.

Parameters:
embeddable - the embeddable metamodel
Method Detail

getEmbeddable

public Embeddable getEmbeddable()
Returns the embeddable metamodel.

Returns:
the embeddable metamodel

setEmbeddable

public void setEmbeddable(Embeddable embeddable)
Sets the embeddable metamodel.

Parameters:
embeddable - the embeddable metamodel

init

public void init(Property property)
Specified by:
init in interface PropertyHandler

prepareValueFromSnapshot

public Object prepareValueFromSnapshot(Object entity,
                                       Object value,
                                       SnapshotDecoder decoder,
                                       EntityState state)
Description copied from interface: PropertyHandler
Prepares the specified property value, performing all necessary conversions, but without actually applying it to the specified entity. The prepared values will be collected in a PropertyChangeSet instance which gets passed to any configured interceptors before the property is applied with the setValue method of this class.

Specified by:
prepareValueFromSnapshot in interface PropertyHandler
Parameters:
entity - the entity to prepare the property for
value - the new value for the property
decoder - the decoder to use for decoding associations
state - the state of the entity
Returns:
the (possibly converted) value of the property as it will later be applied to the entity.

setValue

public void setValue(Object entity,
                     Object value)
Description copied from interface: PropertyHandler
Sets the specified property value of the given entity. This method can safely assume that the value has been property prepared (possibly converted) with the prepareValueFromSnapshot method of this class before this method gets invoked.

Specified by:
setValue in interface PropertyHandler
Parameters:
entity - the entity to set the property for
value - the new value for the property

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.

Specified by:
getValueForSnapshot in interface PropertyHandler
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