public class CustomConversions extends Object
List
of converters and some additional logic
around them. The converters build up two sets of types which store-specific basic 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
.Modifier and Type | Class and Description |
---|---|
protected static class |
CustomConversions.ConverterConfiguration
Value object holding the actual
CustomConversions.StoreConversions and custom converters configured for
registration. |
protected static class |
CustomConversions.ConverterRegistrationIntent
Value class tying together a
ConverterRegistration and its origin to allow fine
grained registration based on store supported types. |
static class |
CustomConversions.StoreConversions
Value type to capture store-specific extensions to the
CustomConversions . |
Constructor and Description |
---|
CustomConversions(CustomConversions.ConverterConfiguration converterConfiguration) |
CustomConversions(CustomConversions.StoreConversions storeConversions,
Collection<?> converters)
Creates a new
CustomConversions instance registering all given user defined converters and selecting
converters from CustomConversions.StoreConversions depending on
store simple types only considering those that either convert
to/from a store supported type. |
Modifier and Type | Method and Description |
---|---|
Optional<Class<?>> |
getCustomWriteTarget(Class<?> sourceType)
Returns the target type to convert to in case we have a custom conversion registered to convert the given source
type into a store native one.
|
Optional<Class<?>> |
getCustomWriteTarget(Class<?> sourceType,
Class<?> requestedTargetType)
Returns the target type we can read an inject of the given source type to.
|
<DV,SV,C extends PersistentProperty<C>,VCC extends ValueConversionContext<C>> |
getPropertyValueConverter(C property)
Delegate to obtain the
PropertyValueConverter for the given property from
PropertyValueConversions . |
SimpleTypeHolder |
getSimpleTypeHolder()
Returns the underlying
SimpleTypeHolder . |
boolean |
hasCustomReadTarget(Class<?> sourceType,
Class<?> targetType)
Returns whether we have a custom conversion registered to read the given source into the given target type.
|
boolean |
hasCustomWriteTarget(Class<?> sourceType)
Returns whether we have a custom conversion registered to read
sourceType into a native type. |
boolean |
hasCustomWriteTarget(Class<?> sourceType,
Class<?> targetType)
Returns whether we have a custom conversion registered to read an object of the given source type into an object of
the given native target type.
|
boolean |
hasPropertyValueConverter(PersistentProperty<?> property)
Delegate check if a
PropertyValueConverter for the given property is present via
PropertyValueConversions . |
boolean |
isSimpleType(Class<?> type)
Returns whether the given type is considered to be simple.
|
void |
registerConvertersIn(ConverterRegistry conversionService)
Populates the given
GenericConversionService with the converters registered. |
public CustomConversions(CustomConversions.ConverterConfiguration converterConfiguration)
converterConfiguration
- the CustomConversions.ConverterConfiguration
to apply.public CustomConversions(CustomConversions.StoreConversions storeConversions, Collection<?> converters)
CustomConversions
instance registering all given user defined converters and selecting
converters
from CustomConversions.StoreConversions
depending on
store simple types
only considering those that either convert
to/from a store supported type.storeConversions
- must not be null.converters
- must not be null.public SimpleTypeHolder getSimpleTypeHolder()
SimpleTypeHolder
.public boolean isSimpleType(Class<?> type)
Converter
registered for a particular type.type
- SimpleTypeHolder.isSimpleType(Class)
public void registerConvertersIn(ConverterRegistry conversionService)
GenericConversionService
with the converters registered.conversionService
- public boolean hasPropertyValueConverter(PersistentProperty<?> property)
PropertyValueConverter
for the given property is present via
PropertyValueConversions
.property
- must not be null.PropertyValueConverter
is available.PropertyValueConversions.hasValueConverter(PersistentProperty)
@Nullable public <DV,SV,C extends PersistentProperty<C>,VCC extends ValueConversionContext<C>> PropertyValueConverter<DV,SV,VCC> getPropertyValueConverter(C property)
PropertyValueConverter
for the given property from
PropertyValueConversions
.DV
- domain-specific typeSV
- store-native typeC
- conversion context typeproperty
- must not be null.PropertyValueConverter
or null if none available.PropertyValueConversions.getValueConverter(PersistentProperty)
public Optional<Class<?>> getCustomWriteTarget(Class<?> sourceType)
sourceType
- must not be nullpublic Optional<Class<?>> getCustomWriteTarget(Class<?> sourceType, Class<?> requestedTargetType)
requestedTargetType
is null we will simply return the first
target type matching or null if no conversion can be found.sourceType
- must not be nullrequestedTargetType
- must not be null.public boolean hasCustomWriteTarget(Class<?> sourceType)
sourceType
into a native type. The returned
type might be a subclass of the given expected type though.sourceType
- must not be nullpublic boolean hasCustomWriteTarget(Class<?> sourceType, Class<?> targetType)
sourceType
- must not be null.targetType
- must not be null.Copyright © 2011–2022 Pivotal Software, Inc.. All rights reserved.