Update of /cvsroot/xdoclet/xdoclet2/core/src/java/xdoclet
In directory sc8-pr-cvs1:/tmp/cvs-serv7981/core/src/java/xdoclet

Modified Files:
        Destination.java FileDestination.java Generator.java 
        Plugin.java 
Removed Files:
        XMLGenerator.java 
Log Message:
-Made it possible to use custom generation (arbitrary number of files) in addition to 
per class and for all classes.
-Moved some classes to more appropriate packages

Index: Destination.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet2/core/src/java/xdoclet/Destination.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** Destination.java    8 Nov 2002 02:26:06 -0000       1.1
--- Destination.java    22 Nov 2002 18:57:38 -0000      1.2
***************
*** 11,15 ****
   * of the methods {@link #getWriter(XClass)} or {@link 
#getWriter(java.util.Collection)}
   * depending on whether it is designed to be used in conjunction with
!  * generators that generate for one class or multiple classes.
   *
   * @author    <a href="mailto:[EMAIL PROTECTED]";>Aslak Helles&oslash;y</a>
--- 11,15 ----
   * of the methods {@link #getWriter(XClass)} or {@link 
#getWriter(java.util.Collection)}
   * depending on whether it is designed to be used in conjunction with
!  * generators that generateForClasses for one class or multiple classes.
   *
   * @author    <a href="mailto:[EMAIL PROTECTED]";>Aslak Helles&oslash;y</a>
***************
*** 22,25 ****
--- 22,26 ----
       * @param clazz the class used to get the writer.
       * @return a Writer where the generated content will be written.
+      * @throws IOException if the writer can't be accessed.
       */
      public Writer getWriter(XClass clazz) throws IOException {
***************
*** 32,38 ****
       * @param classes the classes used to get the writer. This is where
       * the generated file will be written.
!      * @throws IOException if the file can't be written.
       */
      public Writer getWriter(Collection classes) throws IOException {
          throw new UnsupportedOperationException();
      }
--- 33,51 ----
       * @param classes the classes used to get the writer. This is where
       * the generated file will be written.
!      * @return a Writer where the generated content will be written.
!      * @throws IOException if the writer can't be accessed.
       */
      public Writer getWriter(Collection classes) throws IOException {
+         throw new UnsupportedOperationException();
+     }
+ 
+     /**
+      * Gets a writer corresponding to a Collection of custom objects of any class.
+      *
+      * @param o the object to generate for.
+      * @return a Writer where the generated content will be written.
+      * @throws IOException if the writer can't be accessed.
+      */
+     public Writer getWriter(Object o) throws IOException {
          throw new UnsupportedOperationException();
      }

Index: FileDestination.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet2/core/src/java/xdoclet/FileDestination.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** FileDestination.java        8 Nov 2002 02:26:06 -0000       1.1
--- FileDestination.java        22 Nov 2002 18:57:39 -0000      1.2
***************
*** 69,78 ****
  
      /**
!      * Returns the name of the file to generate for a particular class.
       * Substitutes the {0} String with the class name.
       *
       * @barter.pre isGenerationPerClass()
       * @param clazz the class for which we want the generated file name
!      * @return name of file to generate
       */
      protected String getFileName( XClass clazz ) {
--- 69,78 ----
  
      /**
!      * Returns the name of the file to generateForClasses for a particular class.
       * Substitutes the {0} String with the class name.
       *
       * @barter.pre isGenerationPerClass()
       * @param clazz the class for which we want the generated file name
!      * @return name of file to generateForClasses
       */
      protected String getFileName( XClass clazz ) {

Index: Generator.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet2/core/src/java/xdoclet/Generator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Generator.java      19 Nov 2002 22:08:43 -0000      1.2
--- Generator.java      22 Nov 2002 18:57:39 -0000      1.3
***************
*** 11,18 ****
  import java.io.*;
  import java.util.Collection;
  
  /**
   * A generator is responsible for generating content. It will typically
!  * be used to generate a file.
   * @author    <a href="mailto:[EMAIL PROTECTED]";>Aslak Helles&oslash;y</a>
   * @version   $Revision$
--- 11,19 ----
  import java.io.*;
  import java.util.Collection;
+ import java.util.Iterator;
  
  /**
   * A generator is responsible for generating content. It will typically
!  * be used to generateForClasses a file.
   * @author    <a href="mailto:[EMAIL PROTECTED]";>Aslak Helles&oslash;y</a>
   * @version   $Revision$
***************
*** 23,26 ****
--- 24,52 ----
      private final Collection _acceptedClasses;
  
+     /**
+      * This generation mode should be used when exactly one file should be generated 
+per class.
+      * See {@link xdoclet.generators.XMLGenerator} for an example.
+      */
+     protected static final int MODE_PER_CLASS = 0;
+ 
+     /**
+      * This generation mode should be used when exactly one file should be generated 
+per class.
+      * See {@link xdoclet.generators.SimpleJavaGenerator} for an example.
+       */
+     protected static final int MODE_FOR_ALL_CLASSES = 1;
+ 
+     /**
+      * This generation mode should be used when the number of files to generate does 
+not match
+      * the number of classes or is equal to one. See {@link 
+xdoclet.plugins.xmlFacade.XMLFacadeGenerator}
+      * for an example.
+      */
+     protected static final int MODE_CUSTOM = 2;
+ 
+     /**
+      * Constructor.
+      *
+      * @param destination specifies where the generated content should be written.
+      * @param acceptedClasses Collection of {@link XClass} that we're generating for.
+      */
      protected Generator(Destination destination, Collection acceptedClasses) {
          _destination = destination;
***************
*** 33,58 ****
  
      public void generate() throws XDocletException {
-               System.out.println("GENERATING");
-         if (isGenerationPerClass()) {
-             // Generate one file for each class.
-             for (ClassIterator classIterator = 
XCollections.classIterator(_acceptedClasses); classIterator.hasNext();) {
-                 XClass clazz = classIterator.next();
-                 generateFor( clazz );
-             }
-         } else {
-             // Only generate one file for all classes.
-             generateForAllAcceptedClasses();
-         }
-     }
- 
-     /**
-      * Generates content for a single class
-      *
-      * @param clazz the class to generate for.
-      */
-     private final void generateFor(XClass clazz) throws XDocletException {
-               System.out.println("GENERATING FOR " + clazz.getQualifiedName());
          try {
!             generate( clazz, _destination.getWriter(clazz));
          } catch( IOException e ) {
              throw new XDocletException(e.getMessage(), e);
--- 59,86 ----
  
      public void generate() throws XDocletException {
          try {
!             switch (getGenerationMode()) {
!                 case MODE_PER_CLASS:
!                     // Generate one file for each class.
!                     for (ClassIterator classIterator = 
XCollections.classIterator(_acceptedClasses); classIterator.hasNext();) {
!                         XClass clazz = classIterator.next();
!                         generateForClass( clazz, _destination.getWriter(clazz));
!                     }
!                     break;
! 
!                 case MODE_FOR_ALL_CLASSES:
!                     // Only generateForClasses one file for all classes.
!                     generateForClasses( _acceptedClasses, 
_destination.getWriter(_acceptedClasses));
!                     break;
! 
!                 case MODE_CUSTOM:
!                     for(Iterator i = getCustomObjects().iterator(); i.hasNext();) {
!                         Object o = i.next();
!                         generateForCustom(o, _destination.getWriter(o));
!                     }
!                     break;
!                 default:
!                     throw new IllegalStateException("Illegal Generation mode: " + 
getGenerationMode());
!             }
          } catch( IOException e ) {
              throw new XDocletException(e.getMessage(), e);
***************
*** 61,108 ****
  
      /**
!      * Generates content for a Collection of {@link XClass}
       */
!     private final void generateForAllAcceptedClasses() throws XDocletException {
!         try {
!             generate( _acceptedClasses, _destination.getWriter(_acceptedClasses));
!         } catch( IOException e ) {
!             throw new XDocletException(e.getMessage(), e);
!         }
      }
  
      /**
!      * Indicates whether this generator should generate one file per class or
!      * only one file for all classes. Depending on what this method returns,
!      * one of the following methods must be implemented:
       * <ul>
!      * <li>true -> {@link #generate(XClass, Writer)}</li>
!      * <li>false -> {@link #generate(Collection, Writer)}</li>
       * </ul>
       *
       * @return true if one file per class.
       */
!     protected abstract boolean isGenerationPerClass();
  
      /**
!      * Generates for all classes. Must be overridden if {@link 
#isGenerationPerClass()}
!      * is implemented to return false.
       *
!      * @param classes the classes to generate for.
       * @param writer where the generated content will be written.
       * @throws XDocletException if generation fails.
       */
!     protected void generate( Collection classes, Writer writer ) throws 
XDocletException {
          throw new UnsupportedOperationException();
      }
  
      /**
!      * Generates for one class. Must be overridden if {@link #isGenerationPerClass()}
!      * is implemented to return true.
       *
!      * @param clazz the class to generate for.
       * @param writer where the generated content will be written.
       * @throws XDocletException if generation fails.
       */
!     protected void generate( XClass clazz, Writer writer ) throws XDocletException {
          throw new UnsupportedOperationException();
      }
--- 89,165 ----
  
      /**
!      * Indicates whether this generator should generateForClasses one file per class 
or
!      * only one file for all classes. Depending on what this method returns,
!      * one of the following methods must be implemented:
!      * <ul>
!      * <li>true -> {@link #generateForClass(XClass, Writer)}</li>
!      * <li>false -> {@link #generateForClasses(Collection, Writer)}</li>
!      * </ul>
!      *
!      * @return true if one file per class.
       */
!     protected final boolean isGenerationPerClass() {
!         return false;
      }
  
      /**
!      * Returns the generation mode. Legal values are {@link #MODE_PER_CLASS},
!      * {@link #MODE_FOR_ALL_CLASSES} and {@link #MODE_CUSTOM}. Subclases must
!      * implement this method and return one of the legal values.
!      * Depending on what this method returns, one of the following methods must be 
implemented:
       * <ul>
!      * <li>MODE_PER_CLASS -> {@link #generateForClass(XClass, Writer)}</li>
!      * <li>MODE_FOR_ALL_CLASSES -> {@link #generateForClasses(Collection, 
Writer)}</li>
!      * <li>MODE_CUSTOM -> {@link #generateForCustom(Object, Writer)} and </li>
       * </ul>
       *
       * @return true if one file per class.
       */
!     protected abstract int getGenerationMode();
! 
!     /**
!      * Generates for all classes. Must be overridden if {@link #getGenerationMode()}
!      * is implemented to return {@link #MODE_PER_CLASS}.
!      *
!      * @param classes the classes to generateForClasses for.
!      * @param writer where the generated content will be written.
!      * @throws XDocletException if generation fails.
!      */
!     protected void generateForClasses( Collection classes, Writer writer ) throws 
XDocletException {
!         throw new UnsupportedOperationException();
!     }
  
      /**
!      * Generates for one class. Must be overridden if {@link #getGenerationMode()}
!      * is implemented to return {@link #MODE_FOR_ALL_CLASSES}.
       *
!      * @param clazz the class to generateForClasses for.
       * @param writer where the generated content will be written.
       * @throws XDocletException if generation fails.
       */
!     protected void generateForClass( XClass clazz, Writer writer ) throws 
XDocletException {
          throw new UnsupportedOperationException();
      }
  
      /**
!      * Generates for one class. Must be overridden if {@link #getGenerationMode()}
!      * is implemented to return {@link #MODE_CUSTOM}.
       *
!      * @param object the custom object to generateForClasses for.
       * @param writer where the generated content will be written.
       * @throws XDocletException if generation fails.
       */
!     protected void generateForCustom( Object object, Writer writer ) throws 
XDocletException {
!         throw new UnsupportedOperationException();
!     }
! 
!     /**
!      * Returns a Collection of custom objects to generate for. Must be overridden if 
{@link #getGenerationMode()}
!      * is implemented to return {@link #MODE_CUSTOM}. One file will be generated for 
each object in this collection.
!      *
!      * @return
!      * @throws XDocletException
!      */
!     protected Collection getCustomObjects()  throws XDocletException {
          throw new UnsupportedOperationException();
      }

Index: Plugin.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet2/core/src/java/xdoclet/Plugin.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** Plugin.java 19 Nov 2002 22:08:43 -0000      1.4
--- Plugin.java 22 Nov 2002 18:57:39 -0000      1.5
***************
*** 97,101 ****
  
      /**
!      * Returns a Collection of {@link Generator} that will be invoked to generate 
files.
       *
       * @return a Collection of {@link Generator}.
--- 97,101 ----
  
      /**
!      * Returns a Collection of {@link Generator} that will be invoked to 
generateForClasses files.
       *
       * @return a Collection of {@link Generator}.

--- XMLGenerator.java DELETED ---



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to