Class TypeConverter
java.lang.Object
org.alfresco.service.cmr.repository.datatype.TypeConverter
- Direct Known Subclasses:
DefaultTypeConverter
Support for generic conversion between types.
Additional conversions may be added.
Direct conversion and two stage conversions via Number are supported. We do
not support conversion by any route at the moment
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceConversion interfaceprotected classSupport for chaining conversionsstatic classSupport for chaining conversions -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <F,T> void addConverter(Class<F> source, Class<T> destination, TypeConverter.Converter<F, T> converter) Add a converter to the list of those availablefinal <F,I, T> TypeConverter.Converter<F, T> addDynamicTwoStageConverter(Class<F> source, Class<I> intermediate, Class<T> destination) Add a dynamic two stage converterfinal booleanbooleanValue(Object value) Get the boolean value for the value object May have conversion failurefinal byteGet the byte value for the value object May have conversion failurefinal charGet the char value for the value object May have conversion failurefinal <T> TGeneral conversion method to Object types (note it cannot support conversion to primary types due the restrictions of reflection.final <T> Collection<T>convert(Class<T> c, Collection<?> values) General conversion method to convert collection contents to the specified type.final Objectconvert(DataTypeDefinition propertyType, Object value) General conversion method to Object types (note it cannot support conversion to primary types due the restrictions of reflection.final Collection<?>convert(DataTypeDefinition propertyType, Object[] values) General conversion method to convert collection contents to the specified type.final Collection<?>convert(DataTypeDefinition propertyType, Collection<?> values) General conversion method to convert collection contents to the specified type.final doubledoubleValue(Object value) Get the bollean value for the value object May have conversion failurefinal floatfloatValue(Object value) Get the bollean value for the value object May have conversion failurefinal <T> Collection<T>getCollection(Class<T> c, Object value) Get a collection for the passed value converted to the specified type<F,T> TypeConverter.Converter<F, T> getConverter(Class<F> source, Class<T> dest) Find a conversion for a specific Classfinal <T> TypeConverter.Converter<Object,T> getConverter(Object value, Class<T> dest) Find conversion for the specified object Note: Takes into account the class of the object and any interfaces it may also support.Map<Class<?>,Map<Class<?>, TypeConverter.Converter<?, ?>>> final intGet the int value for the value object May have conversion failurefinal booleanisMultiValued(Object value) Is the value multi valuedfinal longGet the long value for the value object May have conversion failurefinal shortshortValue(Object value) Get the short value for the value object May have conversion failurefinal intGet the number of values represented
-
Constructor Details
-
TypeConverter
public TypeConverter()
-
-
Method Details
-
convert
General conversion method to Object types (note it cannot support conversion to primary types due the restrictions of reflection. Use the static conversion methods to primitive types)- Parameters:
propertyType- - the target property typevalue- - the value to be converted- Returns:
- - the converted value as the correct type
-
convert
General conversion method to Object types (note it cannot support conversion to primary types due the restrictions of reflection. Use the static conversion methods to primitive types)- Type Parameters:
T- The target type for the result of the conversion- Parameters:
c- - a class for the target typevalue- - the value to be converted- Returns:
- - the converted value as the correct type
- Throws:
TypeConversionException- if the conversion cannot be performed
-
convert
General conversion method to convert collection contents to the specified type. Wrapper around the Collection version for arrays.- Parameters:
propertyType- - the target property typevalues- - the value to be converted- Returns:
- - the converted value as the correct type
- Throws:
DictionaryException- if the property type's registered java class is invalidTypeConversionException- if the conversion cannot be performed
-
convert
General conversion method to convert collection contents to the specified type.- Parameters:
propertyType- - the target property typevalues- - the value to be converted- Returns:
- - the converted value as the correct type
- Throws:
DictionaryException- if the property type's registered java class is invalidTypeConversionException- if the conversion cannot be performed
-
convert
General conversion method to convert collection contents to the specified type.- Type Parameters:
T- The target type for the result of the conversion- Parameters:
c- - a class for the target typevalues- - the collection to be converted- Returns:
- - the converted collection
- Throws:
TypeConversionException- if the conversion cannot be performed
-
booleanValue
Get the boolean value for the value object May have conversion failure- Parameters:
value- Object- Returns:
- boolean
-
charValue
Get the char value for the value object May have conversion failure- Parameters:
value- Object- Returns:
- char
-
byteValue
Get the byte value for the value object May have conversion failure- Parameters:
value- Object- Returns:
- byte
-
shortValue
Get the short value for the value object May have conversion failure- Parameters:
value- Object- Returns:
- short
-
intValue
Get the int value for the value object May have conversion failure- Parameters:
value- Object- Returns:
- int
-
longValue
Get the long value for the value object May have conversion failure- Parameters:
value- Object- Returns:
- long
-
floatValue
Get the bollean value for the value object May have conversion failure- Parameters:
value- Object- Returns:
- float
-
doubleValue
Get the bollean value for the value object May have conversion failure- Parameters:
value- Object- Returns:
- double
-
isMultiValued
Is the value multi valued- Parameters:
value- Object- Returns:
- true - if the underlyinf is a collection of values and not a singole value
-
size
Get the number of values represented- Parameters:
value- Object- Returns:
- 1 for normal values and the size of the collection for MVPs
-
getCollection
Get a collection for the passed value converted to the specified type- Parameters:
value- Object- Returns:
- Collection
-
addConverter
public final <F,T> void addConverter(Class<F> source, Class<T> destination, TypeConverter.Converter<F, T> converter) Add a converter to the list of those available -
addDynamicTwoStageConverter
public final <F,I, TypeConverter.Converter<F,T> T> addDynamicTwoStageConverter(Class<F> source, Class<I> intermediate, Class<T> destination) Add a dynamic two stage converter -
getConverter
Find conversion for the specified object Note: Takes into account the class of the object and any interfaces it may also support. -
getConverters
-
getConverter
Find a conversion for a specific Class- Returns:
- conversion
-