org.alfresco.repo.domain.propval
Class DefaultPropertyTypeConverter

java.lang.Object
  extended by org.alfresco.repo.domain.propval.DefaultPropertyTypeConverter
All Implemented Interfaces:
PropertyTypeConverter

public class DefaultPropertyTypeConverter
extends java.lang.Object
implements PropertyTypeConverter

Default converter for handling data going to and from the persistence layer.

Properties are stored as a set of well-defined types defined by the enumeration PropertyValueEntity.PersistedType. Ultimately, data can be persisted as BLOB data, but must be the last resort.

Since:
3.2

Field Summary
protected static java.util.Map defaultPersistedTypesByClass
          An unmodifiable map of types and how they should be persisted
 
Constructor Summary
DefaultPropertyTypeConverter()
          Default constructor
 
Method Summary
protected  void addTypeMapping(java.lang.Class clazz, PropertyValueEntity.PersistedType targetType)
          Allow subclasses to add further type mappings specific to the implementation
 java.io.Serializable constructInstance(java.lang.String clazzName)
          Construct an instance of an object that was deemed to be PropertyValueEntity.PersistedType.CONSTRUCTABLE.
 java.lang.Object convert(java.lang.Class targetClass, java.io.Serializable value)
          Performs the conversion using DefaultTypeConverter but also adds special handling for enum types.
 PropertyValueEntity.PersistedType getPersistentType(java.io.Serializable value)
          When external to persisted type mappings are not obvious, the persistence framework, before persisting as PropertyValueEntity.PersistedType.SERIALIZABLE, will give the converter a chance to choose how the value must be persisted: PropertyValueEntity.PersistedType.LONG PropertyValueEntity.PersistedType.DOUBLE PropertyValueEntity.PersistedType.STRING PropertyValueEntity.PersistedType.SERIALIZABLE PropertyValueEntity.PersistedType.CONSTRUCTABLE The converter should return PropertyValueEntity.PersistedType.SERIALIZABLE if no further conversions are possible.
protected  boolean isConstructable(java.io.Serializable value)
          Determines if the value can be adequately recreated (to equality) by creating a new instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultPersistedTypesByClass

protected static final java.util.Map defaultPersistedTypesByClass
An unmodifiable map of types and how they should be persisted

Constructor Detail

DefaultPropertyTypeConverter

public DefaultPropertyTypeConverter()
Default constructor

Method Detail

addTypeMapping

protected void addTypeMapping(java.lang.Class clazz,
                              PropertyValueEntity.PersistedType targetType)
Allow subclasses to add further type mappings specific to the implementation

Parameters:
clazz - the class to be converted
targetType - the target persisted type

isConstructable

protected boolean isConstructable(java.io.Serializable value)
Determines if the value can be adequately recreated (to equality) by creating a new instance. For example, a java.util.HashMap is constructable provided that the map is empty.

Subclasses can override this to handle any well-known types, and in conjunction with DefaultPropertyTypeConverter.constructInstance(String), even choose to return true if it needs a non-default constructor.

Parameters:
value - the value to check
Returns:
Returns true if the value can be reconstructed by instantiation using a default constructor

constructInstance

public java.io.Serializable constructInstance(java.lang.String clazzName)
Construct an instance of an object that was deemed to be PropertyValueEntity.PersistedType.CONSTRUCTABLE.

Specified by:
constructInstance in interface PropertyTypeConverter
Parameters:
clazzName - the name of the class
Returns:
Returns the new instance

getPersistentType

public PropertyValueEntity.PersistedType getPersistentType(java.io.Serializable value)
When external to persisted type mappings are not obvious, the persistence framework, before persisting as PropertyValueEntity.PersistedType.SERIALIZABLE, will give the converter a chance to choose how the value must be persisted: The converter should return PropertyValueEntity.PersistedType.SERIALIZABLE if no further conversions are possible. Implicit in the return value is the converter's ability to do the conversion when required.

If the converter can fully reconstruct an equal instance using just the name of the value's class, then PropertyValueEntity.PersistedType.CONSTRUCTABLE can be used.

Specified by:
getPersistentType in interface PropertyTypeConverter
Parameters:
value - the value that does not have an obvious persistence slot
Returns:
Returns the type of persistence to use

convert

public java.lang.Object convert(java.lang.Class targetClass,
                                java.io.Serializable value)
Performs the conversion using DefaultTypeConverter but also adds special handling for enum types.

Specified by:
convert in interface PropertyTypeConverter
Parameters:
targetClass - the desired type to convert to
value - the value to convert
Returns:
Returns the persisted type and value to persist


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.