You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by do...@apache.org on 2001/12/29 22:07:18 UTC
cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter DefaultMasterConverter.java
donaldp 01/12/29 13:07:18
Modified: proposal/myrmidon/src/java/org/apache/myrmidon/components/converter
DefaultMasterConverter.java
Log:
Made the MasterConverter search through the destination classes hierarchy to find a match for converter. This will allow a converter that converts to a specific superclass also work for all subclasses.
Revision Changes Path
1.10 +33 -13 jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultMasterConverter.java
Index: DefaultMasterConverter.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultMasterConverter.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DefaultMasterConverter.java 23 Dec 2001 06:25:35 -0000 1.9
+++ DefaultMasterConverter.java 29 Dec 2001 21:07:18 -0000 1.10
@@ -71,7 +71,9 @@
* @return the converted object
* @exception Exception if an error occurs
*/
- public Object convert( Class destination, final Object original, final Context context )
+ public Object convert( final Class destination,
+ final Object original,
+ final Context context )
throws ConverterException
{
final Class originalClass = original.getClass();
@@ -90,18 +92,8 @@
getLogger().debug( message );
}
- //TODO: Start searching inheritance hierarchy for converter
- final String name = m_registry.getConverterName( originalClass.getName(),
- destination.getName() );
-
- if( null == name )
- {
- final String message =
- REZ.getString( "no-converter.notice",
- originalClass.getName(),
- destination.getName() );
- throw new ConverterException( message );
- }
+ //Searching inheritance hierarchy for converter
+ final String name = getConverterName( originalClass, destination );
try
{
@@ -121,5 +113,33 @@
final String message = REZ.getString( "bad-typemanager.error" );
throw new ConverterException( message, te );
}
+ }
+
+ private String getConverterName( final Class originalClass,
+ final Class destination )
+ throws ConverterException
+ {
+ Class clazz = destination;
+
+ //TODO: Maybe we should search the source classes hierarchy aswell
+ final Class terminator = Object.class;
+ while( terminator != clazz )
+ {
+ final String name =
+ m_registry.getConverterName( originalClass.getName(),
+ clazz.getName() );
+ if( name != null )
+ {
+ return name;
+ }
+
+ clazz = clazz.getSuperclass();
+ }
+
+ final String message =
+ REZ.getString( "no-converter.notice",
+ originalClass.getName(),
+ destination.getName() );
+ throw new ConverterException( message );
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>