|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.convert.conversion.AbstractConversionFactory
public abstract class AbstractConversionFactory
Abstract base class for creating conversion factories.
This class is especially suited for creating factories as it minimises the effort required in the subclass.
To implement a conversion from a class and all of it subclasses, simply extend
this class and implement the convertValue(Object, Converter)
method.
Field Summary | |
---|---|
protected static Class |
STRING_CLASS
Useful constant for subclass constructors |
Constructor Summary | |
---|---|
protected |
AbstractConversionFactory(Class baseFromType,
Class toType)
Restricted constructor. |
Method Summary | |
---|---|
protected abstract Object |
convertValue(Object value,
Converter converter)
Convert the non-null value to another type. |
Class |
getBaseFromType()
The base type to convert from. |
Conversion |
getInstance(Object value,
Class fromType,
Class toType)
Create a new conversion object for the specified from and to types. |
protected int |
getMatchPercent()
Gets the percentage to return if a match occurs. |
int |
getMatchPercent(Object value,
Class fromType,
Class toType)
Checks if this factory matches the request conversion. |
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 AbstractConversionFactory(Class baseFromType, Class toType)
baseFromType
- the base of the class hierarchy to convert fromtoType
- the type to convert toMethod Detail |
---|
public int getMatchPercent(Object value, Class fromType, Class toType)
This implementation returns getMatchPercent()
if the specified
fromType
is the same as, or a subclass of, the stored
baseFromType
and the specified toType
matches
the stored toType
.
getMatchPercent
in interface ConversionFactory
value
- the value to be converted, read only, may be nullfromType
- the type to convert from, may be nulltoType
- the type to convert to, may be null
protected int getMatchPercent()
This implementation returns 60
.
Subclasses may wish to override and return a different value.
public Conversion getInstance(Object value, Class fromType, Class toType)
This implementation returns a Conversion
instance that
refers back to this class for its implementation of the actual conversion
via convertValue(Object, Converter)
.
getInstance
in interface ConversionFactory
value
- the value to be converted, read only, may be nullfromType
- the type to convert from, may be nulltoType
- the type to convert to, may be null
protected abstract Object convertValue(Object value, Converter converter) throws Exception
This method is implemented by subclases to perform the actual conversion.
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 getBaseFromType()
public Class getToType()
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |