[infinispan-commits] Infinispan SVN: r549 - trunk/tools/src/main/java/org/infinispan/tools/doclet/config.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Sun Jul 12 13:45:40 EDT 2009


Author: vblagojevic at jboss.com
Date: 2009-07-12 13:45:40 -0400 (Sun, 12 Jul 2009)
New Revision: 549

Modified:
   trunk/tools/src/main/java/org/infinispan/tools/doclet/config/ConfigHtmlGenerator.java
Log:
tree layout of all elements
new list layout of all elements

Modified: trunk/tools/src/main/java/org/infinispan/tools/doclet/config/ConfigHtmlGenerator.java
===================================================================
--- trunk/tools/src/main/java/org/infinispan/tools/doclet/config/ConfigHtmlGenerator.java	2009-07-10 15:57:40 UTC (rev 548)
+++ trunk/tools/src/main/java/org/infinispan/tools/doclet/config/ConfigHtmlGenerator.java	2009-07-12 17:45:40 UTC (rev 549)
@@ -12,7 +12,11 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 public class ConfigHtmlGenerator extends HtmlGenerator {
 
@@ -30,14 +34,22 @@
    }
 
    protected String generateContents() {
+      
       StringBuilder sb = new StringBuilder();
       // index of components
-      sb.append("<h2>Infinispan configuration options</h2><br />");
+      sb.append("<h2>Infinispan configuration options</h2><br/>");
       sb.append("<UL>");
 
       List<Class<?>> configBeans;
       try {
          configBeans = getConfigBeans();
+         TreeNode root  = tree(configBeans);     
+         
+         sb.append("<div class=\"" +"source" + "\"><pre>");
+         sb.append(root.pp(""));
+         sb.append("</pre></div>");
+         
+         tree(configBeans);
          for (Class<?> clazz : configBeans) {
             ConfigurationElement ces[] = null;
             ConfigurationElements configurationElements = clazz.getAnnotation(ConfigurationElements.class);
@@ -51,39 +63,65 @@
             }
             if (ces != null) {
                for (ConfigurationElement ce : ces) {
-
                   boolean createdAttributes = false;
                   boolean createdProperties = false;
-                  sb.append("<A NAME=\"").append(ce.name()).append("\">\n");
-                  sb.append("\n<TABLE WIDTH=\"100%\" CELLSPACING=\"1\" CELLPADDING=\"0\" BORDER=\"1\">\n");
-                  sb.append("<TR CLASS=\"TableHeadingColor\"><TH ALIGN=\"LEFT\"><b>Element: <tt> ").append(ce.name()).append(", </tt></b>");
-                  sb.append("Parent element: <tt>").append(ce.parent()).append("</tt>");
+                  sb.append("\n<a name=\"").append("ce_" + ce.parent() +"_" +ce.name() +"\">" + "</a>");
+                  sb.append("<div class=\"section\"><h3><a name=\"" + ce.name() + "\"></a>" + ce.name() +"</h3>");
+                  sb.append("\n<p>");
                   if (ce.description().length() > 0) {
-                     sb.append(" ").append(ce.description()).append("\n");
+                     sb.append(ce.description());
                   } else {
+                     sb.append("todo");
+                  }
+                  TreeNode n = findNode(root,ce.name(),ce.parent());
+                  sb.append(" Parent element is " + "<a href=\"").append(
+                           "#ce_" + n.parent.parent.name + "_" + n.parent.name + "\">" + "&lt;"
+                                    + ce.parent() + "&gt;" + "</a>.");    
+                  
+                  if(n != null && !n.children.isEmpty()){
+                     sb.append(" Child elements are ");
+                     int childCount = n.children.size();
+                     int count = 1;
+                     for (TreeNode tn : n.children) {
+                        if (count < childCount) {
+                           sb.append("<a href=\"").append(
+                                    "#ce_" + tn.parent.name + "_" + tn.name + "\">" + "&lt;"
+                                             + tn.name + "&gt;" + "</a>,");
+                        } else {
+                           sb.append("<a href=\"").append(
+                                    "#ce_" + tn.parent.name + "_" + tn.name + "\">" + "&lt;"
+                                             + tn.name + "&gt;" + "</a>.");
+                        }
+                        count++;
+                     }
                      sb.append("\n");
                   }
+                  sb.append("</p>"); 
                   for (Method m : clazz.getMethods()) {
                      ConfigurationAttribute a = m.getAnnotation(ConfigurationAttribute.class);
                      boolean childElement = a != null && a.containingElement().equals(ce.name());
                      if (childElement && !createdAttributes) {
                         // Attributes
-                        sb.append("<TR CLASS=\"TableSubHeadingColor\"><TH ALIGN=\"LEFT\"><strong><i>Attributes</i></strong></TH></TR>\n");
-                        sb.append("<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\"><TD ALIGN=\"CENTER\"><TABLE WIDTH=\"100%\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\">\n");
-                        sb.append("<TR CLASS=\"TableSubHeadingColor\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\"><strong>Name</strong></TD>\n");
-                        sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" WIDTH=\"40%\"><strong>Description</strong></TD>\n");
-                        sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\"><strong>Default values</strong></TD>\n");
-                        sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\"><strong>Allowed values</strong></TD>\n</TR>\n");
+                        sb.append("<table class=\"bodyTable\"> ");
+                        sb.append("<tr class=\"a\"><th>Attribute</th><th>Type</th><th>Default</th><th>Description</th></tr>\n");
                         createdAttributes = true;
                      }
                      if (childElement) {
-                        sb.append("<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">");
-                        sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\"><tt>").append(a.name()).append("</tt></TD>");
-                        sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\">").append(a.description()).append("</TD>");
-
+                        sb.append("<tr class=\"b\">");
+                        sb.append("<td>").append("<code>" + a.name() +"</code>").append("</td>\n");
+                        
+                        //if allowed values specified for attribute, use it
+                        if (a.allowedValues().length() > 0) {
+                           sb.append("<td>").append("<code>" + a.allowedValues()+"</code>").append("</td>\n");
+                        }
+                        //otherwise, reflect method and use parameter as allowed value
+                        else if (isSetterMethod(m)) {
+                           sb.append("<td>").append("<code>" + m.getParameterTypes()[0].getSimpleName() + "</code>").append("</td>\n");
+                        }
+                        
                         //if default value specified in annotation use it
                         if (a.defaultValue().length() > 0) {
-                           sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\"><tt>").append(a.defaultValue()).append("</tt></TD>");
+                           sb.append("<td>").append(a.defaultValue()).append("</td>\n");
                         }
 
                         //otherwise reflect that field and read default value
@@ -91,28 +129,23 @@
                            try {
                               //reflect default value 
                               Object matchingFieldValue = matchingFieldValue(m);
-                              sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\"><tt>").append(matchingFieldValue).append("</tt></TD>");
+                              sb.append("<td>").append(matchingFieldValue).append("</td>\n");
                            } catch (Exception e) {
-                              sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\"><tt>").append("N/A").append("</tt></TD>");
+                              sb.append("<td>").append("N/A").append("</td>\n");
                            }
