org.apache.commons.convert
Class ConversionRegistry

java.lang.Object
  extended by org.apache.commons.convert.ConversionRegistry

public class ConversionRegistry
extends Object

ConversionRegistry manages the Conversion and ConversionFactory objects.

This class allows conversions to be added, removed and looked up. This implementation is fully synchronized.

 Converter converter = new Converter();
 converter.getRegistry().addDefaultConversions();
 converter.getRegistry().addConversion(new MyNewConversion());
 

Since:
1.0
Version:
$Id: ConversionRegistry.java 155441 2005-02-26 13:19:22Z dirkv $
Author:
Stephen Colebourne

Field Summary
protected  Map iConversions
          Map of from class to conversion
protected  ConversionFactory[] iFactories
          Array of conversion factories
protected  Object iFactoryLock
          Object to synchronize on for factories
 
Constructor Summary
protected ConversionRegistry()
          Restricted constructor, use Converter.
 
Method Summary
 void addConversion(Conversion conv)
          Adds a Conversion to the map of known conversions.
 void addConversionFactory(ConversionFactory factory)
          Adds a ConversionFactory to the set of known factories.
 void addDefaultConversions()
          Add the default set of conversions to the registry.
 Conversion getConversion(Object value, Class fromType, Class toType)
          Gets the conversion object that best matches the from and to types.
 String toString()
          Returns a string describing this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

iConversions

protected Map iConversions
Map of from class to conversion


iFactories

protected ConversionFactory[] iFactories
Array of conversion factories


iFactoryLock

protected final Object iFactoryLock
Object to synchronize on for factories

Constructor Detail

ConversionRegistry

protected ConversionRegistry()
Restricted constructor, use Converter.

Method Detail

addDefaultConversions

public void addDefaultConversions()
Add the default set of conversions to the registry.


addConversion

public void addConversion(Conversion conv)
Adds a Conversion to the map of known conversions. Any previous conversion for this from-to pair is replaced.

Parameters:
conv - the conversion to add

addConversionFactory

public void addConversionFactory(ConversionFactory factory)
Adds a ConversionFactory to the set of known factories. Any previous factory that matches by equals() is replaced.

Parameters:
factory - the factory to add

getConversion

public Conversion getConversion(Object value,
                                Class fromType,
                                Class toType)
Gets the conversion object that best matches the from and to types.

The lookup first examines the known conversions. If none is found, the factories are used to search for and create a conversion. If no suitable factory is found then null is returned.

Parameters:
value - the value that will be converted, read only and not to be stored
fromType - the type to convert from
toType - the type to convert to
Returns:
the best matching conversion, null if no match

toString

public String toString()
Returns a string describing this object.

Overrides:
toString in class Object
Returns:
a string describing this object


Copyright © 2003-2010 The Apache Software Foundation. All Rights Reserved.