donaldp     2002/06/12 23:40:29

  Modified:    container/src/java/org/apache/myrmidon/components/builder
                        ConvertingProjectBuilder.java
  Added:       container/src/java/org/apache/myrmidon/components/builder
                        ConvertingModelBuilder.java
  Log:
  Extract the ant1 -> myrmidon converting behaviour into ModelBuilder.
  
  Now all the ProjectBuilders are almost identical except for the ModelBuilder 
they use. We should probably try to reog so there is only one Project Builder 
and looks up specified ModelBuilder
  
  Revision  Changes    Path
  1.14      +4 -42     
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/builder/ConvertingProjectBuilder.java
  
  Index: ConvertingProjectBuilder.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/builder/ConvertingProjectBuilder.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ConvertingProjectBuilder.java     11 Jun 2002 05:30:47 -0000      1.13
  +++ ConvertingProjectBuilder.java     13 Jun 2002 06:40:29 -0000      1.14
  @@ -7,7 +7,7 @@
    */
   package org.apache.myrmidon.components.builder;
   
  -import org.apache.myrmidon.api.metadata.ModelElement;
  +import org.apache.myrmidon.interfaces.builder.ModelBuilder;
   
   /**
    * A simple ProjectBuilder, which programmatically converts an Ant1 Project
  @@ -23,46 +23,8 @@
   public class ConvertingProjectBuilder
       extends DefaultProjectBuilder
   {
  -    /**
  -     * Transforms the project model.  This implementation does nothing.
  -     */
  -    protected void transformProject( final ModelElement model )
  -        throws Exception
  +    protected ModelBuilder getModelBuilder( final String systemID )
       {
  -        // Check the version, if it's present, just use this config.
  -        // TODO: check for version < 2.0
  -        if( model.getAttribute( VERSION_ATTRIBUTE ) != null )
  -        {
  -            return;
  -        }
  -
  -        // Put a new version attribute.
  -        model.setAttribute( VERSION_ATTRIBUTE, "2.0" );
  -
  -        // Move all the non <target> elements (implicit target) to before
  -        // any <target> elements.
  -        final ModelElement[] children = model.getChildren();
  -        int insertPos = 0;
  -        for( int i = 0; i < children.length; i++ )
  -        {
  -            final ModelElement child = children[ i ];
  -
  -            if( ! child.getName().equals( "target" ) )
  -            {
  -                if( i > insertPos )
  -                {
  -                    model.removeChild( child );
  -                    model.addChild( insertPos, child );
  -                }
  -                insertPos++;
  -            }
  -        }
  -
  -        // Add an "import" task for the ant1 tasks - this is the first
  -        // Task in the implicit target.
  -        final ModelElement typelibDeclaration =
  -            new ModelElement( "import", model.getLocation() );
  -        typelibDeclaration.setAttribute( "library", "ant1" );
  -        model.addChild( 0, typelibDeclaration );
  +        return new ConvertingModelBuilder();
       }
   }
  
  
  
  1.1                  
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/builder/ConvertingModelBuilder.java
  
  Index: ConvertingModelBuilder.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.components.builder;
  
  import org.apache.myrmidon.api.metadata.ModelElement;
  import org.apache.myrmidon.api.metadata.ModelException;
  
  /**
   * A simple ModelBuilder, which programmatically converts an Ant1 Project
   * configuration into a Myrmidon one.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Darrell DeBoer</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/13 06:40:29 $
   *
   * @ant.type type="model-builder" name="xml"
   * @ant.type type="model-builder" name="ant"
   * @ant.type type="model-builder" name="default"
   */
  public class ConvertingModelBuilder
      extends DefaultModelBuilder
  {
      public ModelElement build( final String source )
          throws ModelException
      {
          final ModelElement model = super.build( source );
  
          // Check the version, if it's present, just use this config.
          // TODO: check for version < 2.0
          if( model.getAttribute( DefaultProjectBuilder.VERSION_ATTRIBUTE ) != 
null )
          {
              return model;
          }
  
          // Put a new version attribute.
          model.setAttribute( DefaultProjectBuilder.VERSION_ATTRIBUTE, "2.0" );
  
          // Move all the non <target> elements (implicit target) to before
          // any <target> elements.
          final ModelElement[] children = model.getChildren();
          int insertPos = 0;
          for( int i = 0; i < children.length; i++ )
          {
              final ModelElement child = children[ i ];
  
              if( !child.getName().equals( "target" ) )
              {
                  if( i > insertPos )
                  {
                      model.removeChild( child );
                      model.addChild( insertPos, child );
                  }
                  insertPos++;
              }
          }
  
          // Add an "import" task for the ant1 tasks - this is the first
          // Task in the implicit target.
          final ModelElement typelibDeclaration =
              new ModelElement( "import", model.getLocation() );
          typelibDeclaration.setAttribute( "library", "ant1" );
          model.addChild( 0, typelibDeclaration );
  
          return model;
      }
  }
  
  
  

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

Reply via email to