Author: sshafroi
Date: 2008-03-31 16:28:06 +0200 (Mon, 31 Mar 2008)
New Revision: 6321

Added:
   branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateSchemaFile.java
Modified:
   
branches/2.16/mojo/src/main/java/no/sesat/mojo/SearchModesSchemaGenerator.java
   branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/Builder.java
   branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/ConfigAbstract.java
   branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/ConfigAttribute.java
   branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/ConfigElement.java
   branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateDTD.java
   branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateFile.java
   branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateRelaxNG.java
   branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateXSD.java
   branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/NameFilter.java
Log:
added comments and fixed 'checkstyle'

Modified: 
branches/2.16/mojo/src/main/java/no/sesat/mojo/SearchModesSchemaGenerator.java
===================================================================
--- 
branches/2.16/mojo/src/main/java/no/sesat/mojo/SearchModesSchemaGenerator.java  
    2008-03-31 08:58:58 UTC (rev 6320)
+++ 
branches/2.16/mojo/src/main/java/no/sesat/mojo/SearchModesSchemaGenerator.java  
    2008-03-31 14:28:06 UTC (rev 6321)
@@ -16,68 +16,75 @@
  */
 public class SearchModesSchemaGenerator extends AbstractMojo {
 
-       /**
-        * The maven project.
-        * 
-        * @parameter expression="${project}"
-        * @required
-        * @readonly
-        * @description "the maven project to use"
-        */
-       private MavenProject project;
+    /**
+     * The Maven project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     * @description "the maven project to use"
+     */
+    private MavenProject project;
 
-       /**
-        * Classpath
-        * 
-        * @parameter
-        */
-       private List<String> classpaths;
+    /**
+     * Classpath
+     *
+     * @parameter
+     */
+    private List<String> classpaths;
 
-       /**
-        * Output directory
-        * 
-        * @parameter
-        */
-       private String outputDir;
+    /**
+     * Output directory
+     *
+     * @parameter
+     */
+    private String outputDir;
 
-       public void execute() throws MojoExecutionException {
-               getLog().info(this.getClass().getName());
+    /**
+     * @see org.apache.maven.plugin.Mojo#execute()
+     */
+    public void execute() throws MojoExecutionException {
+        getLog().info(this.getClass().getName());
 
-               if (classpaths == null)
-                       getLog().error("classpaths variable must be specified");
+        if (classpaths == null) {
+            getLog().error("classpaths variable must be specified");
+        }
 
-               if (outputDir == null)
-                       getLog().error("outputDir variable must be specified");
+        if (outputDir == null) {
+            getLog().error("outputDir variable must be specified");
+        }
 
-               String classpath = "";
-               for (Iterator<String> iterator = classpaths.iterator(); 
iterator.hasNext();) {
-                       String name = (String) iterator.next();
-                       File file = new File(name);
-                       if (!file.isAbsolute()) {
-                               file = new File(project.getBasedir(), name);
-                       }
-                       if (file.exists()) {
-                               try {
-                                       classpath += file.getCanonicalPath() + 
File.separator;
-                               } catch (IOException e) {
-                                       getLog().warn(e);
-                               }
-                               if (iterator.hasNext())
-                                       classpath += File.pathSeparator;
-                       } else {
-                               getLog().warn("Classpath not found : " + 
file.getAbsolutePath());
-                       }
-               }
+        String classpath = "";
+        for (final Iterator<String> iterator = classpaths.iterator(); 
iterator.hasNext();) {
+            final String name = iterator.next();
+            File file = new File(name);
+            if (!file.isAbsolute()) {
+                file = new File(project.getBasedir(), name);
+            }
+            if (file.exists()) {
+                try {
+                    classpath += file.getCanonicalPath() + File.separator;
+                } catch (IOException e) {
+                    getLog().warn(e);
+                }
+                if (iterator.hasNext()) {
+                    classpath += File.pathSeparator;
+                }
+            } else {
+                getLog().warn("Classpath not found : " + 
file.getAbsolutePath());
+            }
+        }
 
-               File outputDirFile = new File(outputDir);
-               if (!outputDirFile.isAbsolute())
-                       outputDirFile = new File(project.getBasedir(), 
outputDir);
+        File outputDirFile = new File(outputDir);
+        if (!outputDirFile.isAbsolute()) {
+            outputDirFile = new File(project.getBasedir(), outputDir);
+        }
 
-               outputDir = outputDirFile.getAbsolutePath();
+        outputDir = outputDirFile.getAbsolutePath();
 
-               getLog().info("Using: classpath = " + classpath);
-               getLog().info("Using: outputDir = " + outputDir);
+        getLog().info("Using: classpath = " + classpath);
+        getLog().info("Using: outputDir = " + outputDir);
 
-               Builder.Build(classpath, outputDir);
-       }
-}
\ No newline at end of file
+        Builder.build(classpath, outputDir, project.getName());
+    }
+}

Modified: branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/Builder.java
===================================================================
--- branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/Builder.java   
2008-03-31 08:58:58 UTC (rev 6320)
+++ branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/Builder.java   
2008-03-31 14:28:06 UTC (rev 6321)
@@ -19,198 +19,206 @@
 import com.sun.tools.javadoc.ModifierFilter;
 import com.sun.tools.javadoc.RootDocImpl;
 
