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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 20 16:11:07 EDT 2009


Author: alesj
Date: 2009-07-20 16:11:07 -0400 (Mon, 20 Jul 2009)
New Revision: 91443

Added:
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/ComponentTypes.java
Removed:
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/ExcludeTypes.java
Modified:
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherServlet.java
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/DefaultGraphComponentFactory.java
   projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/graph/test/GraphCreatorTestCase.java
Log:
Map color.

Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherServlet.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherServlet.java	2009-07-20 19:42:07 UTC (rev 91442)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherServlet.java	2009-07-20 20:11:07 UTC (rev 91443)
@@ -36,7 +36,7 @@
 import org.jboss.mc.servlet.vdf.api.KernelControllerVDFConnector;
 import org.jboss.mctools.grapher.graph.GraphCreator;
 import org.jboss.mctools.grapher.layout.GraphLayout;
-import org.jboss.mctools.grapher.map.ExcludeTypes;
+import org.jboss.mctools.grapher.map.ComponentTypes;
 import org.jboss.mctools.grapher.map.GraphComponentMapper;
 import org.jboss.mctools.grapher.render.Renderer;
 import org.jgraph.JGraph;
@@ -115,7 +115,7 @@
       if (log.isTraceEnabled())
          log.trace("Invoking creator: " + creator);
 
-      JGraph graph = creator.createGraph(controller, ExcludeTypes.createExcludedTypes(request));
+      JGraph graph = creator.createGraph(controller, ComponentTypes.createExcludedTypes(request));
 
       // apply layout
       GraphLayout currentLayout = layoutMapper.mapComponent(request);

Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/DefaultGraphComponentFactory.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/DefaultGraphComponentFactory.java	2009-07-20 19:42:07 UTC (rev 91442)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/DefaultGraphComponentFactory.java	2009-07-20 20:11:07 UTC (rev 91443)
@@ -25,6 +25,7 @@
 
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.mctools.grapher.routing.ParallelSplineRouter;
+import org.jboss.mctools.grapher.map.ComponentTypes;
 import org.jgraph.graph.ConnectionSet;
 import org.jgraph.graph.DefaultGraphCell;
 import org.jgraph.graph.Edge;
@@ -38,11 +39,16 @@
  */
 public class DefaultGraphComponentFactory implements GraphComponentFactory
 {
+   /** The vertex color */
+   protected Color COLOR = Color.WHITE;
+
    /** The edge routing */
-   private final Edge.Routing routing = new ParallelSplineRouter();
+   protected Edge.Routing routing;
 
-   /** The vertex color */
-   private final Color COLOR = Color.WHITE;
+   public DefaultGraphComponentFactory()
+   {
+      routing = new ParallelSplineRouter();
+   }
 
    /**
     * Create vertex.
@@ -77,7 +83,7 @@
     */
    protected Color mapContextToColor(ControllerContext context)
    {
-      return Color.BLUE; // TODO
+      return ComponentTypes.mapColor(context);
    }
 
    public void enhanceVertex(GraphCell vertex, ControllerContext context)
@@ -98,8 +104,18 @@
       int arrow = GraphConstants.ARROW_CLASSIC;
       GraphConstants.setLineEnd(edge.getAttributes(), arrow);
       GraphConstants.setEndFill(edge.getAttributes(), true);
-      GraphConstants.setRouting(edge.getAttributes(), routing);
+      GraphConstants.setRouting(edge.getAttributes(), getRouting());
 
       return edge;
    }
+
+   protected Edge.Routing getRouting()
+   {
+      return routing;
+   }
+
+   public void setRouting(Edge.Routing routing)
+   {
+      this.routing = routing;
+   }
 }
\ No newline at end of file

