|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.convert.conversion.AbstractConversion
public abstract class AbstractConversion
Abstract base class for conversion objects that provides basic features.
Most Conversion implementations will extend this class. It provides convenient implementations of the methods of the interface, and simplifies null-handling in the subclass.
To implement a conversion from a single class, simply extend this class and
implement the convertValue(Object, Converter)
method. To implement a
conversion from a class and its subclasses, use AbstractConversionFactory
.
Field Summary | |
---|---|
protected static Class |
STRING_CLASS
Useful constant for subclass constructors |
Constructor Summary | |
---|---|
protected |
AbstractConversion(Class fromType,
Class toType)
Constructor that stores the from and to types. |
Method Summary | |
---|---|
Object |
convert(Object value,
Converter converter)
Converts an object from one type to another. |
protected Object |
convertValue(Object value,
Converter converter)
Convert the specified non-null value to another type. |
Class |
getFromType()
The type to convert from. |
Class |
getToType()
The type to convert to. |
String |
toString()
Gets a suitable debugging string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final Class STRING_CLASS
Constructor Detail |
---|
protected AbstractConversion(Class fromType, Class toType)
fromType
- the type to convert fromtoType
- the type to convert toMethod Detail |
---|
public Object convert(Object value, Converter converter) throws Exception
This implementation delegates to convertValue
after handling null.
If the null-safe behaviour is undesired, override this method.
convert
in interface Conversion
value
- the input value to be converted, may be nullconverter
- the converter being used, not null
Exception
- if conversion fails, use ConversionException if creating
a new exception, otherwise just allow exceptions to be thrownprotected Object convertValue(Object value, Converter converter) throws Exception
value
- the input value to be converted, pre-checked to not be nullconverter
- the converter being used, not null
Exception
- if conversion fails, use ConversionException if creating
a new exception, otherwise just allow exceptions to be thrownpublic Class getFromType()
getFromType
in interface Conversion
public Class getToType()
getToType
in interface Conversion
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |