Spring Data MongoDB

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

java.lang.Object
  extended by org.springframework.data.mongodb.core.convert.CustomConversions

public class CustomConversions
extends Object

Value object to capture custom conversion. That is essentially a List of converters and some additional logic around them. The converters are pretty much builds up two sets of types which Mongo basic types #MONGO_TYPES can be converted into and from. These types will be considered simple ones (which means they neither need deeper inspection nor nested conversion. Thus the CustomConversions also act as factory for SimpleTypeHolder .

Author:
Oliver Gierke

Constructor Summary
CustomConversions(List<?> converters)
          Creates a new CustomConversions instance registering the given converters.
 
Method Summary
 Class<?> getCustomWriteTarget(Class<?> source)
          Returns the target type to convert to in case we have a custom conversion registered to convert the given source type into a Mongo native one.
 Class<?> getCustomWriteTarget(Class<?> source, Class<?> expectedTargetType)
          Returns the target type we can write an onject of the given source type to.
 SimpleTypeHolder getSimpleTypeHolder()
          Returns the underlying SimpleTypeHolder.
 boolean hasCustomReadTarget(Class<?> source, Class<?> expectedTargetType)
          Returns whether we have a custom conversion registered to read the given source into the given target type.
 boolean hasCustomWriteTarget(Class<?> source)
          Returns whether we have a custom conversion registered to write into a Mongo native type.
 boolean hasCustomWriteTarget(Class<?> source, Class<?> expectedTargetType)
          Returns whether we have a custom conversion registered to write an object of the given source type into an object of the given Mongo native target type.
 boolean isSimpleType(Class<?> type)
          Returns whether the given type is considered to be simple.
 void registerConvertersIn(GenericConversionService conversionService)
          Populates the given GenericConversionService with the convertes registered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CustomConversions

public CustomConversions(List<?> converters)
Creates a new CustomConversions instance registering the given converters.

Parameters:
converters -
Method Detail

getSimpleTypeHolder

public SimpleTypeHolder getSimpleTypeHolder()
Returns the underlying SimpleTypeHolder.

Returns:

isSimpleType

public boolean isSimpleType(Class<?> type)
Returns whether the given type is considered to be simple. That means it's either a general simple type or we have a writing Converter registered for a particular type.

Parameters:
type -
Returns:
See Also:
SimpleTypeHolder.isSimpleType(Class)

registerConvertersIn

public void registerConvertersIn(GenericConversionService conversionService)
Populates the given GenericConversionService with the convertes registered.

Parameters:
conversionService -

getCustomWriteTarget

public Class<?> getCustomWriteTarget(Class<?> source)
Returns the target type to convert to in case we have a custom conversion registered to convert the given source type into a Mongo native one.

Parameters:
source - must not be null
Returns:

getCustomWriteTarget

public Class<?> getCustomWriteTarget(Class<?> source,
                                     Class<?> expectedTargetType)
Returns the target type we can write an onject of the given source type to. The returned type might be a subclass oth the given expected type though. If expectedTargetType is null we will simply return the first target type matching or null if no conversion can be found.

Parameters:
source - must not be null
expectedTargetType -
Returns:

hasCustomWriteTarget

public boolean hasCustomWriteTarget(Class<?> source)
Returns whether we have a custom conversion registered to write into a Mongo native type. The returned type might be a subclass oth the given expected type though.

Parameters:
source - must not be null
Returns:

hasCustomWriteTarget

public boolean hasCustomWriteTarget(Class<?> source,
                                    Class<?> expectedTargetType)
Returns whether we have a custom conversion registered to write an object of the given source type into an object of the given Mongo native target type.

Parameters:
source - must not be null.
expectedTargetType -
Returns:

hasCustomReadTarget

public boolean hasCustomReadTarget(Class<?> source,
                                   Class<?> expectedTargetType)
Returns whether we have a custom conversion registered to read the given source into the given target type.

Parameters:
source - must not be null
expectedTargetType - must not be null
Returns:

Spring Data MongoDB

Copyright © 2011-2013-2013 SpringSource. All Rights Reserved.