Class TypeConverter
- java.lang.Object
-
- org.alfresco.service.cmr.repository.datatype.TypeConverter
-
- Direct Known Subclasses:
DefaultTypeConverter
@AlfrescoPublicApi public class TypeConverter extends java.lang.Object
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 Classes Modifier and Type Class Description static interface
TypeConverter.Converter<F,T>
Conversion interfaceprotected class
TypeConverter.DynamicTwoStageConverter<F,I,T>
Support for chaining conversionsstatic class
TypeConverter.TwoStageConverter<F,I,T>
Support for chaining conversions
-
Constructor Summary
Constructors Constructor Description TypeConverter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <F,T>
voidaddConverter(java.lang.Class<F> source, java.lang.Class<T> destination, TypeConverter.Converter<F,T> converter)
Add a converter to the list of those available<F,I,T>
TypeConverter.Converter<F,T>addDynamicTwoStageConverter(java.lang.Class<F> source, java.lang.Class<I> intermediate, java.lang.Class<T> destination)
Add a dynamic two stage converterboolean
booleanValue(java.lang.Object value)
Get the boolean value for the value object May have conversion failurebyte
byteValue(java.lang.Object value)
Get the byte value for the value object May have conversion failurechar
charValue(java.lang.Object value)
Get the char value for the value object May have conversion failure<T> T
convert(java.lang.Class<T> c, java.lang.Object value)
General conversion method to Object types (note it cannot support conversion to primary types due the restrictions of reflection.<T> java.util.Collection<T>
convert(java.lang.Class<T> c, java.util.Collection<?> values)
General conversion method to convert collection contents to the specified type.java.lang.Object
convert(DataTypeDefinition propertyType, java.lang.Object value)
General conversion method to Object types (note it cannot support conversion to primary types due the restrictions of reflection.java.util.Collection<?>
convert(DataTypeDefinition propertyType, java.lang.Object[] values)
General conversion method to convert collection contents to the specified type.java.util.Collection<?>
convert(DataTypeDefinition propertyType, java.util.Collection<?> values)
General conversion method to convert collection contents to the specified type.double
doubleValue(java.lang.Object value)
Get the bollean value for the value object May have conversion failurefloat
floatValue(java.lang.Object value)
Get the bollean value for the value object May have conversion failure<T> java.util.Collection<T>
getCollection(java.lang.Class<T> c, java.lang.Object value)
Get a collection for the passed value converted to the specified type<F,T>
TypeConverter.Converter<F,T>getConverter(java.lang.Class<F> source, java.lang.Class<T> dest)
Find a conversion for a specific Class<T> TypeConverter.Converter<java.lang.Object,T>
getConverter(java.lang.Object value, java.lang.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.java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.Class<?>,TypeConverter.Converter<?,?>>>
getConverters()
int
intValue(java.lang.Object value)
Get the int value for the value object May have conversion failureboolean
isMultiValued(java.lang.Object value)
Is the value multi valuedlong
longValue(java.lang.Object value)
Get the long value for the value object May have conversion failureshort
shortValue(java.lang.Object value)
Get the short value for the value object May have conversion failureint
size(java.lang.Object value)
Get the number of values represented
-
-
-
Method Detail
-
convert
public final java.lang.Object convert(DataTypeDefinition propertyType, java.lang.Object value)
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
public final <T> T convert(java.lang.Class<T> c, java.lang.Object value)
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
public final java.util.Collection<?> convert(DataTypeDefinition propertyType, java.lang.Object[] values)
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
public final java.util.Collection<?> convert(DataTypeDefinition propertyType, java.util.Collection<?> values)
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
public final <T> java.util.Collection<T> convert(java.lang.Class<T> c, java.util.Collection<?> values)
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
public final boolean booleanValue(java.lang.Object value)
Get the boolean value for the value object May have conversion failure- Parameters:
value
- Object- Returns:
- boolean
-
charValue
public final char charValue(java.lang.Object value)
Get the char value for the value object May have conversion failure- Parameters:
value
- Object- Returns:
- char
-
byteValue
public final byte byteValue(java.lang.Object value)
Get the byte value for the value object May have conversion failure- Parameters:
value
- Object- Returns:
- byte
-
shortValue
public final short shortValue(java.lang.Object value)
Get the short value for the value object May have conversion failure- Parameters:
value
- Object- Returns:
- short
-
intValue
public final int intValue(java.lang.Object value)
Get the int value for the value object May have conversion failure- Parameters:
value
- Object- Returns:
- int
-
longValue
public final long longValue(java.lang.Object value)
Get the long value for the value object May have conversion failure- Parameters:
value
- Object- Returns:
- long
-
floatValue
public final float floatValue(java.lang.Object value)
Get the bollean value for the value object May have conversion failure- Parameters:
value
- Object- Returns:
- float
-
doubleValue
public final double doubleValue(java.lang.Object value)
Get the bollean value for the value object May have conversion failure- Parameters:
value
- Object- Returns:
- double
-
isMultiValued
public final boolean isMultiValued(java.lang.Object value)
Is the value multi valued- Parameters:
value
- Object- Returns:
- true - if the underlyinf is a collection of values and not a singole value
-
size
public final int size(java.lang.Object value)
Get the number of values represented- Parameters:
value
- Object- Returns:
- 1 for normal values and the size of the collection for MVPs
-
getCollection
public final <T> java.util.Collection<T> getCollection(java.lang.Class<T> c, java.lang.Object value)
Get a collection for the passed value converted to the specified type- Parameters:
value
- Object- Returns:
- Collection
-
addConverter
public final <F,T> void addConverter(java.lang.Class<F> source, java.lang.Class<T> destination, TypeConverter.Converter<F,T> converter)
Add a converter to the list of those available
-
addDynamicTwoStageConverter
public final <F,I,T> TypeConverter.Converter<F,T> addDynamicTwoStageConverter(java.lang.Class<F> source, java.lang.Class<I> intermediate, java.lang.Class<T> destination)
Add a dynamic two stage converter
-
getConverter
public final <T> TypeConverter.Converter<java.lang.Object,T> getConverter(java.lang.Object value, java.lang.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.
-
getConverters
public java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.Class<?>,TypeConverter.Converter<?,?>>> getConverters()
-
getConverter
public <F,T> TypeConverter.Converter<F,T> getConverter(java.lang.Class<F> source, java.lang.Class<T> dest)
Find a conversion for a specific Class- Returns:
- conversion
-
-