-public class Builder {
+/**
+ * Builder to build a structure that mirrors the structure that should be used
+ * in the modes.xml files. *
+ */
+public final class Builder {
 
-       private static String outputDir = "";
-       
-       /**
+    private static String outputDir = "";
+    private static String id = "";
+
+    private Builder() {
+    }
+
+    /**
      * Build and generate schema for modes.xml files.
-     * 
+     *
      * @param classpath
      *            Where to find the classes
-     * @param outputDir
+     * @param dir
      *            Where the results should be put
+     * @param idString
+     *            Id
      */
-       public static void Build(String classpath, String outputDir) {
-               Builder.outputDir = new File(outputDir).getAbsolutePath() + 
File.separator;
+    public static void build(final String classpath, final String dir, final 
String idString) {
+        outputDir = new File(dir).getAbsolutePath() + File.separator;
+        id = idString;
 
-               // hack to supress javadoc's warnings.
-               PrintStream out = System.out;
-               PrintStream err = System.err;
-               System.setOut(new PrintStream(new ByteArrayOutputStream()));
-               System.setErr(new PrintStream(new ByteArrayOutputStream()));
+        // hack to suppress javadoc's warnings.
+        final PrintStream out = System.out;
+        final PrintStream err = System.err;
+        System.setOut(new PrintStream(new ByteArrayOutputStream()));
+        System.setErr(new PrintStream(new ByteArrayOutputStream()));
 
-               Context context = new Context();
-               Messager.preRegister(context, "Builder");
-               JavadocTool comp = JavadocTool.make0(context);
+        final Context context = new Context();
+        Messager.preRegister(context, "Builder");
+        final JavadocTool comp = JavadocTool.make0(context);
 
-               ListBuffer<String> subPackages = new ListBuffer<String>();
-               subPackages.append("no");
-               ListBuffer<String> xcludePackages = new ListBuffer<String>();
-               ListBuffer<String> javaNames = new ListBuffer<String>();
-               ListBuffer<String[]> options = new ListBuffer<String[]>();
+        final ListBuffer<String> subPackages = new ListBuffer<String>();
+        subPackages.append("no");
+        final ListBuffer<String> xcludePackages = new ListBuffer<String>();
+        final ListBuffer<String> javaNames = new ListBuffer<String>();
+        final ListBuffer<String[]> options = new ListBuffer<String[]>();
 
-               Options compOpts = Options.instance(context);
-               compOpts.put("-classpath", classpath);
+        final Options compOpts = Options.instance(context);
+        compOpts.put("-classpath", classpath);
 
-               RootDocImpl root = null;
-               try {
-                       root = comp.getRootDocImpl("", "", new 
ModifierFilter(PUBLIC | PROTECTED), javaNames.toList(), options.toList(), 
false, subPackages.toList(),
-                                       xcludePackages.toList(), false, false, 
false);
-               } catch (IOException e) {
-                       e.printStackTrace();
-               }
+        RootDocImpl root = null;
+        try {
+            root = comp.getRootDocImpl("", "", new ModifierFilter(PUBLIC | 
PROTECTED), javaNames.toList(), options
+                    .toList(), false, subPackages.toList(), 
xcludePackages.toList(), false, false, false);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
 
-               System.setOut(out);
-               System.setErr(err);
+        System.setOut(out);
+        System.setErr(err);
 
-               if (root != null)
-                       start(root);
-       }
+        if (root != null) {
+            start(root);
+        }
+    }
 
-       /**
+    /**
      * This is the entry point for a doclet.
-     * 
+     *
      * @param root
      *            Root document
-     * @return
+     * @return true when everything is ok
      */
-    public static boolean start(RootDoc root) {
-               ConfigElement defaultConvert = new 
ConfigElement("default-convert");
-               defaultConvert.attributes.add(new ConfigAttribute("name"));
-               defaultConvert.attributes.add(new ConfigAttribute("prefix"));
-               defaultConvert.attributes.add(new ConfigAttribute("postfix"));
+    public static boolean start(final RootDoc root) {
+        final ConfigElement defaultConvert = new 
ConfigElement("default-convert");
+        defaultConvert.attributes.add(new ConfigAttribute("name"));
+        defaultConvert.attributes.add(new ConfigAttribute("prefix"));
+        defaultConvert.attributes.add(new ConfigAttribute("postfix"));
 
-               Vector<ConfigElement> commands = new Vector<ConfigElement>();
-               Vector<ConfigElement> resultHandlers = new 
Vector<ConfigElement>();
-               Vector<ConfigElement> queryTransformers = new 
Vector<ConfigElement>();
-               {
-                       ClassDoc[] classes = root.classes();
-                       for (int i = 0; i < classes.length; i++) {
-                               String name = classes[i].name();
-                               if (name.endsWith("Config") && 
!classes[i].isAbstract()) {
-                                       ConfigElement element = new 
ConfigElement(classes[i]);
+        final Vector<ConfigElement> commands = new Vector<ConfigElement>();
+        final Vector<ConfigElement> resultHandlers = new 
Vector<ConfigElement>();
+        final Vector<ConfigElement> queryTransformers = new 
Vector<ConfigElement>();
+        {
+            final ClassDoc[] classes = root.classes();
+            for (int i = 0; i < classes.length; i++) {
+                final String name = classes[i].name();
+                if (name.endsWith("Config") && !classes[i].isAbstract()) {
+                    final ConfigElement element = new 
ConfigElement(classes[i]);
 
-                                       if (name.endsWith("CommandConfig")) {
-                                               element.applyNameFilter(new 
NameFilter() {
-                                                       public String 
filter(String name) {
-                                                               name = 
name.substring(0, name.lastIndexOf("Config"));
-                                                               String res = 
toXmlName(name);
-                                                               return res;
-                                                       }
-                                               });
-                                               commands.add(element);
-                                       } else if 
(name.endsWith("ResultHandlerConfig")) {
-                                               element.applyNameFilter(new 
NameFilter() {
-                                                       public String 
filter(String name) {
-                                                               name = 
name.substring(0, name.lastIndexOf("ResultHandlerConfig"));
-                                                               String res = 
toXmlName(name);
-                                                               return res;
-                                                       }
-                                               });
-                                               if (!element.name.isEmpty())
-                                                       
resultHandlers.add(element);
-                                       } else if 
(name.endsWith("QueryTransformer") || 
(name.endsWith("QueryTransformerConfig"))) {
-                                               element.applyNameFilter(new 
NameFilter() {
-                                                       public String 
filter(String name) {
-                                                               name = 
name.substring(0, name.lastIndexOf("QueryTransformer"));
-                                                               String res = 
toXmlName(name);
-                                                               return res;
-                                                       }
-                                               });
+                    if (name.endsWith("CommandConfig")) {
+                        element.applyNameFilter(new NameFilter() {
+                            public String filter(final String name) {
+                                return toXmlName(name.substring(0, 
name.lastIndexOf("Config")));
+                            }
+                        });
+                        commands.add(element);
+                    } else if (name.endsWith("ResultHandlerConfig")) {
+                        element.applyNameFilter(new NameFilter() {
+                            public String filter(final String name) {
+                                return toXmlName(name.substring(0, 
name.lastIndexOf("ResultHandlerConfig")));
+                            }
+                        });
+                        if (!element.name.isEmpty()) {
+                            resultHandlers.add(element);
+                        }
+                    } else if (name.endsWith("QueryTransformer") || 
(name.endsWith("QueryTransformerConfig"))) {
+                        element.applyNameFilter(new NameFilter() {
+                            public String filter(final String name) {
+                                return toXmlName(name.substring(0, 
name.lastIndexOf("QueryTransformer")));
+                            }
+                        });
 
-                                               if 
(name.equals("NewsCaseQueryTransformerConfig")) {
-                                                       
element.addChild(defaultConvert);
-                                               }
+                        if (name.equals("NewsCaseQueryTransformerConfig")) {
+                            element.addChild(defaultConvert);
+                        }
 
-                                               queryTransformers.add(element);
-                                       } else {
-                                               System.out.println("Lost: " + 
element.name);
-                                       }
-                               }
-                       }
-               }
+                        queryTransformers.add(element);
+                    } else {
+                        System.out.println("Lost: " + element.name);
+                    }
+                }
+            }
+        }
 
-               ConfigElement modes = new ConfigElement("modes");
-               modes.attributes.add(new ConfigAttribute("template-prefix"));
+        final ConfigElement modes = new ConfigElement("modes");
+        modes.attributes.add(new ConfigAttribute("template-prefix"));
 
-               ConfigElement mode = new ConfigElement("mode");
-               mode.attributes.add(new ConfigAttribute("id"));
-               mode.attributes.add(new ConfigAttribute("inherit"));
-               mode.attributes.add(new ConfigAttribute("analysis"));
-               mode.attributes.add(new ConfigAttribute("executor"));
+        final ConfigElement mode = new ConfigElement("mode");
+        mode.attributes.add(new ConfigAttribute("id"));
+        mode.attributes.add(new ConfigAttribute("inherit"));
+        mode.attributes.add(new ConfigAttribute("analysis"));
+        mode.attributes.add(new ConfigAttribute("executor"));
 
-               mode.addChildren(commands);
-               modes.addChild(mode);
+        mode.addChildren(commands);
+        modes.addChild(mode);
 
-               ConfigElement resultHandler = new 
ConfigElement("result-handlers");
-               resultHandler.addChildren(resultHandlers);
+        final ConfigElement resultHandler = new 
ConfigElement("result-handlers");
+        resultHandler.addChildren(resultHandlers);
 
-               ConfigElement queryTransform = new 
ConfigElement("query-transformers");
-               queryTransform.addChildren(queryTransformers);
+        final ConfigElement queryTransform = new 
ConfigElement("query-transformers");
+        queryTransform.addChildren(queryTransformers);
 
-               ConfigElement navigators = new ConfigElement("navigators");
-               ConfigElement navigator = new ConfigElement("navigator");
-               navigator.attributes.add(new ConfigAttribute("id", null, true));
-               navigator.attributes.add(new ConfigAttribute("name", null, 
true));
-               navigator.attributes.add(new ConfigAttribute("field", null, 
true));
-               navigator.attributes.add(new ConfigAttribute("display-name", 
null, true));
-               navigator.attributes.add(new ConfigAttribute("sort", null, 
false));
-               navigator.attributes.add(new ConfigAttribute("boundary-match"));
+        final ConfigElement navigators = new ConfigElement("navigators");
+        final ConfigElement navigator = new ConfigElement("navigator");
+        navigator.attributes.add(new ConfigAttribute("id", null, true));
+        navigator.attributes.add(new ConfigAttribute("name", null, true));
+        navigator.attributes.add(new ConfigAttribute("field", null, true));
+        navigator.attributes.add(new ConfigAttribute("display-name", null, 
true));
+        navigator.attributes.add(new ConfigAttribute("sort", null, false));
+        navigator.attributes.add(new ConfigAttribute("boundary-match"));
 
-               // only for fast commands
-               navigators.addChild(navigator);
+        // only for fast commands
+        navigators.addChild(navigator);
 
-               for (ConfigElement command : commands) {
-                       command.addChild(resultHandler);
-                       command.addChild(queryTransform);
-                       command.addChild(navigators);
-               }
+        for (ConfigElement command : commands) {
+            command.addChild(resultHandler);
+            command.addChild(queryTransform);
+            command.addChild(navigators);
+        }
 
-               Runnable jobs[] = { new GenerateRelaxNG(modes, outputDir + 
"modes.rnc"), new GenerateXSD(modes, outputDir + "modes.xsd"),
-                               new GenerateDTD(modes, outputDir + "modes.dtd") 
};
-               int jobCount = 5;
-               for (int i = 0; i < (jobs.length + jobCount - 1); i++) {
+        final Runnable[] jobs = {new GenerateRelaxNG(modes, outputDir + 
"modes.rnc", id),
+                new GenerateXSD(modes, outputDir + "modes.xsd", id),
+                new GenerateDTD(modes, outputDir + "modes.dtd", id)};
+        final int jobCount = 5;
+        for (int i = 0; i < (jobs.length + jobCount - 1); i++) {
 
-                       if (i < jobs.length) {
-                               // System.out.println("start job: " + i);
-                               Thread thread = new Thread(jobs[i]);
-                               thread.start();
-                               jobs[i] = thread;
-                       }
-                       if (i >= (jobCount - 1)) {
-                               try {
-                                       ((Thread) jobs[i - jobCount + 
1]).join();
-                                       // System.out.println("job done: " + (i 
- jobCount + 1));
-                               } catch (InterruptedException e) {
-                                       e.printStackTrace();
-                               }
-                       }
-               }
+            if (i < jobs.length) {
+                // System.out.println("start job: " + i);
+                final Thread thread = new Thread(jobs[i]);
+                thread.start();
+                jobs[i] = thread;
+            }
+            if (i >= (jobCount - 1)) {
+                try {
+                    ((Thread) jobs[i - jobCount + 1]).join();
+                    // System.out.println("job done: " + (i - jobCount + 1));
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
 
-               System.out.println("commands : " + commands.size());
-               System.out.println("result handlers : " + 
resultHandlers.size());
-               System.out.println("query transformers : " + 
queryTransformers.size());
+        System.out.println("commands : " + commands.size());
+        System.out.println("result handlers : " + resultHandlers.size());
+        System.out.println("query transformers : " + queryTransformers.size());
 
-               return true;
-       }
+        return true;
+    }
 
-       /**
+    /**
      * Helper function to convert a java name to the equivalent XML name.
-     * 
+     *
      * @param name
-     *            Name that shouold be converted
+     *            Name that should be converted
      * @return The name converted like this MySuperClass --> my-super-class
      */
     public static String toXmlName(final String name) {
-               final StringBuilder xmlName = new StringBuilder(name);
-               for (int i = 0; i < xmlName.length(); ++i) {
-                       final char c = xmlName.charAt(i);
-                       if (Character.isUpperCase(c)) {
-                               xmlName.replace(i, i + 1, (i == 0 ? "" : "-") + 
Character.toLowerCase(c));
-                               ++i;
-                       }
-               }
-               return xmlName.toString();
-       }
-}
\ No newline at end of file
+        final StringBuilder xmlName = new StringBuilder(name);
+        for (int i = 0; i < xmlName.length(); ++i) {
+            final char c = xmlName.charAt(i);
+            if (Character.isUpperCase(c)) {
+                xmlName.replace(i, i + 1, (i == 0 ? "" : "-") + 
Character.toLowerCase(c));
+                ++i;
+            }
+        }
+        return xmlName.toString();
+    }
+}

Modified: 
branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/ConfigAbstract.java
===================================================================
--- branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/ConfigAbstract.java    
2008-03-31 08:58:58 UTC (rev 6320)
+++ branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/ConfigAbstract.java    
2008-03-31 14:28:06 UTC (rev 6321)
@@ -1,10 +1,17 @@
 package no.sesat.mojo.modes;
 
+/**
+ *
+ *
+ */
 public class ConfigAbstract {
-       protected String doc;
-       protected String name;
+    protected String doc;
+    protected String name;
 
-       public boolean hasDoc() {
-               return (doc != null && doc.trim().isEmpty() == false);
-       }
+    /**
+     * @return true if it has documentation.
+     */
+    public boolean hasDoc() {
+        return (doc != null && !doc.trim().isEmpty());
+    }
 }

Modified: 
branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/ConfigAttribute.java
===================================================================
--- branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/ConfigAttribute.java   
2008-03-31 08:58:58 UTC (rev 6320)
+++ branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/ConfigAttribute.java   
2008-03-31 14:28:06 UTC (rev 6321)
@@ -2,40 +2,66 @@
 
 import com.sun.javadoc.MethodDoc;
 
+/**
+ * Data representing an attribute.
+ *
+ */
 public class ConfigAttribute extends ConfigAbstract {
-       protected String type = "CDATA";
-       protected boolean required = false;
 
-       public ConfigAttribute(MethodDoc method) {
-               doc = parseDoc(method);
+    protected String type = "CDATA";
+    protected boolean required = false;
 
-               name = Builder.toXmlName(method.name()).substring(4);
-               type = "CDATA"; // method.parameters()[0].toString();
-       }
+    /**
+     * @param method Construct this attribute from a Javadoc element.
+     */
+    public ConfigAttribute(final MethodDoc method) {
+        doc = parseDoc(method);
 
-       protected ConfigAttribute(String name) {
-               this.name = name;
-       }
+        name = Builder.toXmlName(method.name()).substring(4);
+        type = "CDATA"; // method.parameters()[0].toString();
+    }
 
-       protected ConfigAttribute(String name, String doc) {
-               this.name = name;
-               this.doc = doc;
-       }
+    /**
+     * @param name
+     *            Name of this attribute.
+     */
+    protected ConfigAttribute(final String name) {
+        this.name = name;
+    }
 
-       protected ConfigAttribute(String name, String doc, boolean required) {
-               this.name = name;
-               this.doc = doc;
-               this.required = required;
-       }
+    /**
+     * @param name
+     *            Name of this attribute.
+     * @param doc
+     *            Doc for this attribute.
+     */
+    protected ConfigAttribute(final String name, final String doc) {
+        this.name = name;
+        this.doc = doc;
+    }
 
-       private String parseDoc(MethodDoc method) {
-               if (method == null)
-                       return null;
-               if (method.commentText().contains("[EMAIL PROTECTED]"))
-                       return parseDoc(method.overriddenMethod());
-               else
-                       return method.commentText();
+    /**
+     * @param name
+     *            Name of this attribute.
+     * @param doc
+     *            Doc for this attribute.
+     * @param required
+     *            if this is required attribute or not
+     */
+    protected ConfigAttribute(final String name, final String doc, final 
boolean required) {
+        this.name = name;
+        this.doc = doc;
+        this.required = required;
+    }
 
-       }
-
+    private String parseDoc(final MethodDoc method) {
+        if (method == null) {
+            return null;
+        }
+        if (method.commentText().contains("[EMAIL PROTECTED]")) {
+            return parseDoc(method.overriddenMethod());
+        } else {
+            return method.commentText();
+        }
+    }
 }

Modified: 
branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/ConfigElement.java
===================================================================
--- branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/ConfigElement.java     
2008-03-31 08:58:58 UTC (rev 6320)
+++ branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/ConfigElement.java     
2008-03-31 14:28:06 UTC (rev 6321)
@@ -9,64 +9,81 @@
 import com.sun.javadoc.MethodDoc;
 import com.sun.javadoc.Parameter;
 
+/**
+ * Represent a class/xml element.
+ *
+ */
 public class ConfigElement extends ConfigAbstract {
 
-       final protected List<ConfigAttribute> attributes = new 
Vector<ConfigAttribute>();
-       final private Set<String> attribNames = new TreeSet<String>();
-       final protected int id;
-       private static int idCounter = 0;
+    protected final List<ConfigAttribute> attributes = new 
Vector<ConfigAttribute>();
+    private final Set<String> attribNames = new TreeSet<String>();
+    protected final int id;
+    private static int idCounter = 0;
 
-       protected List<ConfigElement> children = new Vector<ConfigElement>();
+    protected List<ConfigElement> children = new Vector<ConfigElement>();
 
-       public ConfigElement(String name) {
-               id = ++idCounter;
-               this.name = name;
-       }
+    /**
+     * @param name Name of this element.
+     */
+    public ConfigElement(final String name) {
+        id = ++idCounter;
+        this.name = name;
+    }
 
-       public ConfigElement(ClassDoc klass) {
-               this(klass.name());
+    /**
+     * @param klass Class that this element should be based on.
+     */
+    public ConfigElement(final ClassDoc klass) {
+        this(klass.name());
 
-               doc = klass.commentText();
+        doc = klass.commentText();
 
-               // some fake attributes
-               attributes.add(new ConfigAttribute("id", "fix doc", true));
-               attributes.add(new ConfigAttribute("inherit"));
-               attributes.add(new ConfigAttribute("result-fields"));
-               attributes.add(new ConfigAttribute("field-filters"));
-               attributes.add(new ConfigAttribute("collections"));
-               build(klass);
-       }
+        // some fake attributes
+        attributes.add(new ConfigAttribute("inherit"));
 
-       public void applyNameFilter(NameFilter filter) {
-               name = filter.filter(name);
-       }
+        build(klass);
+    }
 
-       public void addChildren(List<ConfigElement> children) {
-               this.children.addAll(children);
-       }
+    /**
+     * @param filter filter used to modify the name
+     */
+    public void applyNameFilter(final NameFilter filter) {
+        name = filter.filter(name);
+    }
 
-       public void addChild(ConfigElement child) {
-               this.children.add(child);
-       }
+    /**
+     * @param childrenList children that we want to add.
+     */
+    public void addChildren(final List<ConfigElement> childrenList) {
+        children.addAll(childrenList);
+    }
 
-       private void build(ClassDoc klass) {
+    /**
+     * @param child child that we want to add.
+     */
+    public void addChild(final ConfigElement child) {
+        children.add(child);
+    }
 
-               if (klass != null) {
-                       MethodDoc[] methods = klass.methods();
-                       for (int i = 0; i < methods.length; i++) {
+    private void build(final ClassDoc klass) {
 
-                               MethodDoc methodDoc = methods[i];
+        if (klass != null) {
+            final MethodDoc[] methods = klass.methods();
+            for (int i = 0; i < methods.length; i++) {
 
-                               if (!attribNames.contains(methodDoc.name()) && 
(methodDoc.name().startsWith("set") || methodDoc.name().startsWith("add"))) {
-                                       Parameter parameters[] = 
methodDoc.parameters();
-                                       if (parameters.length == 1) {
-                                               
attribNames.add(methodDoc.name());
-                                               attributes.add(new 
ConfigAttribute(methodDoc));
+                final MethodDoc methodDoc = methods[i];
 
-                                       }
-                               }
-                       }
-                       build(klass.superclass());
-               }
-       }
-}
\ No newline at end of file
+                if (!attribNames.contains(methodDoc.name())
+                        && (methodDoc.name().startsWith("set") || 
methodDoc.name().startsWith("add"))) {
+                    final Parameter[] parameters = methodDoc.parameters();
+                    if (parameters.length == 1) {
+                        attribNames.add(methodDoc.name());
+                        attributes.add(new ConfigAttribute(methodDoc));
+
+                    }
+                }
+            }
+            build(klass.superclass());
+        }
+    }
+}

