Spring Data Document

org.springframework.data.mongodb.core.convert
Class DefaultTypeMapper

java.lang.Object
  extended by org.springframework.data.mongodb.core.convert.DefaultTypeMapper
All Implemented Interfaces:
TypeMapper
Direct Known Subclasses:
ConfigurableTypeMapper

public class DefaultTypeMapper
extends Object
implements TypeMapper

Default implementation of TypeMapper allowing configuration of the key to lookup and store type information in DBObject. The key defaults to DEFAULT_TYPE_KEY. Actual type-to-String conversion and back is done in getTypeString(TypeInformation) or getTypeInformation(String) respectively.

Author:
Oliver Gierke

Field Summary
static String DEFAULT_TYPE_KEY
           
 
Constructor Summary
DefaultTypeMapper()
           
 
Method Summary
protected  org.springframework.data.util.TypeInformation<?> getTypeInformation(String value)
          Returns the TypeInformation that shall be used when the given String value is found as type hint.
protected  String getTypeString(org.springframework.data.util.TypeInformation<?> typeInformation)
          Turn the given type information into the String representation that shall be stored inside the DBObject.
 boolean isTypeKey(String key)
          Returns whether the given key is the key being used as type key.
 org.springframework.data.util.TypeInformation<?> readType(DBObject dbObject)
          Reads the TypeInformation from the given DBObject.
 void setTypeKey(String typeKey)
          Sets the key to store the type information under.
 void writeType(Class<?> type, DBObject dbObject)
          Writes type information for the given type into the given DBObject.
 void writeType(org.springframework.data.util.TypeInformation<?> info, DBObject dbObject)
          Writes type information for the given TypeInformation into the given DBObject.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TYPE_KEY

public static final String DEFAULT_TYPE_KEY
See Also:
Constant Field Values
Constructor Detail

DefaultTypeMapper

public DefaultTypeMapper()
Method Detail

setTypeKey

public void setTypeKey(String typeKey)
Sets the key to store the type information under. If set to null no type information will be stored in the document.

Parameters:
typeKey - the typeKey to set

isTypeKey

public boolean isTypeKey(String key)
Description copied from interface: TypeMapper
Returns whether the given key is the key being used as type key.

Specified by:
isTypeKey in interface TypeMapper
Returns:

readType

public org.springframework.data.util.TypeInformation<?> readType(DBObject dbObject)
Description copied from interface: TypeMapper
Reads the TypeInformation from the given DBObject.

Specified by:
readType in interface TypeMapper
Parameters:
dbObject - must not be null.
Returns:

writeType

public void writeType(Class<?> type,
                      DBObject dbObject)
Description copied from interface: TypeMapper
Writes type information for the given type into the given DBObject.

Specified by:
writeType in interface TypeMapper
Parameters:
type - must not be null.
dbObject - must not be null.

writeType

public void writeType(org.springframework.data.util.TypeInformation<?> info,
                      DBObject dbObject)
Description copied from interface: TypeMapper
Writes type information for the given TypeInformation into the given DBObject.

Specified by:
writeType in interface TypeMapper
Parameters:
info - must not be null.
dbObject - must not be null.

getTypeString

protected String getTypeString(org.springframework.data.util.TypeInformation<?> typeInformation)
Turn the given type information into the String representation that shall be stored inside the DBObject. If the returned String is null no type information will be stored. Default implementation simply returns the fully-qualified class name.

Parameters:
typeInformation - must not be null.
Returns:
the String representation to be stored or null if no type information shall be stored.

getTypeInformation

protected org.springframework.data.util.TypeInformation<?> getTypeInformation(String value)
Returns the TypeInformation that shall be used when the given String value is found as type hint. The default implementation will simply interpret the given value as fully-qualified class name and try to load the class. Will return null in case the given String is empty. Will not be called in case no String was found for the configured type key at all.

Parameters:
value - the type to load, must not be null.
Returns:
the type to be used for the given String representation or null if nothing found or the class cannot be loaded.

Spring Data Document

Copyright © 2011. All Rights Reserved.