org.springframework.binding.convert.support
Class GenericConversionService

java.lang.Object
  extended by org.springframework.binding.convert.support.GenericConversionService
All Implemented Interfaces:
ConversionService
Direct Known Subclasses:
DefaultConversionService

public class GenericConversionService
extends java.lang.Object
implements ConversionService

Base implementation of a conversion service. Initially empty, e.g. no converters are registered by default.

Author:
Keith Donald

Constructor Summary
GenericConversionService()
           
 
Method Summary
 void addAlias(java.lang.String alias, java.lang.Class targetType)
          Add an alias for given target type.
 void addConverter(Converter converter)
          Add given converter to this conversion service.
 void addConverter(Converter converter, java.lang.String alias)
          Add given converter with an alias to the conversion service.
 void addConverters(Converter[] converters)
          Add all given converters.
 void addDefaultAlias(java.lang.Class targetType)
          Generate a conventions based alias for given target type.
protected  java.util.Map getAliasMap()
          Returns a map of known aliases.
 java.lang.Class getClassByAlias(java.lang.String alias)
          Return the class with the specified alias.
 ConversionExecutor getConversionExecutor(java.lang.Class sourceClass, java.lang.Class targetClass)
          Return a conversion executor command object capable of converting source objects of the specified sourceClass to instances of the targetClass.
 ConversionExecutor getConversionExecutorByTargetAlias(java.lang.Class sourceClass, java.lang.String alias)
          Return a conversion executor command object capable of converting source objects of the specified sourceClass to target objects of the type associated with the specified alias.
 ConversionExecutor[] getConversionExecutorsForSource(java.lang.Class sourceClass)
          Return all conversion executors capable of converting source objects of the the specified sourceClass.
 ConversionService getParent()
          Returns the parent of this conversion service.
protected  java.util.Map getSourceClassConverters()
          Returns an indexed map of converters.
 void setParent(ConversionService parent)
          Set the parent of this conversion service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericConversionService

public GenericConversionService()
Method Detail

getParent

public ConversionService getParent()
Returns the parent of this conversion service. Could be null.


setParent

public void setParent(ConversionService parent)
Set the parent of this conversion service. This is optional.


addConverter

public void addConverter(Converter converter)
Add given converter to this conversion service. If the converter is ConversionServiceAware, it will get the conversion service injected.


addConverters

public void addConverters(Converter[] converters)
Add all given converters. If the converters are ConversionServiceAware, they will get the conversion service injected.


addConverter

public void addConverter(Converter converter,
                         java.lang.String alias)
Add given converter with an alias to the conversion service. If the converter is ConversionServiceAware, it will get the conversion service injected.


addAlias

public void addAlias(java.lang.String alias,
                     java.lang.Class targetType)
Add an alias for given target type.


addDefaultAlias

public void addDefaultAlias(java.lang.Class targetType)
Generate a conventions based alias for given target type. For instance, "java.lang.Boolean" will get the "boolean" alias.


getConversionExecutor

public ConversionExecutor getConversionExecutor(java.lang.Class sourceClass,
                                                java.lang.Class targetClass)
                                         throws ConversionException
Description copied from interface: ConversionService
Return a conversion executor command object capable of converting source objects of the specified sourceClass to instances of the targetClass.

The returned ConversionExecutor is thread-safe and may safely be cached for use in client code.

Specified by:
getConversionExecutor in interface ConversionService
Parameters:
sourceClass - the source class to convert from
targetClass - the target class to convert to
Returns:
the executor that can execute instance conversion, never null
Throws:
ConversionException - an exception occured retrieving a converter for the source-to-target pair

getConversionExecutorByTargetAlias

public ConversionExecutor getConversionExecutorByTargetAlias(java.lang.Class sourceClass,
                                                             java.lang.String alias)
                                                      throws java.lang.IllegalArgumentException
Description copied from interface: ConversionService
Return a conversion executor command object capable of converting source objects of the specified sourceClass to target objects of the type associated with the specified alias.

Specified by:
getConversionExecutorByTargetAlias in interface ConversionService
Parameters:
sourceClass - the sourceClass
alias - the target alias
Returns:
the conversion executor, or null if the alias cannot be found
Throws:
java.lang.IllegalArgumentException

getConversionExecutorsForSource

public ConversionExecutor[] getConversionExecutorsForSource(java.lang.Class sourceClass)
Description copied from interface: ConversionService
Return all conversion executors capable of converting source objects of the the specified sourceClass.

Specified by:
getConversionExecutorsForSource in interface ConversionService
Parameters:
sourceClass - the source class to convert from
Returns:
the matching conversion executors

getClassByAlias

public java.lang.Class getClassByAlias(java.lang.String alias)
Description copied from interface: ConversionService
Return the class with the specified alias.

Specified by:
getClassByAlias in interface ConversionService
Parameters:
alias - the class alias
Returns:
the class, or null if not aliased

getSourceClassConverters

protected java.util.Map getSourceClassConverters()
Returns an indexed map of converters. Each entry key is a source class that can be converted from, and each entry value is a map of target classes that can be convertered to, ultimately mapping to a specific converter that can perform the source->target conversion.


getAliasMap

protected java.util.Map getAliasMap()
Returns a map of known aliases. Each entry key is a String alias and the associated value is either a target class or a converter.



Copyright © 2009 Spring Framework. All Rights Reserved.