[infinispan-commits] Infinispan SVN: r496 - in trunk/tools/src/main/java/org/infinispan/tools/doclet: jmx and 1 other directory.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Tue Jun 23 09:43:37 EDT 2009
Author: vblagojevic at jboss.com
Date: 2009-06-23 09:43:37 -0400 (Tue, 23 Jun 2009)
New Revision: 496
Added:
trunk/tools/src/main/java/org/infinispan/tools/doclet/html/ConfigHtmlGenerator.java
trunk/tools/src/main/java/org/infinispan/tools/doclet/jmx/ConfigDoclet.java
Log:
[ISPN-89] - Document all configuration options available in XML
Added: trunk/tools/src/main/java/org/infinispan/tools/doclet/html/ConfigHtmlGenerator.java
===================================================================
--- trunk/tools/src/main/java/org/infinispan/tools/doclet/html/ConfigHtmlGenerator.java (rev 0)
+++ trunk/tools/src/main/java/org/infinispan/tools/doclet/html/ConfigHtmlGenerator.java 2009-06-23 13:43:37 UTC (rev 496)
@@ -0,0 +1,176 @@
+package org.infinispan.tools.doclet.html;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.List;
+
+import org.infinispan.config.AbstractConfigurationBean;
+import org.infinispan.config.ConfigurationAttribute;
+import org.infinispan.config.ConfigurationElement;
+import org.infinispan.config.ConfigurationElements;
+import org.infinispan.config.ConfigurationProperties;
+import org.infinispan.config.ConfigurationProperty;
+import org.infinispan.tools.ClassFinder;
+
+public class ConfigHtmlGenerator extends HtmlGenerator {
+
+
+ public ConfigHtmlGenerator(String encoding, String title, String bottom, String footer,
+ String header, String metaDescription, List<String> metaKeywords) {
+ super(encoding, title, bottom, footer, header, metaDescription, metaKeywords);
+
+ }
+
+ protected String generateContents() {
+ StringBuilder sb = new StringBuilder();
+ // index of components
+ sb.append("<h2>Infinispan configuration options</h2><br />");
+ sb.append("<UL>");
+
+ List<Class<?>> list;
+ try {
+ list = ClassFinder.isAssignableFrom(AbstractConfigurationBean.class);
+ for(Class<?> clazz: list){
+ 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){
+ 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>");
+ if(ce.description().length() > 0){
+ sb.append(" ").append(ce.description()).append("\n");
+ } else {
+ sb.append("\n");
+ }
+ 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");
+ 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>");
+ if(a.defaultValue().length() >0){
+ sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\"><tt>").append(a.defaultValue()).append("</tt></TD>");
+ }
+ else{
+ try{
+ //reflect default value
+ Object matchingFieldValue = matchingFieldValue(m);
+ sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\"><tt>").append(matchingFieldValue).append("</tt></TD>");
+ } catch(Exception e){
+ sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\"><tt>").append("N/A").append("</tt></TD>");
+ }
+ }
+ if(a.allowedValues().length() > 0){
+ sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\">").append(a.allowedValues()).append("</TD>");
+ }
+ else if(isSetterMethod(m)){
+ sb.append("<TD ALIGN=\"LEFT\" VALIGN=\"TOP\">").append(m.getParameterTypes()[0].getSimpleName()).append("</TD>");
+ }
+ sb.append("\n</TR>");
+ }
+ }
+ if (createdAttributes) {
+ sb.append("\n</TABLE></TD></TR>");
+ }
+
+
+
+ for(Method m:clazz.getMethods()){
+ ConfigurationProperty[] cprops = null;
+ ConfigurationProperties cp = m.getAnnotation(ConfigurationProperties.class);
+ ConfigurationProperty p = null;
+ if (cp != null) {
+ cprops = cp.elements();
+ } else {
+ p = m.getAnnotation(ConfigurationProperty.class);
+ if (p != null) {
+ cprops = new ConfigurationProperty[] { p };
+ }
+ }
+
+ if(cprops != null){
+ 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");
+ 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>");
+ }
+ }
+ }
+ }
+ if(createdProperties){
+ sb.append("\n</TABLE></TD></TR>");
+ }
+
+ //closing table
+ sb.append("\n</TABLE></TD></TR>");
+ }
+ }
+ }
+ } catch (Exception e) {
+ }
+ return sb.toString();
+ }
+
+ private boolean isSetterMethod(Method m){
+ return m.getName().startsWith("set") && m.getParameterTypes().length ==1;
+ }
+
+ private Object matchingFieldValue(Method m) throws Exception{
+ String name = m.getName();
+ if(!name.startsWith("set")) throw new IllegalArgumentException("Not a setter method");
+
+ String fieldName = name.substring(name.indexOf("set") + 3);
+ fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1);
+ Field f = m.getDeclaringClass().getDeclaredField(fieldName);
+ return getField(f, m.getDeclaringClass().newInstance());
+
+ }
+
+ private static Object getField(Field field, Object target) {
+ if(!Modifier.isPublic(field.getModifiers())) {
+ field.setAccessible(true);
+ }
+ try {
+ return field.get(target);
+ }
+ catch(IllegalAccessException iae) {
+ throw new IllegalArgumentException("Could not get field " + field, iae);
+ }
+ }
+}
Added: trunk/tools/src/main/java/org/infinispan/tools/doclet/jmx/ConfigDoclet.java
===================================================================
--- trunk/tools/src/main/java/org/infinispan/tools/doclet/jmx/ConfigDoclet.java (rev 0)
+++ trunk/tools/src/main/java/org/infinispan/tools/doclet/jmx/ConfigDoclet.java 2009-06-23 13:43:37 UTC (rev 496)
@@ -0,0 +1,76 @@
+package org.infinispan.tools.doclet.jmx;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.infinispan.tools.doclet.html.ConfigHtmlGenerator;
+import org.infinispan.tools.doclet.html.HtmlGenerator;
+
+import com.sun.javadoc.DocErrorReporter;
+import com.sun.javadoc.RootDoc;
+import com.sun.tools.doclets.formats.html.ConfigurationImpl;
+
+/**
+ * A Doclet that generates configuration guide for Infinispan
+ *
+ * @author Vladimir Blagojevic
+ * @since 4.0
+ */
+ at SuppressWarnings("restriction")
+public class ConfigDoclet {
+ static String outputDirectory = ".";
+ static String header, footer, encoding, title, bottom;
+
+ public static boolean start(RootDoc root) throws IOException {
+
+ HtmlGenerator generator = new ConfigHtmlGenerator(encoding, title(), bottom, footer, header,
+ "Infinispan configuration options", Arrays.asList("Configuration", "Infinispan",
+ "Data Grids", "Documentation", "Reference", "MBeans"));
+
+ generator.generateHtml(outputDirectory + File.separator + "config.html");
+
+ return true;
+ }
+
+ private static String title() {
+ String s = "Configuration options";
+ if (title == null || title.equals(""))
+ return s;
+ else {
+ s += " (" + title + ")";
+ return s;
+ }
+ }
+
+ public static int optionLength(String option) {
+ return (ConfigurationImpl.getInstance()).optionLength(option);
+ }
+
+ public static boolean validOptions(String options[][], DocErrorReporter reporter) {
+ for (String[] option : options) {
+ // System.out.println(" >> Option " + Arrays.toString(option));
+ if (option[0].equals("-d"))
+ outputDirectory = option[1];
+ else if (option[0].equals("-encoding"))
+ encoding = option[1];
+ else if (option[0].equals("-bottom"))
+ bottom = option[1];
+ else if (option[0].equals("-footer"))
+ footer = option[1];
+ else if (option[0].equals("-header"))
+ header = option[1];
+ else if (option[0].equals("-doctitle"))
+ title = option[1];
+ }
+ return (ConfigurationImpl.getInstance()).validOptions(options, reporter);
+ }
+
+ public static void main(String[] args) throws IOException {
+ HtmlGenerator generator = new ConfigHtmlGenerator(encoding, title(), bottom, footer, header,
+ "Infinispan configuration options", Arrays.asList("Configuration", "Infinispan",
+ "Data Grids", "Documentation", "Reference", "MBeans"));
+
+ generator.generateHtml(outputDirectory + File.separator + "config.html");
+ }
+}
More information about the infinispan-commits
mailing list