net.sourceforge.jparam.conversion.converters
Class AbstractConverter

java.lang.Object
  |
  +--net.sourceforge.jparam.conversion.converters.AbstractConverter
All Implemented Interfaces:
IConverter
Direct Known Subclasses:
AmbigousConverter, CreatorConverter, MethodConverter, ParentConverter, PathConverter

public abstract class AbstractConverter
extends java.lang.Object
implements IConverter

Author:
Ron_Sidi The base class for all converters, it implements all the basic funcionality of a converter.

Field Summary
(package private)  ScalarConversionWeight conversionWeight
           
(package private)  java.lang.Class sourceClass
          the source and target classes, and conversion weight, subclasses must initialize these in order to index the converter correctly
(package private)  java.lang.Class targetClass
           
 
Constructor Summary
AbstractConverter()
           
 
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
protected abstract  boolean converterEquals(IConverter o)
          Tests if this converter is equal to the given converter, all validity checks of source/target/weight and class instance are performed in the equal method, the derived class can perform all casts with no verification The check must verify equality, and not similarity meaning to converters performing the same conversion with the same weight are not necesarily equal, for instance two conversion paths from the same source to the same target but not through the same types, will cause ambiguity if not equal
 boolean equals(java.lang.Object obj)
          Verify all trivial tests, and let subclass to specific verification only
 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
 int hashCode()
           
protected abstract  java.lang.Object internalConvert(java.lang.Object o)
          Internal conversion method, all subclasses must implement the actual conversion logic here
 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:
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sourceforge.jparam.conversion.converters.IConverter
update
 

Field Detail

sourceClass

java.lang.Class sourceClass
the source and target classes, and conversion weight, subclasses must initialize these in order to index the converter correctly

targetClass

java.lang.Class targetClass

conversionWeight

ScalarConversionWeight conversionWeight
Constructor Detail

AbstractConverter

public AbstractConverter()
Method Detail

getTargetClass

public java.lang.Class getTargetClass()
Description copied from interface: IConverter
Return the Class object the target object will be instanceof
Specified by:
getTargetClass in interface IConverter
Following copied from interface: net.sourceforge.jparam.conversion.converters.IConverter
Returns:
expected target Class

getWeight

public ScalarConversionWeight getWeight()
Description copied from interface: IConverter
Return the scalar weight of this converter, if this is a concatenated converter, its weight should include the weight of all of its subconverters
Specified by:
getWeight in interface IConverter
Following copied from interface: net.sourceforge.jparam.conversion.converters.IConverter
Returns:
conversion weight

getSourceClass

public java.lang.Class getSourceClass()
Description copied from interface: IConverter
Return the Class object the converter expects the source to be instanceof
Specified by:
getSourceClass in interface IConverter
Following copied from interface: net.sourceforge.jparam.conversion.converters.IConverter
Returns:
expected source Class

convert

public java.lang.Object convert(java.lang.Object o)
                         throws JParamException
Description copied from interface: IConverter
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
Specified by:
convert in interface IConverter
Following copied from interface: net.sourceforge.jparam.conversion.converters.IConverter
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

internalConvert

protected abstract java.lang.Object internalConvert(java.lang.Object o)
                                             throws java.lang.Exception
Internal conversion method, all subclasses must implement the actual conversion logic here

No tests are needed since the given object is of the expected type

Parameters:
o - An object instanceof getSourceClass
Returns:
An object instanceof getTargetClass
Throws:
java.lang.Exception - If there was an error performing the conversion

toString

public java.lang.String toString()
Description copied from interface: IConverter
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)
 

Specified by:
toString in interface IConverter
Overrides:
toString in class java.lang.Object
Following copied from interface: net.sourceforge.jparam.conversion.converters.IConverter
Returns:
an informative representation of the conversion, used for debugging

toConversionString

public java.lang.String toConversionString()
Description copied from interface: IConverter
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

Specified by:
toConversionString in interface IConverter
Following copied from interface: net.sourceforge.jparam.conversion.converters.IConverter
Returns:
a String representation of the conversion process

converterEquals

protected abstract boolean converterEquals(IConverter o)
Tests if this converter is equal to the given converter, all validity checks of source/target/weight and class instance are performed in the equal method, the derived class can perform all casts with no verification The check must verify equality, and not similarity meaning to converters performing the same conversion with the same weight are not necesarily equal, for instance two conversion paths from the same source to the same target but not through the same types, will cause ambiguity if not equal
Parameters:
o - A converter to check for equality
Returns:
true if the converters are equal

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Verify all trivial tests, and let subclass to specific verification only
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)


Copyright © 2004 SourceForge. All Rights Reserved.