net.sourceforge.jparam.conversion.converters
Interface IConverter

All Known Implementing Classes:
AbstractConverter

public interface IConverter

This interface is used to convert an object between two given class

Each converter can convert ONLY object of the source class (or subclasses, to support chaining since there are no static types in Java) to the target class

Author:
Ron_Sidi

Method Summary
 java.lang.Object convert(java.lang.Object o)
          Perform the conversion of the given object to the expected target class, if for some reason the conversion fails (or if the source/target objects do not match the expected classes), an exception should be thrown
 java.lang.Class getSourceClass()
          Return the Class object the converter expects the source to be instanceof
 java.lang.Class getTargetClass()
          Return the Class object the target object will be instanceof
 ScalarConversionWeight getWeight()
          Return the scalar weight of this converter, if this is a concatenated converter, its weight should include the weight of all of its subconverters
 java.lang.String toConversionString()
          Return a string representation of the conversion process only, no additional data, this output will be used when ambiguity is detected in order to give the user meaningfull error messages An ambiguity output would be:
 java.lang.String toString()
          A more programatically meaningfull description of the conversion, it should show at least the weight of the conversion and possibly more data for example: A path conversion string could look like:
 IConverter update(IConverter updatedConverter)
          This method is used to inform the converter of a new available converter if the new converter affects in any way on the current converter, a new converter that reflects the change should be return.
 

Method Detail

getTargetClass

public java.lang.Class getTargetClass()
Return the Class object the target object will be instanceof
Returns:
expected target Class

getSourceClass

public java.lang.Class getSourceClass()
Return the Class object the converter expects the source to be instanceof
Returns:
expected source Class

convert

public java.lang.Object convert(java.lang.Object o)
                         throws JParamException
Perform the conversion of the given object to the expected target class, if for some reason the conversion fails (or if the source/target objects do not match the expected classes), an exception should be thrown
Parameters:
o - the source object (should be instance of getSourceClass)
Returns:
the converted object (instance of getTargetClass)
Throws:
JParamException - if for some reason the conversion failed

getWeight

public ScalarConversionWeight getWeight()
Return the scalar weight of this converter, if this is a concatenated converter, its weight should include the weight of all of its subconverters
Returns:
conversion weight

toConversionString

public java.lang.String toConversionString()
Return a string representation of the conversion process only, no additional data, this output will be used when ambiguity is detected in order to give the user meaningfull error messages An ambiguity output would be:

 		duckling -> duck -> short -> int 
 		duckling -> duck -> char -> int
 

Note that there is no additional text or info here

Returns:
a String representation of the conversion process

toString

public java.lang.String toString()
A more programatically meaningfull description of the conversion, it should show at least the weight of the conversion and possibly more data for example: A path conversion string could look like:

 		duck --> archduck --> ducky(USER + TO_PARENT)
 

An ambigous conversion could look like:

 		AMBIGOUS( 
 			duck -> short -> double
 			duck -> uchar -> double)(USER + PROMOTION)
 

Overrides:
toString in class java.lang.Object
Returns:
an informative representation of the conversion, used for debugging

update

public IConverter update(IConverter updatedConverter)
This method is used to inform the converter of a new available converter if the new converter affects in any way on the current converter, a new converter that reflects the change should be return. This will have no affect on atomic converters, but might affect compound converters (it could affect their weight, and could make them ambigous or change an ambigous converter to a valid one)
Parameters:
updatedConverter - the newly supported converter
Returns:
IConverter this if nothing changed or a new converter representing the change


Copyright © 2004 SourceForge. All Rights Reserved.