Modified: branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateDTD.java
===================================================================
--- branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateDTD.java       
2008-03-31 08:58:58 UTC (rev 6320)
+++ branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateDTD.java       
2008-03-31 14:28:06 UTC (rev 6321)
@@ -5,73 +5,86 @@
 import java.util.Set;
 import java.util.TreeSet;
 
-public class GenerateDTD extends GenerateFile implements Runnable {
+/**
+ * Generator for DTD.
+ *
+ */
+public class GenerateDTD extends GenerateSchemaFile {
+    private final Set<String> written = new TreeSet<String>();
 
-       private final ConfigElement root;
-       private final String fileName;
-       private Set<String> written = new TreeSet<String>();
+    /**
+     * @param element
+     *            Root element.
+     * @param name
+     *            File name.
+     * @param idString
+     *            id.
+     */
+    public GenerateDTD(final ConfigElement element, final String name, final 
String idString) {
+        super(element, name, idString);
+    }
 
-       public GenerateDTD(ConfigElement element, String name) {
-               fileName = name;
-               root = element;
-       }
+    /**
+     * Generate DTD.
+     */
+    @Override
+    public void runImpl() {
+        println("<?xml version='1.0' encoding='UTF-8'?>\n");
+        println("<!-- " + id + " -->");
+        generate(root);
+    }
 
-       public void run() {
-               init(fileName);
-               println("<?xml version='1.0' encoding='UTF-8'?>\n");
-               generate(root);
-               done();
-       }
+    private void generate(final ConfigElement element) {
+        if (written.add(element.name)) {
 
-       private void generate(ConfigElement element) {
-               if (written.add(element.name)) {
+            if (element.hasDoc()) {
+                println("<!-- " + element.doc + " -->");
+            }
 
-                       if (element.hasDoc())
-                               println("<!-- " + element.doc + " -->");
+            print("<!ELEMENT " + element.name);
+            if (element.children.isEmpty()) {
+                print(" EMPTY");
+            } else {
+                print(" (");
+                for (int i = 0; i < element.children.size(); i++) {
+                    if (i > 0) {
+                        print("|");
+                    }
+                    print(element.children.get(i).name);
+                }
+                print(")*");
+            }
+            println(">");
 
-                       print("<!ELEMENT " + element.name);
-                       if (element.children.isEmpty())
-                               print(" EMPTY");
-                       else {
-                               print(" (");
-                               for (int i = 0; i < element.children.size(); 
i++) {
-                                       if (i > 0)
-                                               print("|");
-                                       print(element.children.get(i).name);
-                                       ;
-                               }
-                               print(")*");
-                       }
-                       println(">");
+            generate(element.attributes);
+            printlnI("<!ATTLIST " + element.name + " ");
+            for (final Iterator<ConfigAttribute> iterator = 
element.attributes.iterator(); iterator.hasNext();) {
+                final ConfigAttribute attrib = iterator.next();
+                print(attrib.name + " ");
+                generate(attrib);
+            }
+            printlnU(">");
 
-                       generate(element.attributes);
-                       printlnI("<!ATTLIST " + element.name + " ");
-                       for (Iterator<ConfigAttribute> iterator = 
element.attributes.iterator(); iterator.hasNext();) {
-                               ConfigAttribute attrib = (ConfigAttribute) 
iterator.next();
-                               print(attrib.name + " ");
-                               generate(attrib);
-                       }
-                       printlnU(">");
+            for (int i = 0; i < element.children.size(); i++) {
+                generate(element.children.get(i));
+            }
+        }
+    }
 
-                       for (int i = 0; i < element.children.size(); i++) {
-                               generate(element.children.get(i));
-                       }
-               }
-       }
+    private void generate(final ConfigAttribute attrib) {
+        println(attrib.type + " " + (attrib.required ? "#REQUIRED" : 
"#IMPLIED"));
+    }
 
-       private void generate(ConfigAttribute attrib) {
-               println(attrib.type + " " + (attrib.required ? "#REQUIRED" : 
"#IMPLIED"));
-       }
-
-       private void generate(List<ConfigAttribute> attributes) {
-               println("<!--");
-               for (Iterator<ConfigAttribute> iterator = 
attributes.iterator(); iterator.hasNext();) {
-                       ConfigAttribute attrib = (ConfigAttribute) 
iterator.next();
-                       print("   @attr " + attrib.name);
-                       if (attrib.hasDoc())
-                               print(" " + attrib.doc);
-                       println("");
-               }
-               println("-->");
-       }
+    private void generate(final List<ConfigAttribute> attributes) {
+        println("<!--");
+        for (final Iterator<ConfigAttribute> iterator = attributes.iterator(); 
iterator.hasNext();) {
+            final ConfigAttribute attrib = iterator.next();
+            print("   @attr " + attrib.name);
+            if (attrib.hasDoc()) {
+                print(" " + attrib.doc);
+            }
+            println("");
+        }
+        println("-->");
+    }
 }

Modified: branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateFile.java
===================================================================
--- branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateFile.java      
2008-03-31 08:58:58 UTC (rev 6320)
+++ branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateFile.java      
2008-03-31 14:28:06 UTC (rev 6321)
@@ -4,62 +4,106 @@
 import java.io.FileNotFoundException;
 import java.io.PrintStream;
 
+/**
+ * This class provide methods that makes it easy to write indented text to a
+ * file.
+ *
+ */
 public abstract class GenerateFile {
 
-       private PrintStream stream;
-       private int depth = 0;
-       private boolean indent = true;
+    private PrintStream stream;
+    private int depth = 0;
+    private boolean indent = true;
+    private File file;
 
-       private File file;
+    /**
+     * Initialize this generator. It will open the file specified.
+     *
+     * @param name
+     *            Filename
+     */
+    protected void init(final String name) {
+        file = new File(name);
 
-       protected void init(String name) {
-               file = new File(name);
+        try {
+            stream = new PrintStream(file);
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        }
+    }
 
-               try {
-                       stream = new PrintStream(file);
-               } catch (FileNotFoundException e) {
-                       e.printStackTrace();
-               }
-       }
+    /**
+     * Indent one level.
+     */
+    protected void indent() {
+        depth++;
+    }
 
-       protected void indent() {
-               depth++;
-       }
+    /**
+     * Unindent one level.
+     */
+    protected void unindent() {
+        depth--;
+        if (depth < 0) {
+            throw new RuntimeException("Indenting below zero");
+        }
+    }
 
-       protected void unindent() {
-               depth--;
-               if (depth < 0)
-                       throw new RuntimeException("Indenting below zero");
-       }
+    /**
+     * Print text to file with a newline appended and increase indention level
+     * by one.
+     *
+     * @param string
+     *            String that will be printed
+     */
+    protected void printlnI(final String string) {
+        println(string);
+        depth++;
+    }
 
-       protected void printlnI(String string) {
-               println(string);
-               depth++;
-       }
+    /**
+     * Decrease indention level by one, and print text to file with a newline
+     * appended.
+     *
+     * @param string
+     *            String that will be printed
+     */
+    protected void printlnU(final String string) {
+        depth--;
+        println(string);
+    }
 
-       protected void printlnU(String string) {
-               depth--;
-               println(string);
-       }
+    /**
+     * Print text to file.
+     *
+     * @param string
+     *            String that will be printed
+     */
+    protected void print(final String string) {
+        if (indent) {
+            for (int i = 1; i <= depth; i++) {
+                stream.print("    ");
+            }
+        }
+        stream.print(string);
+        indent = false;
+    }
 
-       protected void print(String string) {
-               if (indent)
-                       for (int i = 1; i <= depth; i++) {
-                               stream.print("    ");
-                       }
-               stream.print(string);
-               indent = false;
-       }
+    /**
+     * Print text to file and a newline.
+     *
+     * @param string
+     *            String that will be printed
+     */
+    protected void println(final String string) {
+        print(string + "\n");
+        indent = true;
+    }
 
-       protected void println(String string) {
-               print(string += "\n");
-               indent = true;
-       }
-
-       protected void done() {
-               if (depth != 0)
-                       throw new RuntimeException("Indenting not balanced.");
-
-               System.out.println("Written file: " + file);
-       }
+    /**
+     * Close stream.
+     */
+    protected void done() {
+        stream.close();
+    }
 }

Modified: 
branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateRelaxNG.java
===================================================================
--- branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateRelaxNG.java   
2008-03-31 08:58:58 UTC (rev 6320)
+++ branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateRelaxNG.java   
2008-03-31 14:28:06 UTC (rev 6321)
@@ -2,71 +2,80 @@
 
 import java.util.Iterator;
 
-public class GenerateRelaxNG extends GenerateFile implements Runnable {
+/**
+ * Generator for Relax NG.
+ */
+public class GenerateRelaxNG extends GenerateSchemaFile {
 
-       private final ConfigElement root;
-       private final String fileName;
+    /**
+     * @param element
+     *            Root element.
+     * @param name
+     *            File name.
+     * @param idString
+     *            id.
+     */
+    protected GenerateRelaxNG(final ConfigElement element, final String name, 
final String idString) {
+        super(element, name, idString);
+    }
 
-       public GenerateRelaxNG(ConfigElement element, String name) {
-               fileName = name;
-               root = element;
-       }
+    /**
+     * Generate Relax NG.
+     */
+    @Override
+    protected void runImpl() {
+        generate(root);
+    }
 
-       public void run() {
-               init(fileName);
-               generate(root);
-               done();
-       }
+    private void generate(final ConfigElement element) {
 
-       private void generate(ConfigElement element) {
+        if (element.hasDoc()) {
+            final String[] docArray = element.doc.split("\n");
+            for (int i = 0; i < docArray.length; i++) {
+                println("## " + docArray[i]);
+            }
+        }
 
-               if (element.hasDoc()) {
-                       String[] docArray = element.doc.split("\n");
-                       for (int i = 0; i < docArray.length; i++) {
-                               println("## " + docArray[i]);
-                       }
-               }
+        println("element " + element.name + " {");
+        indent();
+        if (element.attributes.isEmpty() && element.children.isEmpty()) {
+            print(" empty ");
+        } else {
+            for (final Iterator<ConfigAttribute> iterator = 
element.attributes.iterator(); iterator.hasNext();) {
+                final ConfigAttribute attrib = iterator.next();
 
-               println("element " + element.name + " {");
-               indent();
-               if (element.attributes.isEmpty() && element.children.isEmpty()) 
{
-                       print(" empty ");
-               } else {
-                       for (Iterator<ConfigAttribute> iterator = 
element.attributes.iterator(); iterator.hasNext();) {
-                               ConfigAttribute attrib = (ConfigAttribute) 
iterator.next();
+                generate(attrib);
+                if (iterator.hasNext() || !element.children.isEmpty()) {
+                    println(",");
+                } else {
+                    println("");
+                }
+            }
+        }
 
-                               generate(attrib);
-                               if (iterator.hasNext() || 
!element.children.isEmpty()) {
-                                       println(",");
-                               } else {
-                                       println("");
-                               }
-                       }
-               }
+        if (!element.children.isEmpty()) {
+            println("(");
+            for (int i = 0; i < element.children.size(); i++) {
+                if (i > 0) {
+                    println("|");
+                }
+                generate(element.children.get(i));
+            }
+            println(")*");
+        }
+        unindent();
+        println("}*");
 
-               if (!element.children.isEmpty()) {
-                       println("(");
-                       for (int i = 0; i < element.children.size(); i++) {
-                               if (i > 0) {
-                                       println("|");
-                               }
-                               generate(element.children.get(i));
-                       }
-                       println(")*");
-               }
-               unindent();
-               println("}*");
+    }
 
-       }
+    private void generate(final ConfigAttribute attrib) {
+        if (attrib.hasDoc()) {
+            final String[] docArray = attrib.doc.split("\n");
+            for (int i = 0; i < docArray.length; i++) {
+                println("## " + docArray[i]);
+            }
+        }
+        print("attribute " + attrib.name + " { text }" + (attrib.required ? "" 
: "?"));
+    }
 
-       private void generate(ConfigAttribute attrib) {
-               if (attrib.hasDoc()) {
-                       String[] docArray = attrib.doc.split("\n");
-                       for (int i = 0; i < docArray.length; i++) {
-                               println("## " + docArray[i]);
-                       }
-               }
-               print("attribute " + attrib.name + " { text }" + 
(attrib.required ? "" : "?"));
-       }
-
 }

Added: 
branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateSchemaFile.java
===================================================================
--- 
branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateSchemaFile.java    
                            (rev 0)
+++ 
branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateSchemaFile.java    
    2008-03-31 14:28:06 UTC (rev 6321)
@@ -0,0 +1,42 @@
+package no.sesat.mojo.modes;
+
+/**
+ * Common class for Schema Generators.
+ *
+ */
+public abstract class GenerateSchemaFile extends GenerateFile implements 
Runnable {
+    protected final ConfigElement root;
+    protected final String id;
+
+    private final String fileName;
+
+    /**
+     * @param element
+     *            Root element
+     * @param name
+     *            File name
+     * @param idString
+     *            Id for this schema
+     */
+    public GenerateSchemaFile(final ConfigElement element, final String name, 
final String idString) {
+        fileName = name;
+        id = idString;
+        root = element;
+    }
+
+    /**
+     *
+     * @see java.lang.Runnable#run()
+     */
+    public final void run() {
+        init(fileName);
+        runImpl();
+        done();
+    }
+
+    /**
+     * This will be called when this runnable is run, and should generate the
+     * expected schema file.
+     */
+    protected abstract void runImpl();
+}

Modified: branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateXSD.java
===================================================================
--- branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateXSD.java       
2008-03-31 08:58:58 UTC (rev 6320)
+++ branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/GenerateXSD.java       
2008-03-31 14:28:06 UTC (rev 6321)
@@ -4,68 +4,75 @@
 import java.util.Set;
 import java.util.TreeSet;
 
-public class GenerateXSD extends GenerateFile implements Runnable {
+/**
+ * Generator for XML Schema.
+ */
+public class GenerateXSD extends GenerateSchemaFile {
+    private final Set<String> written = new TreeSet<String>();
 
-       private final ConfigElement root;
-       private final String fileName;
-       private Set<String> written = new TreeSet<String>();
+    /**
+     * @param element
+     *            Root element.
+     * @param name
+     *            File name.
+     * @param idString
+     *            id.
+     */
+    protected GenerateXSD(final ConfigElement element, final String name, 
final String idString) {
+        super(element, name, idString);
+    }
 
-       public GenerateXSD(ConfigElement element, String name) {
-               fileName = name;
-               root = element;
-       }
+    /**
+     * Generate XML Schema.
+     */
+    @Override
+    protected void runImpl() {
+        println("<?xml version='1.0'?>");
+        println("<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
id='" + id + "'>");
+        indent();
+        println("<xsd:element name='" + root.name + "' type='" + root.name + 
"'/>");
+        generate(root);
+        unindent();
+        print("</xsd:schema>");
+    }
 
-       public void run() {
-               init(fileName);
+    private void generate(final ConfigElement element) {
+        if (written.add(element.name)) {
+            printlnI("<xsd:complexType name='" + element.name + "'>");
+            if (element.hasDoc()) {
+                printlnI("<xsd:annotation>");
+                printlnI("<xsd:documentation>");
+                println("<![CDATA[" + element.doc + "]]>)");
+                printlnU("</xsd:documentation>");
+                printlnU("</xsd:annotation>");
+            }
 
-               println("<?xml version='1.0'?>");
-               println("<xsd:schema 
xmlns:xsd='http://www.w3.org/2001/XMLSchema'>");
-               indent();
-               println("<xsd:element name='" + root.name + "' type='" + 
root.name + "'/>");
-               generate(root);
-               unindent();
-               print("</xsd:schema>");
+            printlnI("<xsd:choice  minOccurs='0' maxOccurs='unbounded'>");
+            for (int i = 0; i < element.children.size(); i++) {
+                final ConfigElement child = element.children.get(i);
+                println("<xsd:element name='" + child.name + "' type='" + 
child.name + "'/>");
+            }
+            printlnU("</xsd:choice>");
 
-               done();
-       }
+            for (final Iterator<ConfigAttribute> iterator = 
element.attributes.iterator(); iterator.hasNext();) {
+                final ConfigAttribute attrib = iterator.next();
+                if (attrib.hasDoc()) {
+                    printlnI("<xsd:attribute name='" + attrib.name + "'>");
+                    printlnI("<xsd:annotation>");
+                    printlnI("<xsd:documentation>");
+                    println("<![CDATA[" + attrib.doc + "]]>)");
+                    printlnU("</xsd:documentation>");
+                    printlnU("</xsd:annotation>");
+                    printlnU("</xsd:attribute>");
+                } else {
+                    println("<xsd:attribute name='" + attrib.name + "'/>");
+                }
+            }
+            printlnU("</xsd:complexType>");
 
-       private void generate(ConfigElement element) {
-               if (written.add(element.name)) {
-                       printlnI("<xsd:complexType name='" + element.name + 
"'>");
-                       if (element.hasDoc()) {
-                               printlnI("<xsd:annotation>");
-                               printlnI("<xsd:documentation>");
-                               println("<![CDATA[" + element.doc + "]]>)");
-                               printlnU("</xsd:documentation>");
-                               printlnU("</xsd:annotation>");
-                       }
-
-                       printlnI("<xsd:choice  minOccurs='0' 
maxOccurs='unbounded'>");
-                       for (int i = 0; i < element.children.size(); i++) {
-                               ConfigElement child = element.children.get(i);
-                               println("<xsd:element name='" + child.name + "' 
type='" + child.name + "'/>");
-                       }
-                       printlnU("</xsd:choice>");
-
-                       for (Iterator<ConfigAttribute> iterator = 
element.attributes.iterator(); iterator.hasNext();) {
-                               ConfigAttribute attrib = (ConfigAttribute) 
iterator.next();
-                               if (attrib.hasDoc()) {
-                                       printlnI("<xsd:attribute name='" + 
attrib.name + "'>");
-                                       printlnI("<xsd:annotation>");
-                                       printlnI("<xsd:documentation>");
-                                       println("<![CDATA[" + attrib.doc + 
"]]>)");
-                                       printlnU("</xsd:documentation>");
-                                       printlnU("</xsd:annotation>");
-                                       printlnU("</xsd:attribute>");
-                               } else {
-                                       println("<xsd:attribute name='" + 
attrib.name + "'/>");
-                               }
-                       }
-                       printlnU("</xsd:complexType>");
-
-               }
-               for (ConfigElement child : element.children) {
-                       generate(child);
-               }
-       }
+        }
+        for (ConfigElement child : element.children) {
+            generate(child);
+        }
+    }
 }

Modified: branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/NameFilter.java
===================================================================
--- branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/NameFilter.java        
2008-03-31 08:58:58 UTC (rev 6320)
+++ branches/2.16/mojo/src/main/java/no/sesat/mojo/modes/NameFilter.java        
2008-03-31 14:28:06 UTC (rev 6321)
@@ -1,5 +1,15 @@
 package no.sesat.mojo.modes;
 
+/**
+ * Function wrapper.
+ *
+ */
 public interface NameFilter {
-       public String filter(String string);
+
+    /**
+     * @param string
+     *            String that we want to be filtered.
+     * @return The filtered string.
+     */
+    String filter(String string);
 }

_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits

Reply via email to