org.spicefactory.pimento.metadata
Class PropertyMetadata

java.lang.Object
  extended by org.spicefactory.pimento.metadata.PropertyMetadata
All Implemented Interfaces:
Externalizable
Direct Known Subclasses:
EmbeddedPropertyMetadata

public class PropertyMetadata
extends Object
implements Externalizable

The metadata for a single property of a persistent entity.

Author:
Jens Halm

Constructor Summary
PropertyMetadata()
          Creates a new instance.
PropertyMetadata(String name, PropertyType type, Property property)
          Creates a new instance
 
Method Summary
 Object convertValue(Object value)
          Converts the value of this property so that it can be applied to an entity.
 String getName()
          Returns the name of the property.
 Object getValue(Object entity)
          Retrieve the value of this property for the specified entity.
 Object getValueForSnapshot(Object entity, IoContext context, FetchMode fetchMode)
          Reads the specified property from the given entity and returns it in a form suitable for inclusion in an entity snapshot.
 boolean isReadOnly()
          Checks whether this property was marked as read-only.
 boolean isRefreshable()
          Checks whether this property was marked as refreshable.
 Object prepareValueFromSnapshot(Object entity, Object value, IoContext context, boolean createChangeSet)
          Prepares the specified property value, performing all necessary conversions, but without actually applying it to the specified entity.
 void readExternal(DataInput input)
          Restores the content of this object from the DataInput instance.
 void setValue(Object entity, Object value)
          Sets the specified property value of the given entity.
 void writeExternal(DataOutput output)
          Saves the content of this object to the DataOutput instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyMetadata

public PropertyMetadata(String name,
                        PropertyType type,
                        Property property)
Creates a new instance

Parameters:
name - the name of the property
type - the type of the property
property - the reflection instance

PropertyMetadata

public PropertyMetadata()
Creates a new instance. The default constructor will only be used by the Cinnamon AMF decoder.

Method Detail

getName

public String getName()
Returns the name of the property.

Returns:
the name of the property

getValue

public Object getValue(Object entity)
Retrieve the value of this property for the specified entity.

Parameters:
entity - the entity to retrieve the value for
Returns:
the value of this property in the specified entity

convertValue

public Object convertValue(Object value)
Converts the value of this property so that it can be applied to an entity.

Parameters:
value - the value to convert
Returns:
the possibly converted value of the property

getValueForSnapshot

public Object getValueForSnapshot(Object entity,
                                  IoContext context,
                                  FetchMode fetchMode)
Reads the specified property from the given entity and returns it in a form suitable for inclusion in an entity snapshot.

Parameters:
entity - the entity to extract the property value from
context - the active IoContext
fetchMode - the fetch mode to use
Returns:
the current value of the property as a simple value, an entity snapshot or an instance of PropertyState

prepareValueFromSnapshot

public Object prepareValueFromSnapshot(Object entity,
                                       Object value,
                                       IoContext context,
                                       boolean createChangeSet)
Prepares the specified property value, performing all necessary conversions, but without actually applying it to the specified entity.

Parameters:
entity - the entity to prepare the property for
value - the new value for the property
context - the active IoContext
createChangeSet - whether a change set is being created
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)
Sets the specified property value of the given entity.

Parameters:
entity - the entity to set the property for
value - the new value for the property

isRefreshable

public boolean isRefreshable()
Checks whether this property was marked as refreshable.

Returns:
true if this property was marked as refreshable

isReadOnly

public boolean isReadOnly()
Checks whether this property was marked as read-only.

Returns:
true if this property was marked as read-only

readExternal

public void readExternal(DataInput input)
Description copied from interface: Externalizable
Restores the content of this object from the DataInput instance. Values must be read in the same sequence as they were written on the client side.

Specified by:
readExternal in interface Externalizable
Parameters:
input - the AMF3 data to read from

writeExternal

public void writeExternal(DataOutput output)
Description copied from interface: Externalizable
Saves the content of this object to the DataOutput instance.

Specified by:
writeExternal in interface Externalizable
Parameters:
output - the output to write to