-                        }
-
-                        //if allowed values specified for attribute, use it
-                        if (a.allowedValues().length() > 0) {
-                           sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\">").append(a.allowedValues()).append("</TD>");
-                        }
-                        //otherwise, reflect method and use parameter as allowed value
-                        else if (isSetterMethod(m)) {
-                           sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\">").append(m.getParameterTypes()[0].getSimpleName()).append("</TD>");
-                        }
-                        sb.append("\n</TR>");
+                        }                   
+                        if(a.description().length() >0)
+                           sb.append("<td>").append(a.description()).append("</td>\n");
+                        else 
+                           sb.append("<td>").append("todo").append("</td>\n");
+           
+                        sb.append("</tr>\n");
                      }
                   }
                   if (createdAttributes) {
-                     sb.append("\n</TABLE></TD></TR>");
+                     sb.append("</table></div>");
                   }
-
-
+                  
                   for (Method m : clazz.getMethods()) {
                      ConfigurationProperty[] cprops = null;
                      ConfigurationProperties cp = m.getAnnotation(ConfigurationProperties.class);
@@ -130,28 +163,26 @@
                         for (ConfigurationProperty c : cprops) {
                            boolean child = c.parentElement().equals(ce.name());
                            if (child && !createdProperties) {
-                              //custom properties                                                            
-                              sb.append("<TR CLASS=\"TableSubHeadingColor\"><TH ALIGN=\"LEFT\"><strong><i>Properties</i></strong></TH></TR>\n");
-                              sb.append("<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\"><TD ALIGN=\"CENTER\"><TABLE WIDTH=\"100%\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\">\n");
-                              sb.append("<TR CLASS=\"TableSubHeadingColor\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\"><strong>Name</strong></TD>\n");
-                              sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" WIDTH=\"40%\"><strong>Description</strong></TD>\n</TR>\n");
+                              //custom properties         
+                              sb.append("\n<table class=\"bodyTable\"> ");
+                              sb.append("<tr class=\"a\"><th>Property</th><th>Description</th></tr>\n");        
                               createdProperties = true;
                            }
                            if (child) {
-                              sb.append("<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">");
-                              sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\"><tt>").append(c.name()).append("</tt></TD>");
-                              sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\">").append(c.description()).append("</TD>");
-                              sb.append("\n</TR>");
+                              sb.append("<tr class=\"b\">");
+                              sb.append("<td>").append(c.name()).append("</td>\n");                              
+                              if(c.description().length() >0)
+                                 sb.append("<td>").append(c.description()).append("</td>\n");
+                              else 
+                                 sb.append("<td>").append("todo").append("</td>\n"); 
+                              sb.append("</tr>\n");
                            }
                         }
                      }
                   }
                   if (createdProperties) {
-                     sb.append("\n</TABLE></TD></TR>");
-                  }
-
-                  //closing table
-                  sb.append("\n</TABLE></TD></TR>");
+                     sb.append("</table></div>");
+                  }                
                }
             }
          }
