User: rinkrank
  Date: 02/04/06 17:08:28

  Modified:    core/src/xdoclet GenerationManager.java
  Log:
  -made getXdocletFile public (needed for experimental dynalic module code)
  
  Revision  Changes    Path
  1.9       +284 -218  xdoclet/core/src/xdoclet/GenerationManager.java
  
  Index: GenerationManager.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/GenerationManager.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -w -r1.8 -r1.9
  --- GenerationManager.java    4 Apr 2002 01:03:07 -0000       1.8
  +++ GenerationManager.java    7 Apr 2002 01:08:28 -0000       1.9
  @@ -34,35 +34,35 @@
    *
    * @author Vincent Harcq ([EMAIL PROTECTED])
    * @created March 30, 2002
  - * @version $Revision: 1.8 $
  + * @version   $Revision: 1.9 $
    */
  -public class GenerationManager {
  +public class GenerationManager
  +{
  +
        /**
         * @todo-javadoc Describe the field
         */
  -     private boolean guessGenerationNeeded = true;
  +     private final static File xdocletJar = getXdocletJar();
        /**
         * @todo-javadoc Describe the field
         */
  -     private TemplateSubTask subTask;
  -
  +     private final static File xjavadocJar = getXjavadocJar();
        /**
         * @todo-javadoc Describe the field
         */
  -     private final static File xdocletJar = getXdocletJar();
  +     private final static String TEMPLATE_FILES_DB = "xdoclet-template-db-" + 
DocletTask.XDOCLET_VERSION + ".properties";
        /**
         * @todo-javadoc Describe the field
         */
  -     private final static File xjavadocJar = getXjavadocJar();
  +     private static Map parserDb = null;
        /**
         * @todo-javadoc Describe the field
         */
  -     private final static String TEMPLATE_FILES_DB = "xdoclet-template-db-" + 
DocletTask.XDOCLET_VERSION + ".properties";
  +     private boolean    guessGenerationNeeded = true;
        /**
         * @todo-javadoc Describe the field
         */
  -     private static Map parserDb = null;
  -
  +     private TemplateSubTask subTask;
   
        /**
         * Describe what the GenerationManager constructor does
  @@ -71,31 +71,101 @@
         * @todo-javadoc Write javadocs for constructor
         * @todo-javadoc Write javadocs for method parameter
         */
  -     public GenerationManager(TemplateSubTask subTask) {
  +     public GenerationManager( TemplateSubTask subTask )
  +     {
                this.subTask = subTask;
        }
   
  +     /**
  +      * Gets the XdocletJar attribute of the GenerationManager class
  +      *
  +      * @return   The XdocletJar value
  +      */
  +     public final static File getXdocletJar()
  +     {
  +             String path_str = 
GenerationManager.class.getProtectionDomain().getCodeSource().getLocation().getFile().toString();
  +
  +             if( path_str != null && path_str.startsWith( "/" ) )
  +             {
  +                     path_str = path_str.substring( 1 );
  +             }
  +             return new File( path_str );
  +     }
   
        /**
  -      * Sets the GuessGenerationNeeded attribute of the GenerationManager object
  +      * During parsing we build the Template database. We store it on file.
         *
  -      * @param guessGenerationNeeded The new GuessGenerationNeeded value
  +      * @param templateURL           the template file
  +      * @param files                 the merge files involved in the generation
  +      * @exception XDocletException  Describe the exception
  +      * @todo-javadoc                Write javadocs for exception
         */
  -     public void setGuessGenerationNeeded(boolean guessGenerationNeeded) {
  -             this.guessGenerationNeeded = guessGenerationNeeded;
  +     public static void updateParserDb( URL templateURL, String[] files )
  +              throws XDocletException
  +     {
  +             // Merge existing list with new list
  +             String[] mergeFiles = ( String[] ) getParserDb().get( new File( 
templateURL.getFile() ).getName() );
  +             List complete = new ArrayList( Arrays.asList( files ) );
  +
  +             if( mergeFiles != null )
  +             {
  +                     for( int j = 0; j < mergeFiles.length; j++ )
  +                     {
  +                             String file = mergeFiles[j];
  +
  +                             if( !complete.contains( file ) )
  +                             {
  +                                     complete.add( file );
  +                             }
  +                     }
  +             }
  +             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 );
        }
   
  +     /**
  +      * Return (and construct) the template database. It is a map between a 
<code>String</code>
  +      * representing the template file and an array of <String> representing the
  +      * merge files that are part of the generation.
  +      *
  +      * @return   the <code>Map</code>
  +      */
  +     private static Map getParserDb()
  +     {
  +             Category cat = Log.getCategory( GenerationManager.class, "parserdb" );
  +
  +             if( parserDb == null )
  +             {
  +                     parserDb = new HashMap();
  +             }
  +             return parserDb;
  +     }
   
        /**
         * Gets the GuessGenerationNeeded attribute of the GenerationManager object
         *
         * @return The GuessGenerationNeeded value
         */
  -     public boolean isGuessGenerationNeeded() {
  +     public boolean isGuessGenerationNeeded()
  +     {
                return guessGenerationNeeded;
        }
   
  -
        /**
         * Test if a Java source mmust be generated or not depending of timestamp of
         * elements involved.
  @@ -107,77 +177,98 @@
         * @exception XDocletException
         */
        public boolean isGenerationNeeded(XClass clazz, File file, boolean 
withTemplate)
  -                      throws XDocletException {
  +              throws XDocletException
  +     {
                Category cat = Log.getCategory(GenerationManager.class, "generation");
   
  -             if (subTask.getContext().isForce()) {
  -                     if (cat.isDebugEnabled()) {
  +             if( subTask.getContext().isForce() )
  +             {
  +                     if( cat.isDebugEnabled() )
  +                     {
                                cat.debug("Force generation enabled");
                        }
                        return true;
                }
   
  -             if (isGuessGenerationNeeded() == false) {
  -                     if (cat.isDebugEnabled()) {
  +             if( isGuessGenerationNeeded() == false )
  +             {
  +                     if( cat.isDebugEnabled() )
  +                     {
                                cat.debug("guessGenerationNeeded enabled");
                        }
                        return true;
                }
   
                // 1. Check the classpath for timestamp on XDOCLET JAR and XJAVADOC JAR
  -             if (file.lastModified() < xdocletJar.lastModified()) {
  -                     if (cat.isDebugEnabled()) {
  +             if( file.lastModified() < xdocletJar.lastModified() )
  +             {
  +                     if( cat.isDebugEnabled() )
  +                     {
                                cat.debug("Generation needed for '" + file.getName() + 
"' because of timestamp of " + xdocletJar.getName());
                        }
                        return true;
                }
  -             if (cat.isDebugEnabled()) {
  +             if( cat.isDebugEnabled() )
  +             {
                        cat.debug("Reject file '" + file.getName() + "' because of 
timestamp of " + xdocletJar.getName());
                }
   
  -             if (file.lastModified() < xjavadocJar.lastModified()) {
  -                     if (cat.isDebugEnabled()) {
  +             if( file.lastModified() < xjavadocJar.lastModified() )
  +             {
  +                     if( cat.isDebugEnabled() )
  +                     {
                                cat.debug("Generation needed for '" + file.getName() + 
"' because of timestamp of " + xjavadocJar.getName());
                        }
                        return true;
                }
  -             if (cat.isDebugEnabled()) {
  +             if( cat.isDebugEnabled() )
  +             {
                        cat.debug("Reject file '" + file.getName() + "' because of 
timestamp of " + xjavadocJar.getName());
                }
   
                // 2. Check the bean timestamp
  -             if (file.lastModified() < clazz.lastModified()) {
  -                     if (cat.isDebugEnabled()) {
  +             if( file.lastModified() < clazz.lastModified() )
  +             {
  +                     if( cat.isDebugEnabled() )
  +                     {
                                cat.debug("Generation needed for '" + file.getName() + 
"' because of timestamp of " + clazz.qualifiedName());
                        }
                        return true;
                }
  -             if (cat.isDebugEnabled()) {
  +             if( cat.isDebugEnabled() )
  +             {
                        cat.debug("Reject file '" + clazz.qualifiedName() + "' because 
of timestamp of " + clazz.qualifiedName());
                }
   
                // 3. Check the superclasses timestamp
                XClass supers = clazz.superclass();
   
  -             while (supers != null) {
  -                     if (supers.qualifiedName().equals("java.lang.Object")) {
  +             while( supers != null )
  +             {
  +                     if( supers.qualifiedName().equals( "java.lang.Object" ) )
  +                     {
                                return false;
                        }
  -                     if (file.lastModified() < supers.lastModified()) {
  -                             if (cat.isDebugEnabled()) {
  +                     if( file.lastModified() < supers.lastModified() )
  +                     {
  +                             if( cat.isDebugEnabled() )
  +                             {
                                        cat.debug("Generation needed for '" + 
file.getName() + "' because of timestamp of " + supers.qualifiedName());
                                }
                                return true;
                        }
  -                     if (cat.isDebugEnabled()) {
  +                     if( cat.isDebugEnabled() )
  +                     {
                                cat.debug("Reject file '" + clazz.qualifiedName() + "' 
because of timestamp of " + supers.qualifiedName());
                        }
                        supers = supers.superclass();
                }
   
                // 4. Check the timestamp of template file and merge files
  -             if (withTemplate) {
  -                     if (isGenerationNeeded(file, subTask.getTemplateURL())) {
  +             if( withTemplate )
  +             {
  +                     if( isGenerationNeeded( file, subTask.getTemplateURL() ) )
  +                     {
                                return true;
                        }
                }
  @@ -185,7 +276,6 @@
                return false;
        }
   
  -
        /**
         * Verify if the generation of a file to generate is needed because either the
         * Template used to generate the file have a later timestamp, or because ALL
  @@ -197,65 +287,82 @@
         * @exception XDocletException
         */
        public boolean isGenerationNeeded(File file)
  -                      throws XDocletException {
  +              throws XDocletException
  +     {
                Category cat = Log.getCategory(GenerationManager.class, "generation");
   
  -             if (cat.isDebugEnabled()) {
  +             if( cat.isDebugEnabled() )
  +             {
                        cat.debug("Generation need check for " + file.getName());
                }
   
  -             if (subTask.getContext().isForce()) {
  -                     if (cat.isDebugEnabled()) {
  +             if( subTask.getContext().isForce() )
  +             {
  +                     if( cat.isDebugEnabled() )
  +                     {
                                cat.debug("Force generation enabled");
                        }
                        return true;
                }
   
  -             if (isGuessGenerationNeeded() == false) {
  -                     if (cat.isDebugEnabled()) {
  +             if( isGuessGenerationNeeded() == false )
  +             {
  +                     if( cat.isDebugEnabled() )
  +                     {
                                cat.debug("guessGenerationNeeded enabled");
                        }
                        return true;
                }
   
                // 1. Check the classpath for timestamp on XDOCLET JAR
  -             if (file.lastModified() < xdocletJar.lastModified()) {
  -                     if (cat.isDebugEnabled()) {
  +             if( file.lastModified() < xdocletJar.lastModified() )
  +             {
  +                     if( cat.isDebugEnabled() )
  +                     {
                                cat.debug("Generation needed for '" + file.getName() + 
"' because of timestamp of " + xdocletJar.getName());
                        }
                        return true;
                }
  -             if (cat.isDebugEnabled()) {
  +             if( cat.isDebugEnabled() )
  +             {
                        cat.debug("Reject file '" + file.getName() + "' because of 
timestamp of " + xdocletJar.getName());
                }
  -             if (file.lastModified() < xjavadocJar.lastModified()) {
  -                     if (cat.isDebugEnabled()) {
  +             if( file.lastModified() < xjavadocJar.lastModified() )
  +             {
  +                     if( cat.isDebugEnabled() )
  +                     {
                                cat.debug("Generation needed for '" + file.getName() + 
"' because of timestamp of " + xjavadocJar.getName());
                        }
                        return true;
                }
  -             if (cat.isDebugEnabled()) {
  +             if( cat.isDebugEnabled() )
  +             {
                        cat.debug("Reject file '" + file.getName() + "' because of 
timestamp of " + xdocletJar.getName());
                }
   
  -             if (cat.isDebugEnabled()) {
  +             if( cat.isDebugEnabled() )
  +             {
                        cat.debug("Generation need check for " + file.getName());
                }
   
                // 2. Check the timestamp of template file and merge files
  -             if (isGenerationNeeded(file, subTask.getTemplateURL())) {
  +             if( isGenerationNeeded( file, subTask.getTemplateURL() ) )
  +             {
                        return true;
                }
   
  -             if (cat.isDebugEnabled()) {
  +             if( cat.isDebugEnabled() )
  +             {
                        cat.debug("Generation need check for " + file.getName());
                }
   
                // 3. Check Timestamp of all java sources in sourcepath
                XClass[] classes = AbstractProgramElementTagsHandler.getAllClasses();
   
  -             for (int i = 0; i < classes.length; i++) {
  -                     if (isGenerationNeeded(classes[i], file, false)) {
  +             for( int i = 0; i < classes.length; i++ )
  +             {
  +                     if( isGenerationNeeded( classes[i], file, false ) )
  +                     {
                                return true;
                        }
                }
  @@ -263,6 +370,15 @@
                return false;
        }
   
  +     /**
  +      * Sets the GuessGenerationNeeded attribute of the GenerationManager object
  +      *
  +      * @param guessGenerationNeeded  The new GuessGenerationNeeded value
  +      */
  +     public void setGuessGenerationNeeded( boolean guessGenerationNeeded )
  +     {
  +             this.guessGenerationNeeded = guessGenerationNeeded;
  +     }
   
        /**
         * Verify if the generation of a file is needed because either the template
  @@ -275,62 +391,79 @@
         * @exception XDocletException
         */
        private boolean isGenerationNeeded(File file, URL templateURL)
  -                      throws XDocletException {
  +              throws XDocletException
  +     {
                Category cat = Log.getCategory(GenerationManager.class, "xml");
   
  -             if (cat.isDebugEnabled()) {
  +             if( cat.isDebugEnabled() )
  +             {
                        cat.debug("Generation need check for " + file.getName());
                }
   
                // 1. Check Timestamp of Template file
  -             if (file.lastModified() < new 
File(subTask.getTemplateURL().getFile()).lastModified()) {
  -                     if (cat.isDebugEnabled()) {
  +             if( file.lastModified() < new File( subTask.getTemplateURL().getFile() 
).lastModified() )
  +             {
  +                     if( cat.isDebugEnabled() )
  +                     {
                                cat.debug("Generation needed for '" + file.getName() + 
"' because of timestamp of " + subTask.getTemplateURL());
                        }
                        return true;
                }
  -             if (cat.isDebugEnabled()) {
  +             if( cat.isDebugEnabled() )
  +             {
                        cat.debug("Reject file '" + file.getName() + "' because of 
timestamp of " + subTask.getTemplateURL());
                }
   
                // 2. Check timestamp of Merge files found inside Template
                String[] files;
   
  -             if (getParserDb().get(new File(templateURL.getFile()).getName()) == 
null) {
  +             if( getParserDb().get( new File( templateURL.getFile() ).getName() ) 
== null )
  +             {
                        subTask.getParser().setOutput(file);
                        subTask.getParser().setTemplateURL(templateURL);
   
  -                     try {
  +                     try
  +                     {
                                subTask.getParser().start();
  -                     } catch (TemplateException e) {
  +                     }
  +                     catch( TemplateException e )
  +                     {
                                throw new XDocletException(e.toString());
                        }
   
                        files = subTask.getParser().getMergeFiles();
  -                     if (files != null) {
  +                     if( files != null )
  +                     {
                                updateParserDb(templateURL, files);
                        }
                }
  -             else {
  +             else
  +             {
                        files = (String[])getParserDb().get(new 
File(templateURL.getFile()).getName());
  -                     for (int i = 0; i < files.length; i++) {
  -                             if (cat.isDebugEnabled()) {
  +                     for( int i = 0; i < files.length; i++ )
  +                     {
  +                             if( cat.isDebugEnabled() )
  +                             {
                                        cat.debug(templateURL.getFile() + " : " + 
files[i]);
                                }
                        }
                }
   
  -             if (cat.isDebugEnabled()) {
  +             if( cat.isDebugEnabled() )
  +             {
                        cat.debug("Number of Merge files involved = " + files.length);
                }
  -             for (int i = 0; i < files.length; i++) {
  +             for( int i = 0; i < files.length; i++ )
  +             {
                        String merge_file_pattern = files[i];
                        List merge_files = new ArrayList();
   
  -                     if (merge_file_pattern.indexOf("{0}") != -1) {
  +                     if( merge_file_pattern.indexOf( "{0}" ) != -1 )
  +                     {
                                XClass[] classes = ClassTagsHandler.getAllClasses();
   
  -                             for (int j = 0; j < classes.length; j++) {
  +                             for( int j = 0; j < classes.length; j++ )
  +                             {
                                        XClass aClass = classes[j];
                                        String ejb_name = 
MessageFormat.format(merge_file_pattern, new 
Object[]{AbstractProgramElementTagsHandler.getClassNameFor(aClass)});
                                        String merge_file_name = 
PackageTagsHandler.packageNameAsPathFor(aClass.containingPackage()) + File.separator + 
ejb_name;
  @@ -338,103 +471,36 @@
                                        merge_files.add(new 
File(subTask.getMergeDir(), merge_file_name));
                                }
                        }
  -                     else {
  +                     else
  +                     {
                                merge_files.add(new File(subTask.getMergeDir(), 
merge_file_pattern));
                        }
  -                     for (Iterator iterator = merge_files.iterator(); 
iterator.hasNext(); ) {
  +                     for( Iterator iterator = merge_files.iterator(); 
iterator.hasNext();  )
  +                     {
                                File merge_file = (File)iterator.next();
   
  -                             if (cat.isDebugEnabled()) {
  +                             if( cat.isDebugEnabled() )
  +                             {
                                        cat.debug("Generation check for '" + 
file.getName() + "' because of " + merge_file.getName());
                                }
  -                             if (merge_file.exists()) {
  -                                     if (file.lastModified() < 
merge_file.lastModified()) {
  -                                             if (cat.isDebugEnabled()) {
  +                             if( merge_file.exists() )
  +                             {
  +                                     if( file.lastModified() < 
merge_file.lastModified() )
  +                                     {
  +                                             if( cat.isDebugEnabled() )
  +                                             {
                                                        cat.debug("Generation needed 
for '" + file.getName() + "' because of timestamp of " + merge_file.getName());
                                                }
                                                return true;
                                        }
  -                                     if (cat.isDebugEnabled()) {
  +                                     if( cat.isDebugEnabled() )
  +                                     {
                                                cat.debug("Reject file '" + 
file.getName() + "' because of timestamp of " + merge_file.getName());
                                        }
                                }
                        }
                }
                return false;
  -     }
  -
  -
  -     /**
  -      * During parsing we build the Template database. We store it on file.
  -      *
  -      * @param templateURL the template file
  -      * @param files the merge files involved in the generation
  -      * @exception XDocletException Describe the exception
  -      * @todo-javadoc Write javadocs for exception
  -      */
  -     public static void updateParserDb(URL templateURL, String[] files)
  -                      throws XDocletException {
  -             // Merge existing list with new list
  -             String[] mergeFiles = (String[])getParserDb().get(new 
File(templateURL.getFile()).getName());
  -             List complete = new ArrayList(Arrays.asList(files));
  -
  -             if (mergeFiles != null) {
  -                     for (int j = 0; j < mergeFiles.length; j++) {
  -                             String file = mergeFiles[j];
  -
  -                             if (!complete.contains(file)) {
  -                                     complete.add(file);
  -                             }
  -                     }
  -             }
  -             getParserDb().put(new File(templateURL.getFile()).getName(), 
complete.toArray(new String[complete.size()]));
  -     }
  -
  -
  -     /**
  -      * Gets the XdocletJar attribute of the GenerationManager class
  -      *
  -      * @return The XdocletJar value
  -      */
  -     private final static File getXdocletJar() {
  -             String path_str = 
GenerationManager.class.getProtectionDomain().getCodeSource().getLocation().getFile().toString();
  -
  -             if (path_str != null && path_str.startsWith("/")) {
  -                     path_str = path_str.substring(1);
  -             }
  -             return new File(path_str);
  -     }
  -
  -
  -     /**
  -      * 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);
  -     }
  -
  -
  -     /**
  -      * Return (and construct) the template database. It is a map between a 
<code>String</code>
  -      * representing the template file and an array of <String> representing the
  -      * merge files that are part of the generation.
  -      *
  -      * @return the <code>Map</code>
  -      */
  -     private static Map getParserDb() {
  -             Category cat = Log.getCategory(GenerationManager.class, "parserdb");
  -
  -             if (parserDb == null) {
  -                     parserDb = new HashMap();
  -             }
  -             return parserDb;
        }
   
   }
  
  
  

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

Reply via email to