Copied: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/ComponentTypes.java (from rev 91376, projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/ExcludeTypes.java)
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/ComponentTypes.java	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/ComponentTypes.java	2009-07-20 20:11:07 UTC (rev 91443)
@@ -0,0 +1,193 @@
+/*
+ * 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.map;
+
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+
+import org.jboss.dependency.plugins.AliasControllerContext;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.kernel.plugins.dependency.AbstractKernelControllerContext;
+import org.jboss.kernel.plugins.registry.AbstractKernelRegistryEntry;
+import org.jboss.kernel.plugins.registry.BeanKernelRegistryEntry;
+import org.jboss.logging.Logger;
+
+/**
+ * Create exclude types mapping.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+ at SuppressWarnings("unchecked")
+public final class ComponentTypes
+{
+   private static final Logger log = Logger.getLogger(ComponentTypes.class);
+
+   private static final Map<String, Class<? extends ControllerContext>> exclusions = new HashMap<String, Class<? extends ControllerContext>>();
+   private static final Map<Class<? extends ControllerContext>, Color> colors = new LinkedHashMap<Class<? extends ControllerContext>, Color>();
+
+   static
+   {
+      mapControllerContextClass("pojo", AbstractKernelControllerContext.class, Color.BLUE);
+      mapControllerContextClass("alias", AliasControllerContext.class, Color.LIGHT_GRAY);
+      mapControllerContextClass("core", BeanKernelRegistryEntry.class, Color.RED);
+      mapControllerContextClass("ext", AbstractKernelRegistryEntry.class, Color.ORANGE);
+      mapControllerContextClass("mbean", "org.jboss.system.microcontainer.ServiceControllerContext", Color.MAGENTA);
+      mapControllerContextClass("dep", "org.jboss.deployers.plugins.deployers.DeploymentControllerContext", Color.GREEN);
+   }
+
+   /**
+    * Map key to class.
+    *
+    * @param key the key
+    * @param clazz the class to map
+    * @param color the color
+    */
+   public static void mapControllerContextClass(String key, Class<? extends ControllerContext> clazz, Color color)
+   {
+      if (key == null)
+         throw new IllegalArgumentException("Null key");
+
+      if (clazz == null)
+      {
+         exclusions.remove(key);
+      }
+      else
+      {
+         exclusions.put(key, clazz);
+         colors.put(clazz, color);
+      }
+   }
+
+   /**
+    * Map key to class.
+    *
+    * @param key the key
+    * @param className the class name
+    * @param color the color
+    */
+   public static void mapControllerContextClass(String key, String className, Color color)
+   {
+      if (key == null)
+         throw new IllegalArgumentException("Null key");
+
+      if (className == null)
+      {
+         exclusions.remove(key);
+      }
+      else
+      {
+         try
+         {
+            Class<? extends ControllerContext> clazz = (Class<? extends ControllerContext>)ComponentTypes.class.getClassLoader().loadClass(className);
+            exclusions.put(key, clazz);
+            colors.put(clazz, color);
+         }
+         catch (Exception e)
+         {
+            log.warn("Unable to exclude component type: " + e);
+         }
+      }
+   }
+
+   /**
+    * Remove color mapping.
+    *
+    * @param clazz the component class
+    * @return the mapped color
+    */
+   public static Color removeColorMapping(Class<? extends ControllerContext> clazz)
+   {
+      return colors.remove(clazz);
+   }
+
+   /**
+    * Get excluded types.
+    *
+    * @param request the servlet request
+    * @return excluded types
+    */
+   public static Class<? extends ControllerContext>[] createExcludedTypes(HttpServletRequest request)
+   {
+      String exclude = request.getParameter("exclude");
+      String[] split = (exclude != null) ? exclude.split(",") : new String[]{};
+      return createExcludedTypes(request.getParameter("all") != null, split);
+   }
+
+   /**
+    * Get excluded types.
+    *
+    * @param all exclude all
+    * @param excludes the excludes
+    * @return excluded types
+    */
+   public static Class<? extends ControllerContext>[] createExcludedTypes(boolean all, String... excludes)
+   {
+      if (excludes == null || excludes.length == 0)
+      {
+         // by default we exclude deployments
+         Class<? extends ControllerContext> dep = exclusions.get("dep");
+         if (all == false && dep != null)
+         {
+            List<Class<? extends ControllerContext>> singleton = Collections.<Class<? extends ControllerContext>>singletonList(dep);
+            return singleton.toArray(new Class[1]);
+         }
+         else
+         {
+            return null;
+         }
+      }
+
+      List<Class<? extends ControllerContext>> result = new ArrayList<Class<? extends ControllerContext>>();
+      for (String key : excludes)
+      {
+         Class<? extends ControllerContext> clazz = exclusions.get(key);
+         if (clazz != null)
+            result.add(clazz);
+      }
+      return result.toArray(new Class[result.size()]);
+   }
+
+   /**
+    * Get mapped color.
+    *
+    * @param context the context
+    * @return mapped color
+    */
+   public static Color mapColor(ControllerContext context)
+   {
+      if (context == null)
+         return Color.WHITE;
+
+      for (Map.Entry<Class<? extends ControllerContext>, Color> entry : colors.entrySet())
+      {
+         if (entry.getKey().isInstance(context))
+            return entry.getValue();
+      }
+      return Color.YELLOW;
+   }
+}

