User: rinkrank
  Date: 02/04/27 16:54:32

  Modified:    core/src/xdoclet Tag: MODULE_REFACTORING_BRANCH
                        DocletTask.java GenerationManager.java
  Log:
  Refactored to use new dynamic subelements from Ant 1.5
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.39.2.1  +133 -126  xdoclet/core/src/xdoclet/DocletTask.java
  
  Index: DocletTask.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/DocletTask.java,v
  retrieving revision 1.39
  retrieving revision 1.39.2.1
  diff -u -w -r1.39 -r1.39.2.1
  --- DocletTask.java   21 Apr 2002 20:40:14 -0000      1.39
  +++ DocletTask.java   27 Apr 2002 23:54:31 -0000      1.39.2.1
  @@ -4,6 +4,7 @@
    */
   package xdoclet;
   
  +import org.apache.tools.ant.DynamicConfigurator;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.DirectoryScanner;
   import org.apache.tools.ant.Project;
  @@ -13,16 +14,20 @@
   import xdoclet.util.XmlValidator;
   import xdoclet.util.Log;
   import xdoclet.template.TemplateException;
  +import xdoclet.template.TemplateTagHandler;
  +import xdoclet.template.TemplateEngine;
  +import xdoclet.loader.*;
   
   import xjavadoc.SourceSet;
   import xjavadoc.XJavaDoc;
   import xjavadoc.ant.XJavadocTask;
   
   import java.io.*;
  +import java.util.Map;
   import java.util.HashMap;
   import java.util.List;
   import java.util.ArrayList;
  -import java.util.Vector;
  +import java.util.Iterator;
   
   /**
    * A base class for all Tasks. It can also be used directly, useful for the case
  @@ -32,10 +37,11 @@
    * @author    Ara Abrahamian ([EMAIL PROTECTED])
    * @author    <a href="mailto:[EMAIL PROTECTED]";>Aslak Helles�y</a>
    * @created   June 19, 2001
  - * @version   $Revision: 1.39 $
  + * @version   $Revision: 1.39.2.1 $
    */
  -public class DocletTask extends XJavadocTask
  +public class DocletTask extends XJavadocTask implements DynamicConfigurator
   {
  +
        // ant will replace the tag with the version propperty specified in build.xml
        /**
         * @todo-javadoc   Describe the field
  @@ -49,18 +55,62 @@
        private final static File DEFAULT_TMP_FILE = new File( System.getProperty( 
"java.io.tmpdir" ), _fileName );
   
        private static File _tmpFile = DEFAULT_TMP_FILE;
  +     private static List modules = null;
        protected transient DocletContext context = null;
  +     private final Map  subtaskClassNameMap = new HashMap();
        private File       destDir;
        private File       mergeDir;
        private String     excludedTags = null;
        private boolean    force = false;
        private String     addedTags;
  -     private ArrayList  templates = new ArrayList();
  -     private ArrayList  configParams = new ArrayList();
  +     private List       subTasks = new ArrayList();
  +     private List       configParams = new ArrayList();
   
  -     public DocletTask()
  +     public DocletTask() throws BuildException
        {
                setClassname( "xdoclet.XDocletMain" );
  +             registerTagHandlersMaybe();
  +             registerSubtasks();
  +     }
  +
  +     private final static void registerTagHandlersMaybe() throws BuildException
  +     {
  +             if( modules == null )
  +             {
  +                     ModuleFinder moduleFinder = new ModuleFinder();
  +
  +                     modules = moduleFinder.findModules();
  +
  +                     Iterator i = modules.iterator();
  +
  +                     while( i.hasNext() )
  +                     {
  +                             XDocletModule module = ( XDocletModule ) i.next();
  +                             // register tag handlers
  +                             List tagHandlerDefinitions = 
module.getTagHandlerDefinitions();
  +                             Iterator k = tagHandlerDefinitions.iterator();
  +
  +                             while( k.hasNext() )
  +                             {
  +                                     TagHandlerDefinition thd = ( 
TagHandlerDefinition ) k.next();
  +
  +                                     try
  +                                     {
  +                                             TemplateTagHandler handler = ( 
TemplateTagHandler ) Class.forName( thd.className ).newInstance();
  +
  +                                             
TemplateEngine.getEngineInstance().setTagHandlerFor( thd.namespace, handler );
  +                                     }
  +                                     catch( TemplateException e )
  +                                     {
  +                                             throw new BuildException( "Couldn't 
register " + thd.className + " to namespace " + thd.namespace + ":" + e.getMessage(), 
e );
  +                                     }
  +                                     catch( Exception e )
  +                                     {
  +                                             throw new BuildException( "Couldn't 
instantiate " + thd.className + " taghandler " + e.getMessage(), e );
  +                                     }
  +                             }
  +                     }
  +             }
        }
   
        /**
  @@ -68,7 +118,7 @@
         *
         * @return   The ConfigParams value
         */
  -     public ArrayList getConfigParams()
  +     public List getConfigParams()
        {
                return configParams;
        }
  @@ -94,16 +144,6 @@
        }
   
        /**
  -      * Gets the Templates attribute of the DocletTask object
  -      *
  -      * @return   The Templates value
  -      */
  -     public ArrayList getTemplates()
  -     {
  -             return templates;
  -     }
  -
  -     /**
         * Gets the DestDir attribute of the DocletTask object
         *
         * @return   The DestDir value
  @@ -128,6 +168,11 @@
                return addedTags;
        }
   
  +     public void setDynamicAttribute( String name, String value )
  +     {
  +             // do nothing
  +     }
  +
        public void setXdoclettempfile( File tmpFile )
        {
                _tmpFile = tmpFile;
  @@ -198,6 +243,36 @@
                this.addedTags = addedTags;
        }
   
  +     public Object createDynamicElement( String name )
  +     {
  +             String className = ( String ) subtaskClassNameMap.get( name );
  +
  +             try
  +             {
  +                     if( className == null )
  +                     {
  +                             throw new BuildException( "Can't create a " + name + " 
element here." );
  +                     }
  +
  +                     SubTask subTask = ( SubTask ) Class.forName( className 
).newInstance();
  +
  +                     subTasks.add( subTask );
  +                     return subTask;
  +             }
  +             catch( ClassNotFoundException e )
  +             {
  +                     throw new BuildException( "Couldn't find class " + className, 
e );
  +             }
  +             catch( InstantiationException e )
  +             {
  +                     throw new BuildException( "Couldn't instantiate " + className, 
e );
  +             }
  +             catch( IllegalAccessException e )
  +             {
  +                     throw new BuildException( "Couldn't invoke constructor for " + 
className, e );
  +             }
  +     }
  +
        /**
         * Describe the method
         *
  @@ -207,7 +282,32 @@
         */
        public void addTemplate( TemplateSubTask subtask )
        {
  -             templates.add( subtask );
  +             if( subtask.getSubTaskClassName() == null )
  +             {
  +                     subTasks.add( subtask );
  +             }
  +             else
  +             {
  +                     try
  +                     {
  +                             Class subtask_class = Class.forName( 
subtask.getSubTaskClassName() );
  +                             TemplateSubTask alias = ( TemplateSubTask ) 
subtask_class.newInstance();
  +
  +                             //now copy from subtask to real alias
  +                             alias.copyAttributesFrom( subtask );
  +
  +                             subTasks.add( subtask );
  +                     }
  +                     catch( ClassNotFoundException e )
  +                     {
  +                     }
  +                     catch( InstantiationException e )
  +                     {
  +                     }
  +                     catch( IllegalAccessException e )
  +                     {
  +                     }
  +             }
        }
   
        /**
  @@ -219,7 +319,7 @@
         */
        public void addXmlTemplate( XmlSubTask subtask )
        {
  -             templates.add( subtask );
  +             addTemplate( subtask );
        }
   
        /**
  @@ -255,65 +355,9 @@
         *
         * @return   The SubTasks value
         */
  -     protected List getSubTasks()
  -     {
  -             ArrayList true_subtasks = new ArrayList();
  -
  -             for( int i = 0; i < templates.size(); i++ )
  -             {
  -                     TemplateSubTask holder = ( TemplateSubTask ) templates.get( i 
);
  -
  -                     SubTask subtask = getSubTaskFromPlaceHolder( holder );
  -
  -                     if( subtask == null )
  +     protected final List getSubTasks()
                        {
  -                             log( Translator.getString( 
"couldnt_instantiate_subtask", new String[]{holder.getSubTaskClassName()} ), 
Project.MSG_ERR );
  -                             continue;
  -                     }
  -
  -                     true_subtasks.add( subtask );
  -             }
  -
  -             return true_subtasks;
  -     }
  -
  -     /**
  -      * Gets the SubTaskFromPlaceHolder attribute of the DocletTask object
  -      *
  -      * @param holder   Describe what the parameter does
  -      * @return         The SubTaskFromPlaceHolder value
  -      * @todo-javadoc   Write javadocs for method parameter
  -      */
  -     protected SubTask getSubTaskFromPlaceHolder( TemplateSubTask holder )
  -     {
  -             //no subtask class specified
  -             if( holder.getSubTaskClassName() == null )
  -             {
  -                     return holder;
  -             }
  -
  -             try
  -             {
  -                     Class subtask_class = Class.forName( 
holder.getSubTaskClassName() );
  -                     TemplateSubTask subtask = ( TemplateSubTask ) 
subtask_class.newInstance();
  -
  -                     //now copy from holder to real subtask
  -                     subtask.copyAttributesFrom( holder );
  -
  -                     return subtask;
  -             }
  -             catch( ClassNotFoundException e )
  -             {
  -                     return null;
  -             }
  -             catch( InstantiationException e )
  -             {
  -                     return null;
  -             }
  -             catch( IllegalAccessException e )
  -             {
  -                     return null;
  -             }
  +             return subTasks;
        }
   
        /**
  @@ -430,61 +474,24 @@
                }
        }
   
  -     /**
  -      * Describe what the method does
  -      *
  -      * @todo-javadoc   Write javadocs for method
  -      */
  -     private void executeSubTasksOLD()
  -     {
  -             Category cat = Log.getCategory( DocletTask.class, "executeSubTasks" );
  -
  -             DocletContext context = getContext();
  -             SubTask[] subtasks = context.getSubTasks();
  -
  -             for( int i = 0; i < subtasks.length; i++ )
  -             {
  -                     SubTask subtask = subtasks[i];
  -
  -                     if( subtask != null )
  -                     {
  -                             try
  -                             {
  -                                     subtasks[i].init();
  -                                     DocletContext.getInstance().setActiveSubTask( 
subtasks[i] );
  -
  -                                     log( Translator.getString( "running_taskname", 
new String[]{"<" + subtasks[i].getSubTaskName() + "/>"} ), Project.MSG_INFO );
  -                                     subtasks[i].execute();
  -                             }
  -                             catch( XDocletException e )
  -                             {
  -                                     log( Translator.getString( "running_failed" ), 
Project.MSG_ERR );
  -                                     log( "<<" + e.getMessage() + ">>", 
Project.MSG_ERR );
  -
  -                                     if( e.getNestedException() != null )
  +     private final void registerSubtasks() throws BuildException
                                        {
  -                                             
e.getNestedException().printStackTrace();
  -                                     }
  +             Iterator i = modules.iterator();
   
  -                                     if( e.getNestedException() instanceof 
TemplateException )
  +             while( i.hasNext() )
                                        {
  -                                             TemplateException template_ex = ( 
TemplateException ) e.getNestedException();
  +                     XDocletModule module = ( XDocletModule ) i.next();
  +                     // dynamically instrument parent tasks with create methods
  +                     List subTaskDefinitions = module.getSubTaskDefinitions();
  +                     Iterator j = subTaskDefinitions.iterator();
   
  -                                             if( cat.isDebugEnabled() )
  +                     while( j.hasNext() )
                                                {
  -                                                     cat.error( "Template Exception 
= " + template_ex );
  -                                                     cat.error( "Nested Exception = 
" + template_ex.getNestedException() );
  -                                             }
  -                                     }
  +                             SubTaskDefinition std = ( SubTaskDefinition ) j.next();
   
  -                                     if( cat.isDebugEnabled() )
  +                             if( getClass().getName().equals( std.parentTaskClass ) 
)
                                        {
  -                                             cat.error( "Exception trace:\n" + 
e.getPrintStackTrace() );
  -                                     }
  -
  -                                     e.printStackTrace();
  -                                     throw new BuildException( e.getMessage(), e, 
location );
  -                                     //return false;
  +                                     subtaskClassNameMap.put( std.name, 
std.implementationClass );
                                }
                        }
                }
  @@ -501,7 +508,7 @@
         * @todo-javadoc         Write javadocs for method parameter
         * @todo-javadoc         Write javadocs for method parameter
         */
  -     private void fillWithUserDefinedConfigParams( HashMap configs, ArrayList 
config_params, String prefix )
  +     private void fillWithUserDefinedConfigParams( HashMap configs, List 
config_params, String prefix )
        {
                //config params declared with <configParam name="nnn" value="val"/>
                for( int i = 0; i < config_params.size(); i++ )
  
  
  
  1.11.2.1  +7 -17     xdoclet/core/src/xdoclet/GenerationManager.java
  
  Index: GenerationManager.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/GenerationManager.java,v
  retrieving revision 1.11
  retrieving revision 1.11.2.1
  diff -u -w -r1.11 -r1.11.2.1
  --- GenerationManager.java    10 Apr 2002 22:52:14 -0000      1.11
  +++ GenerationManager.java    27 Apr 2002 23:54:31 -0000      1.11.2.1
  @@ -9,6 +9,7 @@
   import xdoclet.tags.ClassTagsHandler;
   import xdoclet.template.TemplateException;
   import xdoclet.util.Log;
  +import xdoclet.loader.ModuleFinder;
   
   import java.io.File;
   import java.io.FileOutputStream;
  @@ -34,7 +35,7 @@
    *
    * @author    Vincent Harcq ([EMAIL PROTECTED])
    * @created   March 30, 2002
  - * @version   $Revision: 1.11 $
  + * @version   $Revision: 1.11.2.1 $
    */
   public class GenerationManager implements java.io.Serializable
   {
  @@ -91,6 +92,11 @@
                return new File( path_str );
        }
   
  +     public static File getXjavadocJar()
  +     {
  +             return ModuleFinder.getJar( XClass.class, "xjavadoc.jar" );
  +     }
  +
        /**
         * During parsing we build the Template database. We store it on file.
         *
  @@ -119,22 +125,6 @@
                        }
                }
                getParserDb().put( new File( templateURL.getFile() ).getName(), 
complete.toArray( new String[complete.size()] ) );
  -     }
  -
  -     /**
  -      * Gets the XjavadocJar attribute of the GenerationManager class
  -      *
  -      * @return   The XjavadocJar value
  -      */
  -     private final static File getXjavadocJar()
  -     {
  -             String path_str = 
XClass.class.getProtectionDomain().getCodeSource().getLocation().getFile().toString();
  -
  -             if( path_str != null && path_str.startsWith( "/" ) )
  -             {
  -                     path_str = path_str.substring( 1 );
  -             }
  -             return new File( path_str );
        }
   
        /**
  
  
  

_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to