org.peaseplate.internal.service
Class DefaultConversionService

java.lang.Object
  extended by org.peaseplate.internal.service.DefaultConversionService
All Implemented Interfaces:
ConversionService

public class DefaultConversionService
extends java.lang.Object
implements ConversionService

The default implementation of the ConversionService

Author:
Manfred HANTSCHEL

Constructor Summary
DefaultConversionService()
           
 
Method Summary
 void add(java.lang.Class<? extends ConversionInitializer> initializerClass)
          Adds the conversion initializer specified by its class name to the service.
<SOURCE,TARGET>
void
add(java.lang.Class<SOURCE> sourceType, java.lang.Class<TARGET> targetType, Conversion<SOURCE,TARGET> conversion)
          Adds a conversion from the specified source type to the specified target type to the service.
 void add(java.lang.ClassLoader... classLoaders)
          Scans the specified class loaders for conversion service definitions.
 void add(ConversionInitializer initializer)
          Adds the conversions in the conversion initializer to the service.
<SOURCE,TARGET>
TARGET
convert(SOURCE value, java.lang.Class<TARGET> targetType)
          Converts the specified value to the specified target type.
<SOURCE,TARGET>
TARGET
convey(SOURCE value, java.lang.Class<TARGET> targetType)
          Converts the specified value to the specified target type.
protected
<SOURCE> ConversionCollection<SOURCE>
get(java.lang.Class<SOURCE> sourceType)
           
<SOURCE,TARGET>
boolean
isConvertable(java.lang.Class<SOURCE> sourceType, java.lang.Class<TARGET> targetType)
          Returns true if there is a conversion rule defined for the specified source type and the specified target type.
protected
<SOURCE,TARGET>
Conversion<SOURCE,TARGET>
resolve(java.lang.Class<SOURCE> sourceType, java.lang.Class<TARGET> targetType)
           
protected
<SOURCE> ConversionCollection<SOURCE>
resolveFromInterfaces(java.lang.Class<SOURCE> sourceType)
           
protected
<SOURCE> ConversionCollection<SOURCE>
resolveFromSuperType(java.lang.Class<SOURCE> sourceType)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultConversionService

public DefaultConversionService()
Method Detail

add

public void add(java.lang.ClassLoader... classLoaders)
         throws java.lang.IllegalArgumentException
Description copied from interface: ConversionService
Scans the specified class loaders for conversion service definitions. The definitions are located in a resource with the name "META-INF/services/org.peaseplate.service.ConversionService". The file contains class names of ConversionInitializers, one class name per line.

Specified by:
add in interface ConversionService
Parameters:
classLoaders - the class loaders
Throws:
java.lang.IllegalArgumentException - if a class could not be instantiated
See Also:
ConversionService.add(java.lang.ClassLoader[])

add

public void add(java.lang.Class<? extends ConversionInitializer> initializerClass)
         throws java.lang.IllegalArgumentException
Description copied from interface: ConversionService
Adds the conversion initializer specified by its class name to the service. The instance will be created immediately, passed to the add(ConversionInitializer) method and then thrown away.

Specified by:
add in interface ConversionService
Parameters:
initializerClass - the class
Throws:
java.lang.IllegalArgumentException - if the class could not be instantiated
See Also:
ConversionService.add(java.lang.Class)

add

public void add(ConversionInitializer initializer)
Description copied from interface: ConversionService
Adds the conversions in the conversion initializer to the service. The initializer itself will not be stored and can be thrown away.

Specified by:
add in interface ConversionService
Parameters:
initializer - the initializer
See Also:
ConversionService.add(org.peaseplate.service.ConversionInitializer)

add

public <SOURCE,TARGET> void add(java.lang.Class<SOURCE> sourceType,
                                java.lang.Class<TARGET> targetType,
                                Conversion<SOURCE,TARGET> conversion)
Description copied from interface: ConversionService
Adds a conversion from the specified source type to the specified target type to the service.

Specified by:
add in interface ConversionService
Type Parameters:
SOURCE - the source type
TARGET - the target type
Parameters:
sourceType - the source type
targetType - the target type
conversion - the conversion
See Also:
ConversionService.add(java.lang.Class, java.lang.Class, org.peaseplate.lang.Conversion)

get

protected <SOURCE> ConversionCollection<SOURCE> get(java.lang.Class<SOURCE> sourceType)

convey

public <SOURCE,TARGET> TARGET convey(SOURCE value,
                                     java.lang.Class<TARGET> targetType)
              throws ConversionException
Description copied from interface: ConversionService
Converts the specified value to the specified target type. If the value is null, it converts this value according to the conversion rule.

Specified by:
convey in interface ConversionService
Type Parameters:
SOURCE - the source type
TARGET - the target type
Parameters:
value - the value, may be null
targetType - the target type
Returns:
the converted value
Throws:
ConversionException - if something went wrong during converting
See Also:
ConversionService.convey(java.lang.Object, java.lang.Class)

convert

public <SOURCE,TARGET> TARGET convert(SOURCE value,
                                      java.lang.Class<TARGET> targetType)
               throws ConversionException
Description copied from interface: ConversionService
Converts the specified value to the specified target type. If the value is null, it returns null, and does not use the conversion rule.

Specified by:
convert in interface ConversionService
Type Parameters:
SOURCE - the source type
TARGET - the target type
Parameters:
value - the value, may be null
targetType - the target type
Returns:
the converted value
Throws:
ConversionException - if something went wrong during converting
See Also:
ConversionService.convert(java.lang.Object, java.lang.Class)

isConvertable

public <SOURCE,TARGET> boolean isConvertable(java.lang.Class<SOURCE> sourceType,
                                             java.lang.Class<TARGET> targetType)
Description copied from interface: ConversionService
Returns true if there is a conversion rule defined for the specified source type and the specified target type.

Specified by:
isConvertable in interface ConversionService
Type Parameters:
SOURCE - the source type
TARGET - the target type
Parameters:
sourceType - the source type
targetType - the target type
Returns:
true if conversion rule is defined
See Also:
ConversionService.isConvertable(java.lang.Class, java.lang.Class)

resolve

protected <SOURCE,TARGET> Conversion<SOURCE,TARGET> resolve(java.lang.Class<SOURCE> sourceType,
                                                            java.lang.Class<TARGET> targetType)

resolveFromSuperType

protected <SOURCE> ConversionCollection<SOURCE> resolveFromSuperType(java.lang.Class<SOURCE> sourceType)

resolveFromInterfaces

protected <SOURCE> ConversionCollection<SOURCE> resolveFromInterfaces(java.lang.Class<SOURCE> sourceType)


Copyright © 2008. All Rights Reserved.