Deleted: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/ExcludeTypes.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/ExcludeTypes.java	2009-07-20 19:42:07 UTC (rev 91442)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/ExcludeTypes.java	2009-07-20 20:11:07 UTC (rev 91443)
@@ -1,155 +0,0 @@
-/*
- * 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.map;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
-
-import org.jboss.dependency.plugins.AliasControllerContext;
-import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.kernel.plugins.dependency.AbstractKernelControllerContext;
-import org.jboss.kernel.plugins.registry.AbstractKernelRegistryEntry;
-import org.jboss.kernel.plugins.registry.BeanKernelRegistryEntry;
-import org.jboss.logging.Logger;
-
-/**
- * Create exclude types mapping.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
- at SuppressWarnings("unchecked")
-public final class ExcludeTypes
-{
-   private static final Logger log = Logger.getLogger(ExcludeTypes.class);
-   private static final Map<String, Class<? extends ControllerContext>> map = new HashMap<String, Class<? extends ControllerContext>>();
-
-   static
-   {
-      mapControllerContextClass("pojo", AbstractKernelControllerContext.class);
-      mapControllerContextClass("alias", AliasControllerContext.class);
-      mapControllerContextClass("ext", AbstractKernelRegistryEntry.class);
-      mapControllerContextClass("core", BeanKernelRegistryEntry.class);
-      mapControllerContextClass("mbean", "org.jboss.system.microcontainer.ServiceControllerContext");
-      mapControllerContextClass("dep", "org.jboss.deployers.plugins.deployers.DeploymentControllerContext");
-   }
-
-   /**
-    * Map key to class.
-    *
-    * @param key the key
-    * @param clazz the class to map
-    */
-   public static void mapControllerContextClass(String key, Class<? extends ControllerContext> clazz)
-   {
-      if (key == null)
-         throw new IllegalArgumentException("Null key");
-
-      if (clazz == null)
-      {
-         map.remove(key);
-      }
-      else
-      {
-         map.put(key, clazz);
-      }
-   }
-
-   /**
-    * Map key to class.
-    *
-    * @param key the key
-    * @param className the class name
-    */
-   public static void mapControllerContextClass(String key, String className)
-   {
-      if (key == null)
-         throw new IllegalArgumentException("Null key");
-
-      if (className == null)
-      {
-         map.remove(key);
-      }
-      else
-      {
-         try
-         {
-            Class<? extends ControllerContext> clazz = (Class<? extends ControllerContext>)ExcludeTypes.class.getClassLoader().loadClass(className);
-            map.put(key, clazz);
-         }
-         catch (Exception e)
-         {
-            log.warn("Unable to exclude component type: " + e);
-         }
-      }
-   }
-
-   /**
-    * Get excluded types.
-    *
-    * @param request the servlet request
-    * @return excluded types
-    */
-   public static Class<? extends ControllerContext>[] createExcludedTypes(HttpServletRequest request)
-   {
-      String exclude = request.getParameter("exclude");
-      String[] split = (exclude != null) ? exclude.split(",") : new String[]{};
-      return createExcludedTypes(request.getParameter("all") != null, split);
-   }
-
-   /**
-    * Get excluded types.
-    *
-    * @param all exclude all
-    * @param excludes the excludes
-    * @return excluded types
-    */
-   public static Class<? extends ControllerContext>[] createExcludedTypes(boolean all, String... excludes)
-   {
-      if (excludes == null || excludes.length == 0)
-      {
-         // by default we exclude deployments
-         Class<? extends ControllerContext> dep = map.get("dep");
-         if (all == false && dep != null)
-         {
-            List<Class<? extends ControllerContext>> singleton = Collections.<Class<? extends ControllerContext>>singletonList(dep);
-            return singleton.toArray(new Class[1]);
-         }
-         else
-         {
-            return null;
-         }
-      }
-
-      List<Class<? extends ControllerContext>> result = new ArrayList<Class<? extends ControllerContext>>();
-      for (String key : excludes)
-      {
-         Class<? extends ControllerContext> clazz = map.get(key);
-         if (clazz != null)
-            result.add(clazz);
-      }
-      return result.toArray(new Class[result.size()]);
-   }
-}

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-20 19:42:07 UTC (rev 91442)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/graph/test/GraphCreatorTestCase.java	2009-07-20 20:11:07 UTC (rev 91443)
@@ -32,7 +32,7 @@
 import org.jboss.mctools.grapher.graph.GVertex;
 import org.jboss.mctools.grapher.graph.GraphCreator;
 import org.jboss.mctools.grapher.graph.TreeGraphCreator;
-import org.jboss.mctools.grapher.map.ExcludeTypes;
+import org.jboss.mctools.grapher.map.ComponentTypes;
 import org.jboss.test.mctools.grapher.GrapherTest;
 import org.jgraph.JGraph;
 
@@ -60,7 +60,7 @@
 
    protected void assertGraphCreator(GraphCreator creator, int vertices, int edges, String... excludes)
    {
-      Class<? extends ControllerContext>[] excluded = ExcludeTypes.createExcludedTypes(false, excludes);
+      Class<? extends ControllerContext>[] excluded = ComponentTypes.createExcludedTypes(false, excludes);
       JGraph graph = creator.createGraph(getKernelController(), excluded);
       Object[] roots = graph.getRoots();
       assertNotNull(roots);




More information about the jboss-cvs-commits mailing list