User: rinkrank
  Date: 02/04/08 17:07:16

  Modified:    core/src/xdoclet/loader BootstrapClassLoader.java
                        Bootstrapper.java TagHandlerDefinition.java
  Log:
  -Dynamic loading of optional modules is partially working (subtasks work. 
registering tag handlers doesn't)
  -Translator no longer throws XDocletException
  
  Revision  Changes    Path
  1.2       +85 -9     xdoclet/core/src/xdoclet/loader/BootstrapClassLoader.java
  
  Index: BootstrapClassLoader.java
  ===================================================================
  RCS file: 
/cvsroot/xdoclet/xdoclet/core/src/xdoclet/loader/BootstrapClassLoader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- BootstrapClassLoader.java 7 Apr 2002 21:12:33 -0000       1.1
  +++ BootstrapClassLoader.java 9 Apr 2002 00:07:16 -0000       1.2
  @@ -21,13 +21,50 @@
    */
   class BootstrapClassLoader extends ClassLoader implements Constants
   {
  +
  +     /**
  +      * @todo-javadoc   Describe the field
  +      */
  +     private static String _myJarFileName;
  +     /**
  +      * @todo-javadoc   Describe the field
  +      */
        private final ArrayList _mutatedClassNames = new ArrayList();
  +     /**
  +      * @todo-javadoc   Describe the field
  +      */
        private final HashMap _creators = new HashMap();
   
  -     private String     _xdocletJarFileName = 
GenerationManager.getXdocletJar().getAbsolutePath();
  -
  +     /**
  +      * @todo-javadoc   Describe the field
  +      */
        private HashMap    _classes = new HashMap();
  +     static
  +     {
  +             String myJarFileName = 
BootstrapClassLoader.class.getProtectionDomain().getCodeSource().getLocation().getFile();
  +
  +             // For some weird reason, myJarFile now points to ant.jar. This is a 
hack around that until we find a better solution
  +             File myJarFile = new File( myJarFileName );
  +             File myRealJarFile = new File( myJarFile.getParentFile(), 
"xdoclet.jar" );
  +
  +             if( !myRealJarFile.exists() )
  +             {
  +                     System.err.println( "You have to put xdoclet.jar under " + 
myJarFile.getParentFile().getAbsolutePath() );
  +             }
  +             _myJarFileName = myRealJarFile.getAbsolutePath();
  +     }
   
  +     /**
  +      * Describe what the method does
  +      *
  +      * @param methodName           Describe what the parameter does
  +      * @param implementationClass  Describe what the parameter does
  +      * @param parentTaskClass      Describe what the parameter does
  +      * @todo-javadoc               Write javadocs for method
  +      * @todo-javadoc               Write javadocs for method parameter
  +      * @todo-javadoc               Write javadocs for method parameter
  +      * @todo-javadoc               Write javadocs for method parameter
  +      */
        public void registerCreator( String methodName, String implementationClass, 
String parentTaskClass )
        {
                Creator creator = new Creator();
  @@ -48,29 +85,43 @@
                _mutatedClassNames.add( parentTaskClass );
        }
   
  +     /**
  +      * Describe what the method does
  +      *
  +      * @param class_name                  Describe what the parameter does
  +      * @param resolve                     Describe what the parameter does
  +      * @return                            Describe the return value
  +      * @exception ClassNotFoundException  Describe the exception
  +      * @todo-javadoc                      Write javadocs for method
  +      * @todo-javadoc                      Write javadocs for method parameter
  +      * @todo-javadoc                      Write javadocs for method parameter
  +      * @todo-javadoc                      Write javadocs for return value
  +      * @todo-javadoc                      Write javadocs for exception
  +      */
        protected Class loadClass( String class_name, boolean resolve ) throws 
ClassNotFoundException
        {
  +             Class cl = null;
  +
                if( !_mutatedClassNames.contains( class_name ) )
                {
  -                     return Class.forName( class_name );
  +                     // it's not one of the classes we're going to mutate. classic 
class loading.
  +                     cl = Class.forName( class_name );
  +                     return cl;
                }
   
  -             Class cl = ( Class ) _classes.get( class_name );
  +             cl = ( Class ) _classes.get( class_name );
   
                if( cl == null )
                {
                        try
                        {
                                // The getXdocletJar() is Buggy. It returns the ant 
jar file (??!!)
  -                             _xdocletJarFileName = 
"F:\\xdoclet\\core\\samples\\lib\\xdoclet.jar";
  +                             //xdocletJarFileName = 
"F:\\xdoclet\\core\\samples\\lib\\xdoclet.jar";
   
                                // Parse original class
                                String classEntryName = class_name.replace( '.', '/' ) 
+ ".class";
   
  -                             System.out.println( _xdocletJarFileName );
  -                             System.out.println( classEntryName );
  -
  -                             ClassParser parser = new ClassParser( 
_xdocletJarFileName, classEntryName );
  +                             ClassParser parser = new ClassParser( _myJarFileName, 
classEntryName );
                                JavaClass clazz = parser.parse();
   
                                // Create a ClassGen so we can modify the existing 
class
  @@ -101,6 +152,13 @@
                return cl;
        }
   
  +     /**
  +      * Describe the method
  +      *
  +      * @param cg       Describe the method parameter
  +      * @todo-javadoc   Describe the method
  +      * @todo-javadoc   Describe the method parameter
  +      */
        private void addCreateMethods( ClassGen cg )
        {
                List parentTaskCreators = ( List ) _creators.get( cg.getClassName() );
  @@ -115,6 +173,17 @@
                }
        }
   
  +     /**
  +      * Describe what the method does
  +      *
  +      * @param cg       Describe what the parameter does
  +      * @param creator  Describe what the parameter does
  +      * @return         Describe the return value
  +      * @todo-javadoc   Write javadocs for method
  +      * @todo-javadoc   Write javadocs for method parameter
  +      * @todo-javadoc   Write javadocs for method parameter
  +      * @todo-javadoc   Write javadocs for return value
  +      */
        private Method createCreateMethod( ClassGen cg, Creator creator )
        {
                System.out.println( "Adding create method " + creator.methodName + " 
to " + cg.getClassName() );
  @@ -210,11 +279,18 @@
        }
   
        /**
  +      * @author    Aslak Hellesøy
         * @created   7. april 2002
         */
        private static class Creator
        {
  +             /**
  +              * @todo-javadoc   Describe the field
  +              */
                public String     methodName;
  +             /**
  +              * @todo-javadoc   Describe the field
  +              */
                public String     implementationClass;
        }
   }
  
  
  
  1.2       +35 -3     xdoclet/core/src/xdoclet/loader/Bootstrapper.java
  
  Index: Bootstrapper.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/loader/Bootstrapper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- Bootstrapper.java 7 Apr 2002 21:12:33 -0000       1.1
  +++ Bootstrapper.java 9 Apr 2002 00:07:16 -0000       1.2
  @@ -13,6 +13,9 @@
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.types.Reference;
   
  +import xdoclet.template.TemplateEngine;
  +import xdoclet.template.TemplateException;
  +
   /**
    * Bootstrapper for xdoclet. Defines xdoclet tasks and preproceses them with
    * BCEL This class would have extended Taskdef if Taskdef/Definer hadn't been so
  @@ -23,8 +26,16 @@
    */
   public class Bootstrapper extends Task
   {
  +     /**
  +      * @todo-javadoc   Describe the field
  +      */
        private Path       classpath;
   
  +     /**
  +      * Sets the Classpath attribute of the Bootstrapper object
  +      *
  +      * @param classpath  The new Classpath value
  +      */
        public void setClasspath( Path classpath )
        {
                if( this.classpath == null )
  @@ -55,7 +66,9 @@
        {
                try
                {
  -                     BootstrapClassLoader cl = new BootstrapClassLoader();
  +                     //BootstrapClassLoader cl = new BootstrapClassLoader();
  +                     BootstrapClassLoader bcl = new BootstrapClassLoader();
  +                     AntClassLoader cl = new AntClassLoader( bcl, project, 
this.classpath, true );
   
                        ModuleFinder moduleFinder = new ModuleFinder();
                        List modules = moduleFinder.findModules();
  @@ -64,6 +77,8 @@
                        while( i.hasNext() )
                        {
                                XDocletModule module = ( XDocletModule ) i.next();
  +
  +                             // dynamically instrument parent tasks with create 
methods
                                List subTaskDefinitions = 
module.getSubTaskDefinitions();
                                Iterator j = subTaskDefinitions.iterator();
   
  @@ -71,7 +86,25 @@
                                {
                                        SubTaskDefinition std = ( SubTaskDefinition ) 
j.next();
   
  -                                     cl.registerCreator( std.createMethodName(), 
std.implementationClass, std.parentTaskClass );
  +                                     bcl.registerCreator( std.createMethodName(), 
std.implementationClass, std.parentTaskClass );
  +                             }
  +
  +                             // register tag handlers
  +                             List tagHandlerDefinitions = 
module.getTagHandlerDefinitions();
  +                             Iterator k = tagHandlerDefinitions.iterator();
  +
  +                             while( k.hasNext() )
  +                             {
  +                                     TagHandlerDefinition thd = ( 
TagHandlerDefinition ) k.next();
  +
  +                                     try
  +                                     {
  +                                             
TemplateEngine.getEngineInstance().setTagHandlerFor( thd.namespace, 
thd.getTagHandler() );
  +                                     }
  +                                     catch( TemplateException e )
  +                                     {
  +                                             throw new BuildException( "Couldn't 
register " + thd.getTagHandler().getClass().getName() + " to namespace " + 
thd.namespace + ":" + e.getMessage(), e );
  +                                     }
                                }
                        }
   
  @@ -79,7 +112,6 @@
                        {
                                Class ejbDocletClass = cl.loadClass( 
"xdoclet.ejb.EjbDocletTask" );
   
  -                             System.out.println( "XXX" + System.getProperty( 
"ant.class.path" ) );
                                project.addTaskDefinition( "ejbdoclet", ejbDocletClass 
);
                        }
                        catch( ClassNotFoundException e )
  
  
  
  1.2       +32 -1     xdoclet/core/src/xdoclet/loader/TagHandlerDefinition.java
  
  Index: TagHandlerDefinition.java
  ===================================================================
  RCS file: 
/cvsroot/xdoclet/xdoclet/core/src/xdoclet/loader/TagHandlerDefinition.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- TagHandlerDefinition.java 7 Apr 2002 21:12:33 -0000       1.1
  +++ TagHandlerDefinition.java 9 Apr 2002 00:07:16 -0000       1.2
  @@ -4,16 +4,47 @@
    */
   package xdoclet.loader;
   
  +import xdoclet.template.TemplateTagHandler;
  +
   /**
  + * @author    Aslak Hellesøy
    * @created   7. april 2002
    */
   class TagHandlerDefinition
   {
  +     /**
  +      * @todo-javadoc   Describe the field
  +      */
        public final String namespace;
  -     public final String className;
  +     /**
  +      * @todo-javadoc   Describe the field
  +      */
  +     private final String className;
  +
  +     /**
  +      * Describe what the TagHandlerDefinition constructor does
  +      *
  +      * @param namespace  Describe what the parameter does
  +      * @param className  Describe what the parameter does
  +      * @todo-javadoc     Write javadocs for constructor
  +      * @todo-javadoc     Write javadocs for method parameter
  +      * @todo-javadoc     Write javadocs for method parameter
  +      */
        public TagHandlerDefinition( String namespace, String className )
        {
                this.namespace = namespace;
                this.className = className;
  +     }
  +
  +     /**
  +      * Gets the TagHandler attribute of the TagHandlerDefinition object
  +      *
  +      * @return               The TagHandler value
  +      * @exception Exception  Describe the exception
  +      * @todo-javadoc         Write javadocs for exception
  +      */
  +     public TemplateTagHandler getTagHandler() throws Exception
  +     {
  +             return ( TemplateTagHandler ) Class.forName( className ).newInstance();
        }
   }
  
  
  

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

Sponsored by http://www.ThinkGeek.com/

Reply via email to