[jboss-cvs] JBossAS SVN: r90942 - in projects/mc-tools/grapher/trunk/src: main/java/org/jboss/mctools/grapher/map and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 8 12:14:24 EDT 2009


Author: alesj
Date: 2009-07-08 12:14:23 -0400 (Wed, 08 Jul 2009)
New Revision: 90942

Added:
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/TreeGraphCreator.java
Modified:
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultGraphCreatorMapper.java
   projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/graph/test/GraphCreatorTestCase.java
Log:
Add tree graph creator.

Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java	2009-07-08 15:22:30 UTC (rev 90941)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java	2009-07-08 16:14:23 UTC (rev 90942)
@@ -132,6 +132,17 @@
    }
 
    /**
+    * Do we recurse into context.
+    *
+    * @param context the context to examine
+    * @return true if we recurse, false otherwise
+    */
+   protected boolean doRecurse(ControllerContext context)
+   {
+      return false; // by default we don't recurse
+   }
+
+   /**
     * Handle single context.
     *
     * @param controller the controller
@@ -151,19 +162,18 @@
       {
          for(DependencyItem item : items)
          {
-            DefaultGraphCell dependency;
-
             Object iDependOn = item.getIDependOn();
-            if (iDependOn instanceof Class)
+            DefaultGraphCell dependency = cells.get(iDependOn);
+            ControllerContext dependant = null;
+            if (dependency == null)
             {
-               ControllerContext cc = controller.getContextByClass(Class.class.cast(iDependOn));
-               dependency = getCell(cells, objects, cc);
-            }
-            else
-            {
-               dependency = cells.get(iDependOn);
-               if (dependency == null)
+               dependant = controller.getContext(iDependOn, null);  
+               if (dependant != null)
                {
+                  dependency = getCell(cells, objects, dependant);
+               }
+               else
+               {
                   dependency = createCell(iDependOn);
                   cells.put(iDependOn, dependency);
                   objects.add(dependency);
@@ -179,6 +189,9 @@
             GraphConstants.setEndFill(edge.getAttributes(), true);
 
             objects.add(edge);
+
+            if (dependant != null && doRecurse(dependant))
+               handleContext(controller, cells, objects, attributes, cs, dependant);
          }
       }
    }

Copied: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/TreeGraphCreator.java (from rev 90939, projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/BeanGraphCreator.java)
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/TreeGraphCreator.java	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/TreeGraphCreator.java	2009-07-08 16:14:23 UTC (rev 90942)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.jboss.mctools.grapher.graph;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jgraph.graph.DefaultGraphCell;
+import org.jgraph.graph.ConnectionSet;
+
+/**
+ * Render single bean.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class TreeGraphCreator extends AbstractGraphCreator
+{
+   private Object root;
+   private Set<Object> visited;
+
+   public TreeGraphCreator(Object root)
+   {
+      if (root == null)
+         throw new IllegalArgumentException("Null root name");
+
+      this.root = root;
+      visited = new HashSet<Object>();
+   }
+
+   protected void createCells(KernelController controller, Map<Object, DefaultGraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs)
+   {
+      ControllerContext context = controller.getContext(root, null);
+      if (context == null)
+         throw new IllegalArgumentException("No such context: " + root);
+
+      handleContext(controller, cells, objects, attributes, cs, context);
+   }
+
+   @Override
+   protected boolean doRecurse(ControllerContext context)
+   {
+      Object name = context.getName();
+      return visited.add(name);
+   }
+
+   @Override
+   public String toString()
+   {
+      return super.toString() + "[root=" + root + "]";
+   }
+}
\ No newline at end of file

Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultGraphCreatorMapper.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultGraphCreatorMapper.java	2009-07-08 15:22:30 UTC (rev 90941)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultGraphCreatorMapper.java	2009-07-08 16:14:23 UTC (rev 90942)
@@ -23,8 +23,9 @@
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.jboss.mctools.grapher.graph.BeanGraphCreator;
 import org.jboss.mctools.grapher.graph.GraphCreator;
-import org.jboss.mctools.grapher.graph.BeanGraphCreator;
+import org.jboss.mctools.grapher.graph.TreeGraphCreator;
 
 /**
  * Default graph creator mapper.
@@ -39,6 +40,10 @@
       if (bean != null)
          return new BeanGraphCreator(bean);
 
+      String root = request.getParameter("root");
+      if (root != null)
+         return new TreeGraphCreator(bean);
+
       return ALL;
    }
 }

Modified: projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/graph/test/GraphCreatorTestCase.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/graph/test/GraphCreatorTestCase.java	2009-07-08 15:22:30 UTC (rev 90941)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/graph/test/GraphCreatorTestCase.java	2009-07-08 16:14:23 UTC (rev 90942)
@@ -27,6 +27,7 @@
 import org.jboss.mctools.grapher.graph.AllGraphCreator;
 import org.jboss.mctools.grapher.graph.BeanGraphCreator;
 import org.jboss.mctools.grapher.graph.GraphCreator;
+import org.jboss.mctools.grapher.graph.TreeGraphCreator;
 import org.jboss.test.mctools.grapher.GrapherTest;
 import org.jgraph.JGraph;
 import org.jgraph.graph.DefaultGraphCell;
@@ -79,4 +80,9 @@
    {
       assertGraphCreator(new BeanGraphCreator("Dep2"), 2, 2);
    }
+
+   public void testTree()
+   {
+      assertGraphCreator(new TreeGraphCreator("Dep2"), 3, 3);
+   }
 }




More information about the jboss-cvs-commits mailing list