donaldp     2002/11/15 22:44:47

  Modified:    info/src/java/org/apache/avalon/framework/tools/ant
                        MetaGenerateTask.java
  Log:
  Refactored code to make it easier to modify
  when adding more output targets
  
  Revision  Changes    Path
  1.5       +35 -22    
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/ant/MetaGenerateTask.java
  
  Index: MetaGenerateTask.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/ant/MetaGenerateTask.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MetaGenerateTask.java     16 Nov 2002 05:49:49 -0000      1.4
  +++ MetaGenerateTask.java     16 Nov 2002 06:44:47 -0000      1.5
  @@ -125,7 +125,7 @@
       /**
        * Output the metadata files.
        *
  -     * @throws java.io.IOException If a problem writing output
  +     * @throws IOException If a problem writing output
        */
       private void writeInfoMetaData() throws IOException
       {
  @@ -168,24 +168,12 @@
       private void writeInfo( final ComponentInfo info )
           throws IOException
       {
  -        InfoWriter writer;
  -        String extension;
  -        if( m_xmlOutput )
  -        {
  -            extension = ".xml";
  -            writer = c_xmlWriter;
  -        }
  -        else
  -        {
  -            extension = ".ser";
  -            writer = c_serWriter;
  -        }
  -
  -        final String filename = calcBaseFile( info ) + extension;
  +        final String fqn = info.getDescriptor().getImplementationKey();
  +        final String filename = getOutputFileForClass( fqn );
           final OutputStream outputStream = new FileOutputStream( filename );
           try
           {
  -            writer.writeComponentInfo( info, outputStream );
  +            getInfoWriter().writeComponentInfo( info, outputStream );
           }
           catch( final Exception e )
           {
  @@ -198,18 +186,43 @@
       }
   
       /**
  +     * Return the correct info writer depending on
  +     * what format the info will be output as
  +     *
  +     * @return the InfoWriter to output info with
  +     */
  +    private InfoWriter getInfoWriter()
  +    {
  +        if( m_xmlOutput )
  +        {
  +            return c_xmlWriter;
  +        }
  +        else
  +        {
  +            return c_serWriter;
  +        }
  +    }
  +
  +    /**
        * Determine the base file for specified {@link ComponentInfo}.
        *
  -     * @param info the info object that name is created for
  +     * @param classname the fully qualified name of file to generate
        * @return the base file for info
        * @throws IOException if unable to determine base file
        */
  -    private String calcBaseFile( final ComponentInfo info )
  +    private String getOutputFileForClass( final String classname )
           throws IOException
       {
  -        final String fqn = info.getDescriptor().getImplementationKey();
  -        final String filename =
  -            fqn.replace( '.', File.separatorChar ) + "-info";
  +        String filename =
  +            classname.replace( '.', File.separatorChar ) + "-info";
  +        if( m_xmlOutput )
  +        {
  +            filename += ".xml";
  +        }
  +        else
  +        {
  +            filename += ".ser";
  +        }
           return new File( m_destDir, filename ).getCanonicalPath();
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to