[infinispan-commits] Infinispan SVN: r562 - in trunk/tools/src/main/java/org/infinispan/tools: schema and 1 other directory.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Mon Jul 13 18:47:20 EDT 2009
Author: vblagojevic at jboss.com
Date: 2009-07-13 18:47:19 -0400 (Mon, 13 Jul 2009)
New Revision: 562
Added:
trunk/tools/src/main/java/org/infinispan/tools/schema/ConfigurationTreeWalker.java
trunk/tools/src/main/java/org/infinispan/tools/schema/XMLTreeOutputWalker.java
Modified:
trunk/tools/src/main/java/org/infinispan/tools/doclet/config/ConfigDoclet.java
trunk/tools/src/main/java/org/infinispan/tools/doclet/config/ConfigHtmlGenerator.java
trunk/tools/src/main/java/org/infinispan/tools/schema/SchemaGenerator.java
trunk/tools/src/main/java/org/infinispan/tools/schema/SchemaGeneratorTreeWalker.java
trunk/tools/src/main/java/org/infinispan/tools/schema/TreeNode.java
trunk/tools/src/main/java/org/infinispan/tools/schema/TreeWalker.java
Log:
refactor
Modified: trunk/tools/src/main/java/org/infinispan/tools/doclet/config/ConfigDoclet.java
===================================================================
--- trunk/tools/src/main/java/org/infinispan/tools/doclet/config/ConfigDoclet.java 2009-07-13 18:52:18 UTC (rev 561)
+++ trunk/tools/src/main/java/org/infinispan/tools/doclet/config/ConfigDoclet.java 2009-07-13 22:47:19 UTC (rev 562)
@@ -13,6 +13,7 @@
* A Doclet that generates configuration guide for Infinispan
*
* @author Vladimir Blagojevic
+ * @version $Id$
* @since 4.0
*/
@SuppressWarnings("restriction")
Property changes on: trunk/tools/src/main/java/org/infinispan/tools/doclet/config/ConfigDoclet.java
___________________________________________________________________
Name: svn:keywords
+ Id
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-13 18:52:18 UTC (rev 561)
+++ trunk/tools/src/main/java/org/infinispan/tools/doclet/config/ConfigHtmlGenerator.java 2009-07-13 22:47:19 UTC (rev 562)
@@ -1,5 +1,10 @@
package org.infinispan.tools.doclet.config;
+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;
@@ -7,17 +12,17 @@
import org.infinispan.config.ConfigurationProperties;
import org.infinispan.config.ConfigurationProperty;
import org.infinispan.tools.doclet.html.HtmlGenerator;
+import org.infinispan.tools.schema.TreeNode;
+import org.infinispan.tools.schema.XMLTreeOutputWalker;
import org.infinispan.util.ClassFinder;
-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;
-
+/**
+ * Infinispan configuration reference guide generator
+ *
+ * @author Vladimir Blagojevic
+ * @version $Id$
+ * @since 4.0
+ */
public class ConfigHtmlGenerator extends HtmlGenerator {
String classpath;
@@ -43,10 +48,12 @@
List<Class<?>> configBeans;
try {
configBeans = getConfigBeans();
- TreeNode root = tree(configBeans);
+ XMLTreeOutputWalker tw = new XMLTreeOutputWalker(sb);
+ TreeNode root = tw.constructTreeFromBeans(configBeans);
sb.append("<div class=\"" +"source" + "\"><pre>");
- sb.append(root.pp(""));
+ //print xml tree into StringBuilder
+ tw.preOrderTraverse(root);
sb.append("</pre></div>");
for (Class<?> clazz : configBeans) {
ConfigurationElement ces[] = null;
@@ -71,19 +78,17 @@
} 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 + "\">" + "<"
- + ce.parent() + ">" + "</a>.");
+ TreeNode n = tw.findNode(root,ce.name(),ce.parent());
+ sb.append(" Parent element is " + "<a href=\"").append("#ce_" + n.getParent().getParent().getName() +
+ "_" + n.getParent().getName()+ "\">" + "<" + ce.parent() + ">" + "</a>.");
- if(n != null && !n.children.isEmpty()){
+ if(n != null && !n.getChildren().isEmpty()){
sb.append(" Child elements are ");
- int childCount = n.children.size();
+ int childCount = n.getChildren().size();
int count = 1;
- for (TreeNode tn : n.children) {
- sb.append("<a href=\"").append(
- "#ce_" + tn.parent.name + "_" + tn.name + "\">" + "<"
- + tn.name + ">" + "</a>");
+ for (TreeNode tn : n.getChildren()) {
+ sb.append("<a href=\"").append("#ce_" + tn.getParent().getName() + "_"
+ + tn.getName() + "\">" + "<" + tn.getName() + ">" + "</a>");
if (count < childCount) {
sb.append(",");
} else {
@@ -188,55 +193,6 @@
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;
}
@@ -263,41 +219,4 @@
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 + "<<a href=\"" + "#ce_" + parent.name
- + "_" + name + "\">" + name + "</a>>" + "\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;
- }
- }
}
Property changes on: trunk/tools/src/main/java/org/infinispan/tools/doclet/config/ConfigHtmlGenerator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/tools/src/main/java/org/infinispan/tools/schema/ConfigurationTreeWalker.java
===================================================================
--- trunk/tools/src/main/java/org/infinispan/tools/schema/ConfigurationTreeWalker.java (rev 0)
+++ trunk/tools/src/main/java/org/infinispan/tools/schema/ConfigurationTreeWalker.java 2009-07-13 22:47:19 UTC (rev 562)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.tools.schema;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.infinispan.config.ConfigurationElement;
+import org.infinispan.config.ConfigurationElements;
+
+/**
+ * TreeWalker abstract super class that should be extended for a particular tool
+ *
+ * @author Vladimir Blagojevic
+ * @see SchemaGeneratorTreeWalker
+ * @see XMLTreeOutputWalker
+ * @version $Id$
+ * @since 4.0
+ */
+public abstract class ConfigurationTreeWalker implements TreeWalker{
+
+ public ConfigurationTreeWalker() {
+ super();
+ }
+
+ public TreeNode constructTreeFromBeans(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("infinispan",new TreeNode(),0);
+ makeTree(lce,root, 1);
+ return root;
+ }
+
+ private void makeTree(List<ConfigurationElement> lce, TreeNode tn, int currentDepth) {
+ for (ConfigurationElement ce : lce) {
+ if(ce.parent().equals(tn.getName())){
+ TreeNode child = new TreeNode(ce.name(),tn,currentDepth);
+ tn.getChildren().add(child);
+ makeTree(lce,child,(currentDepth+1));
+ }
+ }
+ }
+
+ public void levelOrderTraverse(TreeNode root) {
+ Queue<TreeNode> q = new LinkedBlockingQueue<TreeNode>();
+ q.add(root);
+
+ while(!q.isEmpty()){
+ TreeNode treeNode = q.poll();
+ treeNode.accept(this);
+ if(treeNode.hasChildren()){
+ q.addAll(treeNode.getChildren());
+ }
+ }
+ }
+
+ public void preOrderTraverse(TreeNode node) {
+ node.accept(this);
+ if(node.hasChildren()){
+ for (TreeNode child : node.getChildren()) {
+ preOrderTraverse(child);
+ }
+ }
+ }
+
+ public void postOrderTraverse(TreeNode node) {
+ if(node.hasChildren()){
+ for (TreeNode child : node.getChildren()) {
+ preOrderTraverse(child);
+ }
+ }
+ node.accept(this);
+ }
+}
\ No newline at end of file
Modified: trunk/tools/src/main/java/org/infinispan/tools/schema/SchemaGenerator.java
===================================================================
--- trunk/tools/src/main/java/org/infinispan/tools/schema/SchemaGenerator.java 2009-07-13 18:52:18 UTC (rev 561)
+++ trunk/tools/src/main/java/org/infinispan/tools/schema/SchemaGenerator.java 2009-07-13 22:47:19 UTC (rev 562)
@@ -23,8 +23,6 @@
import java.io.File;
import java.io.FileWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
@@ -37,16 +35,20 @@
import org.infinispan.Version;
import org.infinispan.config.AbstractConfigurationBean;
-import org.infinispan.config.ConfigurationElement;
-import org.infinispan.config.ConfigurationElements;
import org.infinispan.util.ClassFinder;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+/**
+ * Generates XML Schema for Infinispan configuration
+ *
+ * @author Vladimir Blagojevic
+ * @version $Id$
+ * @since 4.0
+ */
public class SchemaGenerator {
private final List<Class<?>> beans;
- private final TreeNode root;
private final File fileToWrite;
protected SchemaGenerator(File fileToWrite, String searchPath) throws Exception {
@@ -67,55 +69,8 @@
if (beans.isEmpty())
throw new IllegalStateException("Could not find AbstractConfigurationBean(s) on your classpath "
+ pathUsed);
-
- root = tree(beans);
}
- private TreeNode findNode(TreeNode tn, String name, String parent){
- TreeNode result = null;
- if(tn.getName().equals(name) && tn.getParent() != null && tn.getParent().getName().equals(parent)){
- result = tn;
- } else {
- for (TreeNode child :tn.getChildren()){
- 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("infinispan",new TreeNode());
- makeTree(lce,root);
- return root;
- }
-
- private void makeTree(List<ConfigurationElement> lce, TreeNode tn) {
- for (ConfigurationElement ce : lce) {
- if(ce.parent().equals(tn.getName())){
- TreeNode child = new TreeNode(ce.name(),tn);
- tn.getChildren().add(child);
- makeTree(lce,child);
- }
- }
- }
-
public static void main(String[] args) throws Exception {
String outputDir = "./";
@@ -151,7 +106,8 @@
xsElement.setAttribute("type", "tns:infinispanType");
xmldoc.getDocumentElement().appendChild(xsElement);
- SchemaGeneratorTreeWalker tw = new SchemaGeneratorTreeWalker(xmldoc,beans);
+ ConfigurationTreeWalker tw = new SchemaGeneratorTreeWalker(xmldoc,beans);
+ TreeNode root = tw.constructTreeFromBeans(beans);
tw.preOrderTraverse(root);
DOMSource domSource = new DOMSource(xmldoc);
Property changes on: trunk/tools/src/main/java/org/infinispan/tools/schema/SchemaGenerator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/tools/src/main/java/org/infinispan/tools/schema/SchemaGeneratorTreeWalker.java
===================================================================
--- trunk/tools/src/main/java/org/infinispan/tools/schema/SchemaGeneratorTreeWalker.java 2009-07-13 18:52:18 UTC (rev 561)
+++ trunk/tools/src/main/java/org/infinispan/tools/schema/SchemaGeneratorTreeWalker.java 2009-07-13 22:47:19 UTC (rev 562)
@@ -21,13 +21,9 @@
*/
package org.infinispan.tools.schema;
-import java.lang.reflect.Field;
import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
import java.util.List;
-import java.util.Queue;
import java.util.Set;
-import java.util.concurrent.LinkedBlockingQueue;
import org.infinispan.config.ConfigurationAttribute;
import org.infinispan.config.ConfigurationElement;
@@ -36,7 +32,15 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-public class SchemaGeneratorTreeWalker implements TreeWalker {
+/**
+ * TreeWalker that generates each node of the XML schema
+ *
+ * @author Vladimir Blagojevic
+ * @see SchemaGenerator
+ * @version $Id$
+ * @since 4.0
+ */
+public class SchemaGeneratorTreeWalker extends ConfigurationTreeWalker{
Document xmldoc;
private List<Class<?>> beans;
@@ -47,37 +51,6 @@
this.beans = beans;
}
- public void levelOrderTraverse(TreeNode root) {
- Queue<TreeNode> q = new LinkedBlockingQueue<TreeNode>();
- q.add(root);
-
- while(!q.isEmpty()){
- TreeNode treeNode = q.poll();
- treeNode.accept(this);
- if(treeNode.hasChildren()){
- q.addAll(treeNode.getChildren());
- }
- }
- }
-
- public void preOrderTraverse(TreeNode node){
- node.accept(this);
- if(node.hasChildren()){
- for (TreeNode child : node.getChildren()) {
- preOrderTraverse(child);
- }
- }
- }
-
- public void postOrderTraverse(TreeNode node){
- if(node.hasChildren()){
- for (TreeNode child : node.getChildren()) {
- preOrderTraverse(child);
- }
- }
- node.accept(this);
- }
-
public void visitNode(TreeNode treeNode) {
Element complexType = xmldoc.createElement("xs:complexType");
@@ -145,26 +118,4 @@
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);
- }
- }
}
Property changes on: trunk/tools/src/main/java/org/infinispan/tools/schema/SchemaGeneratorTreeWalker.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/tools/src/main/java/org/infinispan/tools/schema/TreeNode.java
===================================================================
--- trunk/tools/src/main/java/org/infinispan/tools/schema/TreeNode.java 2009-07-13 18:52:18 UTC (rev 561)
+++ trunk/tools/src/main/java/org/infinispan/tools/schema/TreeNode.java 2009-07-13 22:47:19 UTC (rev 562)
@@ -24,25 +24,39 @@
import java.util.HashSet;
import java.util.Set;
+/**
+ * TreeNode of Infinispan configuration
+ *
+ * @author Vladimir Blagojevic
+ * @version $Id$
+ * @since 4.0
+ */
public class TreeNode {
private final String name;
private final TreeNode parent;
+ private final int depth;
private final Set<TreeNode> children = new HashSet<TreeNode>();
- public TreeNode(String name, TreeNode parent) {
+ public TreeNode(String name, TreeNode parent, int depth) {
this.name = name;
this.parent = parent;
+ this.depth = depth;
}
public TreeNode() {
this.name="";
this.parent=null;
+ this.depth = -1; // :)
}
public String getName() {
return name;
}
-
+
+ public int getDepth() {
+ return depth;
+ }
+
public boolean hasChildren(){
return !children.isEmpty();
}
Property changes on: trunk/tools/src/main/java/org/infinispan/tools/schema/TreeNode.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: trunk/tools/src/main/java/org/infinispan/tools/schema/TreeWalker.java
===================================================================
--- trunk/tools/src/main/java/org/infinispan/tools/schema/TreeWalker.java 2009-07-13 18:52:18 UTC (rev 561)
+++ trunk/tools/src/main/java/org/infinispan/tools/schema/TreeWalker.java 2009-07-13 22:47:19 UTC (rev 562)
@@ -23,6 +23,15 @@
import org.infinispan.tools.schema.TreeNode;
+/**
+ * TreeWalker visitor
+ *
+ * @author Vladimir Blagojevic
+ * @see SchemaGeneratorTreeWalker
+ * @see XMLTreeOutputWalker
+ * @version $Id$
+ * @since 4.0
+ */
public interface TreeWalker {
void visitNode(TreeNode treeNode);
Property changes on: trunk/tools/src/main/java/org/infinispan/tools/schema/TreeWalker.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: trunk/tools/src/main/java/org/infinispan/tools/schema/XMLTreeOutputWalker.java
===================================================================
--- trunk/tools/src/main/java/org/infinispan/tools/schema/XMLTreeOutputWalker.java (rev 0)
+++ trunk/tools/src/main/java/org/infinispan/tools/schema/XMLTreeOutputWalker.java 2009-07-13 22:47:19 UTC (rev 562)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.tools.schema;
+
+import org.infinispan.tools.doclet.config.ConfigDoclet;
+
+/**
+ * TreeWalker that generates XML pretty print of the configuration tree
+ *
+ * @author Vladimir Blagojevic
+ * @see ConfigDoclet
+ * @version $Id$
+ * @since 4.0
+ */
+public class XMLTreeOutputWalker extends ConfigurationTreeWalker {
+
+ private final StringBuilder sb;
+
+ public XMLTreeOutputWalker(StringBuilder sb) {
+ super();
+ this.sb = sb;
+ }
+
+ public void visitNode(TreeNode treeNode) {
+ String ident = "";
+ for(int i = 0; i<=treeNode.getDepth();i++)
+ ident += " ";
+ sb.append(ident + "<<a href=\"" + "#ce_" + treeNode.getParent().getName()
+ + "_" + treeNode.getName() + "\">" + treeNode.getName() + "</a>>" + "\n");
+
+ }
+
+ public TreeNode findNode(TreeNode tn, String name, String parent){
+ TreeNode result = null;
+ if(tn.getName().equals(name) && tn.getParent() != null && tn.getParent().getName().equals(parent)){
+ result = tn;
+ } else {
+ for (TreeNode child :tn.getChildren()){
+ result = findNode(child,name,parent);
+ if(result != null) break;
+ }
+ }
+ return result;
+ }
+}
More information about the infinispan-commits
mailing list