Overview  Package   Class  Use  Tree  Deprecated  Index  Help 
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES    All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

org.alfresco.service.cmr.repository.datatype
Class TypeConverter
java.lang.Object
  org.alfresco.service.cmr.repository.datatype.TypeConverter
Direct Known Subclasses:
DefaultTypeConverter

public class TypeConverter
extends 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
static interface
TypeConverter.Converter<F,T>
          Conversion interface
protected class
TypeConverter.DynamicTwoStageConverter<F,I,T>
          Support for chaining conversions
static class
TypeConverter.TwoStageConverter<F,I,T>
          Support for chaining conversions
Constructor Summary
TypeConverter()
Method Summary
<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(Class<F> source, Class<I> intermediate, Class<T> destination)
          Add a dynamic two stage converter
boolean
booleanValue(Object value)
          Get the boolean value for the value object May have conversion failure
byte
byteValue(Object value)
          Get the byte value for the value object May have conversion failure
char
charValue(Object value)
          Get the char value for the value object May have conversion failure
<T> Collection<T>
convert(Class<T> c, Collection<?> values)
          General conversion method to convert collection contents to the specified type.
<T> T
convert(Class<T> c, Object value)
          General conversion method to Object types (note it cannot support conversion to primary types due the restrictions of reflection.
convert(DataTypeDefinition propertyType, Collection<?> values)
          General conversion method to convert collection contents to the specified type.
convert(DataTypeDefinition propertyType, Object value)
          General conversion method to Object types (note it cannot support conversion to primary types due the restrictions of reflection.
convert(DataTypeDefinition propertyType, Object[] values)
          General conversion method to convert collection contents to the specified type.
double
doubleValue(Object value)
          Get the bollean value for the value object May have conversion failure
float
floatValue(Object value)
          Get the bollean value for the value object May have conversion failure
<T> Collection<T>
getCollection(Class<T> c, Object value)
          Get a collection for the passed value converted to the specified type
getConverter(Class<F> source, Class<T> dest)
          Find a conversion for a specific Class
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.
getConverters()
int
intValue(Object value)
          Get the int value for the value object May have conversion failure
boolean
isMultiValued(Object value)
          Is the value multi valued
long
longValue(Object value)
          Get the long value for the value object May have conversion failure
short
shortValue(Object value)
          Get the short value for the value object May have conversion failure
int
size(Object value)
          Get the number of values represented
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail
TypeConverter
public TypeConverter()
Method Detail
convert
public final Object convert(DataTypeDefinition propertyType,
                            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 type
value - - the value to be converted
Returns:
- the converted value as the correct type

convert
public final <T> T convert(Class<T> c,
                           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 type
value - - the value to be converted
Returns:
- the converted value as the correct type
Throws:
TypeConversionException - if the conversion cannot be performed

convert
public final Collection<?> convert(DataTypeDefinition propertyType,
                                   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 type
values - - the value to be converted
Returns:
- the converted value as the correct type
Throws:
DictionaryException - if the property type's registered java class is invalid
TypeConversionException - if the conversion cannot be performed

convert
public final Collection<?> convert(DataTypeDefinition propertyType,
                                   Collection<?> values)
General conversion method to convert collection contents to the specified type.
Parameters:
propertyType - - the target property type
values - - the value to be converted
Returns:
- the converted value as the correct type
Throws:
DictionaryException - if the property type's registered java class is invalid
TypeConversionException - if the conversion cannot be performed

convert
public final <T> Collection<T> convert(Class<T> c,
                                       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 type
values - - the collection to be converted
Returns:
- the converted collection
Throws:
TypeConversionException - if the conversion cannot be performed

booleanValue
public final boolean booleanValue(Object value)
Get the boolean value for the value object May have conversion failure
Parameters:
value - Object
Returns:
boolean

charValue
public final char charValue(Object value)
Get the char value for the value object May have conversion failure
Parameters:
value - Object
Returns:
char

byteValue
public final byte byteValue(Object value)
Get the byte value for the value object May have conversion failure
Parameters:
value - Object
Returns:
byte

shortValue
public final short shortValue(Object value)
Get the short value for the value object May have conversion failure
Parameters:
value - Object
Returns:
short

intValue
public final int intValue(Object value)
Get the int value for the value object May have conversion failure
Parameters:
value - Object
Returns:
int

longValue
public final long longValue(Object value)
Get the long value for the value object May have conversion failure
Parameters:
value - Object
Returns:
long

floatValue
public final float floatValue(Object value)
Get the bollean value for the value object May have conversion failure
Parameters:
value - Object
Returns:
float

doubleValue
public final double doubleValue(Object value)
Get the bollean value for the value object May have conversion failure
Parameters:
value - Object
Returns:
double

isMultiValued
public final boolean isMultiValued(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(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> Collection<T> getCollection(Class<T> c,
                                             Object value)
Get a collection for the passed value converted to the specified type
Parameters:
c - Class
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
Type Parameters:
F - from
T - to
Parameters:
source - Class
destination - Class
converter - Converter

addDynamicTwoStageConverter
public final <F,I,T> TypeConverter.Converter<F,T> addDynamicTwoStageConverter(Class<F> source,
                                                                              Class<I> intermediate,
                                                                              Class<T> destination)
Add a dynamic two stage converter
Type Parameters:
F - from
I - intermediate
T - to
Parameters:
source - Class
intermediate - Class
destination - Class

getConverter
public final <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.
Type Parameters:
T - to
Parameters:
value - Object
dest - Class
Returns:
T

getConverters
public Map<Class<?>,Map<Class<?>,TypeConverter.Converter<?,?>>> getConverters()

getConverter
public <F,T> TypeConverter.Converter<F,T> getConverter(Class<F> source,
                                                       Class<T> dest)
Find a conversion for a specific Class
Type Parameters:
F - from
T - to
Parameters:
source - Class
dest - Class
Returns:
conversion

Overview  Package   Class  Use  Tree  Deprecated  Index  Help 
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES    All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005–2016 Alfresco Software. All rights reserved.

Java API documentation generated with DocFlex/Javadoc 1.6.1 using JavadocPro template set.