org.alfresco.service.cmr.repository.datatype
Class TypeConverter

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

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
static interface TypeConverter.Converter
          Conversion interface
protected  class TypeConverter.DynamicTwoStageConverter
          Support for chaining conversions
static class TypeConverter.TwoStageConverter
          Support for chaining conversions
 
Constructor Summary
TypeConverter()
           
 
Method Summary
 void addConverter(java.lang.Class source, java.lang.Class destination, TypeConverter.Converter converter)
          Add a converter to the list of those available
 TypeConverter.Converter addDynamicTwoStageConverter(java.lang.Class source, java.lang.Class intermediate, java.lang.Class destination)
          Add a dynamic two stage converter
 boolean booleanValue(java.lang.Object value)
          Get the boolean value for the value object May have conversion failure
 byte byteValue(java.lang.Object value)
          Get the byte value for the value object May have conversion failure
 char charValue(java.lang.Object value)
          Get the char value for the value object May have conversion failure
 java.util.Collection convert(java.lang.Class c, java.util.Collection values)
          General conversion method to convert collection contents to the specified type.
 java.lang.Object convert(java.lang.Class c, 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.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.
 double doubleValue(java.lang.Object value)
          Get the bollean value for the value object May have conversion failure
 float floatValue(java.lang.Object value)
          Get the bollean value for the value object May have conversion failure
 java.util.Collection getCollection(java.lang.Class c, java.lang.Object value)
          Get a collection for the passed value converted to the specified type
 TypeConverter.Converter getConverter(java.lang.Class source, java.lang.Class dest)
          Find a conversion for a specific Class
 TypeConverter.Converter getConverter(java.lang.Object value, java.lang.Class 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 getConverters()
           
 int intValue(java.lang.Object value)
          Get the int value for the value object May have conversion failure
 boolean isMultiValued(java.lang.Object value)
          Is the value multi valued
 long longValue(java.lang.Object value)
          Get the long value for the value object May have conversion failure
 short shortValue(java.lang.Object value)
          Get the short value for the value object May have conversion failure
 int size(java.lang.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 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 type
value - - the value to be converted
Returns:
- the converted value as the correct type

convert

public final java.lang.Object convert(java.lang.Class 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)

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 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 type
value - - 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 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 type
value - - 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 java.util.Collection convert(java.lang.Class c,
                                          java.util.Collection values)
General conversion method to convert collection contents to the specified type.

Parameters:
c - - a class for the target type
value - - 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 -
Returns:

charValue

public final char charValue(java.lang.Object value)
Get the char value for the value object May have conversion failure

Parameters:
value -
Returns:

byteValue

public final byte byteValue(java.lang.Object value)
Get the byte value for the value object May have conversion failure

Parameters:
value -
Returns:

shortValue

public final short shortValue(java.lang.Object value)
Get the short value for the value object May have conversion failure

Parameters:
value -
Returns:

intValue

public final int intValue(java.lang.Object value)
Get the int value for the value object May have conversion failure

Parameters:
value -
Returns:

longValue

public final long longValue(java.lang.Object value)
Get the long value for the value object May have conversion failure

Parameters:
value -
Returns:

floatValue

public final float floatValue(java.lang.Object value)
Get the bollean value for the value object May have conversion failure

Parameters:
float -
Returns:

doubleValue

public final double doubleValue(java.lang.Object value)
Get the bollean value for the value object May have conversion failure

Parameters:
double -
Returns:

isMultiValued

public final boolean isMultiValued(java.lang.Object value)
Is the value multi valued

Parameters:
value -
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 -
Returns:
1 for normal values and the size of the collection for MVPs

getCollection

public final java.util.Collection getCollection(java.lang.Class c,
                                                java.lang.Object value)
Get a collection for the passed value converted to the specified type

Parameters:
c -
value -
Returns:

addConverter

public final void addConverter(java.lang.Class source,
                               java.lang.Class destination,
                               TypeConverter.Converter converter)
Add a converter to the list of those available

Parameters:
source -
destination -
converter -

addDynamicTwoStageConverter

public final TypeConverter.Converter addDynamicTwoStageConverter(java.lang.Class source,
                                                                 java.lang.Class intermediate,
                                                                 java.lang.Class destination)
Add a dynamic two stage converter

Parameters:
source -
intermediate -
destination -

getConverter

public final TypeConverter.Converter getConverter(java.lang.Object value,
                                                  java.lang.Class dest)
Find conversion for the specified object Note: Takes into account the class of the object and any interfaces it may also support.

Parameters:
source -
dest -
Returns:

getConverters

public java.util.Map getConverters()

getConverter

public TypeConverter.Converter getConverter(java.lang.Class source,
                                            java.lang.Class dest)
Find a conversion for a specific Class

Parameters:
source -
dest -
Returns:


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.