Update of /cvsroot/xdoclet/generama/src/main/java/org/generama
In directory sc8-pr-cvs1:/tmp/cvs-serv12006/main/java/org/generama

Modified Files:
        JellyPlugin.java Plugin.java VelocityPlugin.java 
Added Files:
        AbstractPlugin.java Generama.java MetadataProvider.java 
        WriterMapper.java 
Removed Files:
        AbstractJavaGeneratingPluginTestCase.java 
        AbstractPluginTestCase.java 
        AbstractTextGeneratingPluginTestCase.java 
        AbstractXMLGeneratingPluginTestCase.java 
Log Message:
More refactorings. Generama is nearly completely refactored and completed. All TDD.

--- NEW FILE: AbstractPlugin.java ---
package org.generama;

/**
 * 
 * @author Aslak Hellesøy
 * @version $Revision: 1.1 $
 */
public abstract class AbstractPlugin implements Plugin {
    private String fileName;

    public boolean isGeneratePerElementInMetadataCollection() {
        if(fileName == null) {
            throw new RuntimeException("fileName was not set");
        }
        // Once per element if there is a {0}
        return fileName.indexOf("{0}") != -1;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }
}

--- NEW FILE: Generama.java ---
package org.generama;

import java.util.*;
import java.io.IOException;
import java.io.Writer;

/**
 *
 * @author Aslak Hellesøy
 * @version $Revision: 1.1 $
 */
public class Generama {
    private final Map plugins = new HashMap();
    private final MetadataProvider metadataProvider;

    public Generama(MetadataProvider metadataProvider) {
        this.metadataProvider = metadataProvider;
    }

    public void addPlugin(Plugin plugin, WriterMapper writerMapper) {
        plugins.put(plugin, writerMapper);
    }

    public void execute() throws IOException, GeneramaException {
        Collection metadata = metadataProvider.createMetadata();

        for (Iterator i = plugins.keySet().iterator(); i.hasNext();) {
            Plugin plugin = (Plugin) i.next();

            if (plugin.isGeneratePerElementInMetadataCollection()) {
                for (Iterator iterator = metadata.iterator(); iterator.hasNext();) {
                    Object meta = (Object) iterator.next();
                    plugin.generate(getWriter(plugin, meta), meta);
                }
            } else {
                plugin.generate(getWriter(plugin, metadata), metadata);
            }
        }
    }

    private Writer getWriter(Plugin plugin, Object metadata) {
        WriterMapper mapper = (WriterMapper) plugins.get(plugin);
        if( mapper != null ) {
            return mapper.getWriter(metadata);
        } else {
            return null;
        }
    }
}

--- NEW FILE: MetadataProvider.java ---
package org.generama;

import java.util.Collection;

/**
 *
 * @author Aslak Hellesøy
 * @version $Revision: 1.1 $
 */
public interface MetadataProvider {
    public Collection createMetadata();
}

--- NEW FILE: WriterMapper.java ---
package org.generama;

import java.io.Writer;

/**
 * 
 * @author Aslak Hellesøy
 * @version $Revision: 1.1 $
 */
public interface WriterMapper {
    Writer getWriter(Object metadata);
}

Index: JellyPlugin.java
===================================================================
RCS file: /cvsroot/xdoclet/generama/src/main/java/org/generama/JellyPlugin.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** JellyPlugin.java    17 Aug 2003 18:32:43 -0000      1.1
--- JellyPlugin.java    20 Aug 2003 14:21:16 -0000      1.2
***************
*** 1,6 ****
  package org.generama;
  
- import org.generama.Plugin;
- import org.generama.GeneramaException;
  import org.dom4j.io.OutputFormat;
  import org.dom4j.io.XMLWriter;
--- 1,4 ----
***************
*** 19,23 ****
   * @version $Revision$
   */
! public class JellyPlugin implements Plugin {
      public final void generate(Writer out, Object metadata) throws IOException, 
GeneramaException {
          JellyContext context = new JellyContext();
--- 17,21 ----
   * @version $Revision$
   */
! public class JellyPlugin extends AbstractPlugin {
      public final void generate(Writer out, Object metadata) throws IOException, 
GeneramaException {
          JellyContext context = new JellyContext();

Index: Plugin.java
===================================================================
RCS file: /cvsroot/xdoclet/generama/src/main/java/org/generama/Plugin.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** Plugin.java 17 Aug 2003 18:11:51 -0000      1.1
--- Plugin.java 20 Aug 2003 14:21:16 -0000      1.2
***************
*** 3,7 ****
  import java.io.Writer;
  import java.io.IOException;
- import java.util.Collection;
  
  /**
--- 3,6 ----
***************
*** 12,14 ****
--- 11,14 ----
  public interface Plugin {
      void generate(Writer out, Object metadata) throws IOException, GeneramaException;
+     boolean isGeneratePerElementInMetadataCollection();
  }

Index: VelocityPlugin.java
===================================================================
RCS file: /cvsroot/xdoclet/generama/src/main/java/org/generama/VelocityPlugin.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** VelocityPlugin.java 17 Aug 2003 18:32:43 -0000      1.1
--- VelocityPlugin.java 20 Aug 2003 14:21:16 -0000      1.2
***************
*** 1,6 ****
  package org.generama;
  
- import org.generama.Plugin;
- import org.generama.GeneramaException;
  import org.apache.velocity.VelocityContext;
  import org.apache.velocity.app.VelocityEngine;
--- 1,4 ----
***************
*** 9,13 ****
  import java.io.Writer;
  import java.io.IOException;
- import java.util.Collection;
  
  /**
--- 7,10 ----
***************
*** 16,20 ****
   * @version $Revision$
   */
! public abstract class VelocityPlugin implements Plugin {
      private VelocityComponent velocityComponent;
  
--- 13,17 ----
   * @version $Revision$
   */
! public abstract class VelocityPlugin extends AbstractPlugin {
      private VelocityComponent velocityComponent;
  

--- AbstractJavaGeneratingPluginTestCase.java DELETED ---

--- AbstractPluginTestCase.java DELETED ---

--- AbstractTextGeneratingPluginTestCase.java DELETED ---

--- AbstractXMLGeneratingPluginTestCase.java DELETED ---



-------------------------------------------------------
This SF.net email is sponsored by Dice.com.
Did you know that Dice has over 25,000 tech jobs available today? From
careers in IT to Engineering to Tech Sales, Dice has tech jobs from the
best hiring companies. http://www.dice.com/index.epl?rel_code=104
_______________________________________________
xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to