ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter DefaultMasterConverter.java
Date Sat, 29 Dec 2001 21:07:18 GMT
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:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message