@@ -159,7 +190,56 @@
       }
       return sb.toString();
    }
+   
+   private TreeNode findNode(TreeNode tn, String name, String parent){
+      TreeNode result = null;
+      if(tn.name.equals(name) && tn.parent != null && tn.parent.name.equals(parent)){         
+         result = tn;
+      } else {
+         for (TreeNode child :tn.children){
+            result = findNode(child,name,parent);
+            if(result != null) break;
+         }
+      }
+      return result;
+   }
+   
+   private TreeNode tree(List<Class<?>>configBeans){
+      List<ConfigurationElement> lce = new ArrayList<ConfigurationElement>(7);
+      for (Class<?> clazz : configBeans) {
+         ConfigurationElement ces[] = null;
+         ConfigurationElements configurationElements = clazz.getAnnotation(ConfigurationElements.class);
+         ConfigurationElement configurationElement = clazz.getAnnotation(ConfigurationElement.class);
 
+         if (configurationElement != null && configurationElements == null) {
+            ces = new ConfigurationElement[]{configurationElement};
+         }
+         if (configurationElements != null && configurationElement == null) {
+            ces = configurationElements.elements();
+         }
+         if(ces != null){
+            lce.addAll(Arrays.asList(ces));
+         }
+      }
+      TreeNode root = new TreeNode();
+      root.parent = new TreeNode();
+      root.name = "infinispan";
+      makeTree(lce,root);
+      return root;
+   }
+   
+   private void makeTree(List<ConfigurationElement> lce, TreeNode tn) {
+      for (ConfigurationElement ce : lce) {
+         if(ce.parent().equals(tn.name)){
+            TreeNode child = new TreeNode();
+            child.name = ce.name();
+            child.parent = tn;         
+            tn.children.add(child);
+            makeTree(lce,child);
+         }
+      }
+   }
+
    private boolean isSetterMethod(Method m) {
       return m.getName().startsWith("set") && m.getParameterTypes().length == 1;
    }
@@ -186,4 +266,41 @@
          throw new IllegalArgumentException("Could not get field " + field, iae);
       }
    }
+   
+   private class TreeNode {
+      String name = "";
+      TreeNode parent;
+      Set<TreeNode> children = new HashSet<TreeNode>();
+
+      public String toString() {
+         return name;
+      }
+
+      public String pp(String prefix) {
+         StringBuffer result = new StringBuffer(prefix + "&lt;<a href=\"" + "#ce_" + parent.name
+                  + "_" + name + "\">" + name + "</a>&gt;" + "\n");
+         String newPrefix = prefix + "  ";
+         for (TreeNode child : children)
+            result.append(child.pp(newPrefix));
+         return result.toString();
+      }
+
+      public boolean equals(Object other) {
+         if (other == this)
+            return true;
+         if (!(other instanceof TreeNode))
+            return false;
+         TreeNode tn = (TreeNode) other;
+         return this.parent.name != null && tn.parent != null
+                  && this.parent.name.equals(tn.parent.name) && this.name.equals(tn.name);
+      }
+
+      public int hashCode() {
+         int result = 17;
+         result = 31 * result + name.hashCode();
+         result = 31 * result
+                  + ((parent != null && parent.name != null) ? parent.name.hashCode() : 0);
+         return result;
+      }
+   }
 }




More information about the infinispan-commits mailing list