User: rinkrank
  Date: 02/05/30 11:38:53

  Modified:    core/src/xdoclet DocletTask.java SubTask.java
                        TemplateSubTask.java
  Log:
  Refactoring which removes redundant subtask names (both in @xdoclet.subtask 
name="blabla" and in code)
  -Removed the static SUBTASK_NAME and overridden getSubTaskName() from all SubTasks 
(it's final now in SubTask)
  -DocletTask stores all subtask names in a Class->String Map, using the name from 
xdoclet.xml (which in turn comes from @xdoclet.subtask name="blabla"
  -All references to SomeSubTask.SUBTASK_NAME replaced by a call to 
DocletTask.getSubTaskName(Class subTaskClass)
  -Improved error reporting in DocletTask
  -Reverted the ejbjarxml/webxml to deploymentdescriptor
  -Added omit.docs flag in xdoclet/build.xml set it to true in ANT_OPTS for faster 
build
  
  Revision  Changes    Path
  1.41      +80 -50    xdoclet/core/src/xdoclet/DocletTask.java
  
  Index: DocletTask.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/DocletTask.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -w -r1.40 -r1.41
  --- DocletTask.java   28 May 2002 21:25:00 -0000      1.40
  +++ DocletTask.java   30 May 2002 18:38:52 -0000      1.41
  @@ -16,6 +16,7 @@
   import org.apache.tools.ant.AntClassLoader;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.DynamicConfigurator;
  +import org.apache.tools.ant.Project;
   
   import xjavadoc.ant.XJavadocTask;
   
  @@ -46,12 +47,20 @@
       // ant will replace the tag with the version propperty specified in build.xml
       public final static String XDOCLET_VERSION = "@VERSION@";
   
  +    /**
  +     * subtask class -> logical name (java.lang.String) Used to look up names
  +     */
  +    private final static Map subtaskNameMap = new HashMap();
  +
       protected transient DocletContext context = null;
   
       /**
        * logical name (java.lang.String) -> subtask (xdoclet.SubTask or a subclass of 
it)
        */
       private final Map subtaskMap = new HashMap();
  +
  +    // keep the classpath value for better error reporting
  +    private final String classpath;
       private List    modules = null;
       private File    destDir;
       private File    mergeDir;
  @@ -61,10 +70,12 @@
       private String  addedTags;
       private List    subTasks = new ArrayList();
       private List    configParams = new ArrayList();
  +    private boolean isModulesRegistered = false;
   
  -    static {
  +    public DocletTask() throws BuildException
  +    {
           try {
  -            String classpath = ((AntClassLoader) 
DocletTask.class.getClassLoader()).getClasspath();
  +            classpath = ((AntClassLoader) 
DocletTask.class.getClassLoader()).getClasspath();
   
               System.setProperty("xdoclet.class.path", classpath);
           }
  @@ -73,56 +84,14 @@
           }
       }
   
  -    public DocletTask() throws BuildException
  +    public static String getSubTaskName(Class subTaskClass)
       {
  -        Log log = LogUtil.getLog(getClass(), "DocletTask");
  -
  -        // Register subtasks that apply to us (they do if they in xdoclet.xml have 
declared us as parent)
  -        List modules = ModuleFinder.findModules();
  -        Iterator i = modules.iterator();
  -
  -        while (i.hasNext()) {
  -            XDocletModule module = (XDocletModule) i.next();
  -            List subTaskDefinitions = module.getSubTaskDefinitions();
  -            Iterator j = subTaskDefinitions.iterator();
  -
  -            while (j.hasNext()) {
  -                SubTaskDefinition subTaskDefinition = (SubTaskDefinition) j.next();
  -
  -                try {
  -                    Class parentTaskClass = 
Class.forName(subTaskDefinition.parentTaskClass);
  -
  -                    if (parentTaskClass.isAssignableFrom(getClass())) {
  -                        if (subtaskMap.containsKey(subTaskDefinition.name)) {
  -                            String conflictingSubTaskClassName = 
subtaskMap.get(subTaskDefinition.name).getClass().getName();
  -
  -                            if 
(!subTaskDefinition.implementationClass.equals(conflictingSubTaskClassName)) {
  -                                // duplicate subtask definition, and it's not the 
same classname (which occurs
  -                                // if a module is twice or more on classpath - 
which is OK)
  -                                throw new BuildException("Ambiguous subtask 
definition for logical name " + subTaskDefinition.name + ":" + 
conflictingSubTaskClassName + " and " + subTaskDefinition.implementationClass);
  -                            }
  +        return (String) subtaskNameMap.get(subTaskClass);
                           }
   
  -                        SubTask subTask = (SubTask) 
Class.forName(subTaskDefinition.implementationClass).newInstance();
  -
  -                        log.debug("Registering SubTask " + subTaskDefinition.name + 
" (" + subTaskDefinition.implementationClass + ") to DocletTask " + 
getClass().getName());
  -                        subtaskMap.put(subTaskDefinition.name, subTask);
  -                    }
  -                }
  -                catch (ClassNotFoundException e) {
  -                    throw new BuildException("Couldn't find class: " + 
e.getMessage(), e);
  -                }
  -                catch (InstantiationException e) {
  -                    throw new BuildException("Couldn't instantiate class: " + 
e.getMessage(), e);
  -                }
  -                catch (IllegalAccessException e) {
  -                    throw new BuildException("Couldn't invoke constructor: " + 
e.getMessage(), e);
  -                }
  -                catch (ClassCastException e) {
  -                    throw new BuildException("Couldn't cast to " + 
SubTask.class.getName(), e);
  -                }
  -            }
  -        }
  +    static void registerSubTaskName(SubTask subTask, String name)
  +    {
  +        subtaskNameMap.put(subTask.getClass(), name);
       }
   
       /**
  @@ -272,6 +241,11 @@
   
       public Object createDynamicElement(String name) throws BuildException
       {
  +        if (!isModulesRegistered) {
  +            registerModules();
  +            isModulesRegistered = true;
  +        }
  +
           SubTask subTask = (SubTask) subtaskMap.get(name);
   
           if (subTask == null) {
  @@ -420,6 +394,62 @@
                   }
                   catch (XDocletException ex) {
                       new BuildException(subtask.getSubTaskName() + ": " + 
ex.getMessage(), location);
  +                }
  +            }
  +        }
  +    }
  +
  +    private void registerModules()
  +    {
  +        // Register subtasks that apply to us (they do if they in xdoclet.xml have 
declared us as parent)
  +        List modules = ModuleFinder.findModules();
  +        Iterator i = modules.iterator();
  +
  +        while (i.hasNext()) {
  +            XDocletModule module = (XDocletModule) i.next();
  +            List subTaskDefinitions = module.getSubTaskDefinitions();
  +            Iterator j = subTaskDefinitions.iterator();
  +
  +            while (j.hasNext()) {
  +                SubTaskDefinition subTaskDefinition = (SubTaskDefinition) j.next();
  +
  +                try {
  +                    Class parentTaskClass = 
Class.forName(subTaskDefinition.parentTaskClass);
  +
  +                    if (parentTaskClass.isAssignableFrom(getClass())) {
  +                        if (subtaskMap.containsKey(subTaskDefinition.name)) {
  +                            String conflictingSubTaskClassName = 
subtaskMap.get(subTaskDefinition.name).getClass().getName();
  +
  +                            if 
(!subTaskDefinition.implementationClass.equals(conflictingSubTaskClassName)) {
  +                                // duplicate subtask definition, and it's not the 
same classname (which occurs
  +                                // if a module is twice or more on classpath - 
which is OK)
  +                                throw new BuildException("Ambiguous subtask 
definition for logical name " + subTaskDefinition.name + ":" + 
conflictingSubTaskClassName + " and " + subTaskDefinition.implementationClass);
  +                            }
  +                        }
  +
  +                        Class subTaskClass = 
Class.forName(subTaskDefinition.implementationClass);
  +                        SubTask subTask = (SubTask) subTaskClass.newInstance();
  +
  +                        log("Registering SubTask " + subTaskDefinition.name + " (" 
+ subTaskDefinition.implementationClass + ") to DocletTask " + getClass().getName(), 
Project.MSG_DEBUG);
  +                        subtaskMap.put(subTaskDefinition.name, subTask);
  +                        registerSubTaskName(subTask, subTaskDefinition.name);
  +                    }
  +                }
  +                catch (ClassNotFoundException e) {
  +                    log("Make sure that the jar file containing " +
  +                        e.getMessage() + " is on the classpath specified in the 
<taskdef> that defined " + getTaskName() + "." +
  +                        " This class is required by " + 
subTaskDefinition.implementationClass + " which is one of the subtasks that " +
  +                        "was on your classpath. The " + getTaskName() + " task's 
classpath is:\n\n" + classpath, Project.MSG_ERR);
  +                    throw new BuildException("Couldn't find class: " + 
e.getMessage(), e);
  +                }
  +                catch (InstantiationException e) {
  +                    throw new BuildException("Couldn't instantiate class: " + 
e.getMessage(), e);
  +                }
  +                catch (IllegalAccessException e) {
  +                    throw new BuildException("Couldn't invoke constructor: " + 
e.getMessage(), e);
  +                }
  +                catch (ClassCastException e) {
  +                    throw new BuildException("Couldn't cast to " + 
SubTask.class.getName(), e);
                   }
               }
           }
  
  
  
  1.68      +10 -22    xdoclet/core/src/xdoclet/SubTask.java
  
  Index: SubTask.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/SubTask.java,v
  retrieving revision 1.67
  retrieving revision 1.68
  diff -u -w -r1.67 -r1.68
  --- SubTask.java      28 May 2002 22:35:23 -0000      1.67
  +++ SubTask.java      30 May 2002 18:38:52 -0000      1.68
  @@ -23,7 +23,7 @@
    *
    * @author    Ara Abrahamian ([EMAIL PROTECTED])
    * @created   June 16, 2001
  - * @version   $Revision: 1.67 $
  + * @version   $Revision: 1.68 $
    */
   public abstract class SubTask extends DocletSupport implements Serializable
   {
  @@ -41,7 +41,15 @@
   
       private ArrayList configParams = new ArrayList();
   
  -    private String  subtaskName = null;
  +    /**
  +     * Gets the SubTaskName attribute of the SubTask object
  +     *
  +     * @return   The SubTaskName value
  +     */
  +    public final String getSubTaskName()
  +    {
  +        return DocletTask.getSubTaskName(getClass());
  +    }
   
       /**
        * Gets the ConfigParams attribute of the SubTask object
  @@ -71,26 +79,6 @@
       public File getMergeDir()
       {
           return mergeDir;
  -    }
  -
  -    /**
  -     * Gets the SubTaskName attribute of the SubTask object
  -     *
  -     * @return   The SubTaskName value
  -     */
  -    public String getSubTaskName()
  -    {
  -        return subtaskName;
  -    }
  -
  -    /**
  -     * Sets the SubTaskName attribute of the SubTask object
  -     *
  -     * @param subtaskName  The new SubTaskName value
  -     */
  -    public void setSubTaskName(String subtaskName)
  -    {
  -        this.subtaskName = subtaskName;
       }
   
       /**
  
  
  
  1.43      +7 -12     xdoclet/core/src/xdoclet/TemplateSubTask.java
  
  Index: TemplateSubTask.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/TemplateSubTask.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -w -r1.42 -r1.43
  --- TemplateSubTask.java      28 May 2002 22:35:23 -0000      1.42
  +++ TemplateSubTask.java      30 May 2002 18:38:52 -0000      1.43
  @@ -34,11 +34,11 @@
    * @author            Ara Abrahamian ([EMAIL PROTECTED])
    * @created           Sep 25, 2001
    * @xdoclet:subtask   name="template" parent="xdoclet.DocletTask"
  - * @version           $Revision: 1.42 $
  + * @version           $Revision: 1.43 $
    */
   public class TemplateSubTask extends SubTask
   {
  -    public final static String SUBTASK_NAME = "template";
  +    private final static String SUBTASK_NAME = "template";
   
       private URL     templateURL = null;
   
  @@ -99,6 +99,11 @@
   
       private GenerationManager generationManager;
   
  +    public TemplateSubTask()
  +    {
  +        DocletTask.registerSubTaskName(this, SUBTASK_NAME);
  +    }
  +
       /**
        * Converts the full qualified class name to a valid path with File.separator 
characters instead of . characters and
        * class name postfixed by a ".java".
  @@ -215,16 +220,6 @@
       public String getHavingClassTag()
       {
           return havingClassTag;
  -    }
  -
  -    /**
  -     * Gets the SubTaskName attribute of the TemplateSubTask object
  -     *
  -     * @return   The SubTaskName value
  -     */
  -    public String getSubTaskName()
  -    {
  -        return SUBTASK_NAME;
       }
   
       /**
  
  
  

_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm

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

Reply via email to