[jboss-cvs] JBossAS SVN: r91344 - 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
Thu Jul 16 09:51:40 EDT 2009
Author: alesj
Date: 2009-07-16 09:51:40 -0400 (Thu, 16 Jul 2009)
New Revision: 91344
Added:
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/GrapherConstants.java
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/AbstractGraphCreator.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AllGraphCreator.java
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/GraphCreator.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/TreeGraphCreator.java
projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/graph/test/GraphCreatorTestCase.java
Log:
Exclude different ControllerContext types.
Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherConstants.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherConstants.java 2009-07-16 13:14:43 UTC (rev 91343)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherConstants.java 2009-07-16 13:51:40 UTC (rev 91344)
@@ -50,7 +50,7 @@
public static final GraphCreatorMapper MAPPER = new DefaultGraphCreatorMapper();
/** The default layout */
- public static final GraphLayout LAYOUT = new ReflectionGraphLayout("com.jgraph.layout.tree.JGraphTreeLayout");
+ public static final GraphLayout LAYOUT = new ReflectionGraphLayout("com.jgraph.layout.tree.JGraphRadialTreeLayout");
/** The edge routing */
public static final Edge.Routing ROUTING = ParallelSplineRouter.getInstance();
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-16 13:14:43 UTC (rev 91343)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherServlet.java 2009-07-16 13:51:40 UTC (rev 91344)
@@ -38,6 +38,7 @@
import org.jboss.mctools.grapher.graph.GraphCreator;
import org.jboss.mctools.grapher.layout.GraphLayout;
import org.jboss.mctools.grapher.map.GraphCreatorMapper;
+import org.jboss.mctools.grapher.map.ExcludeTypes;
import org.jboss.mctools.grapher.render.GIFRenderer;
import org.jboss.mctools.grapher.render.JPGRenderer;
import org.jboss.mctools.grapher.render.PNGRenderer;
@@ -152,7 +153,7 @@
if (log.isTraceEnabled())
log.trace("Invoking creator: " + creator);
- JGraph graph = creator.createGraph(controller);
+ JGraph graph = creator.createGraph(controller, ExcludeTypes.createExcludedTypes(request));
// apply layout
layout.applyLayout(graph);
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-16 13:14:43 UTC (rev 91343)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java 2009-07-16 13:51:40 UTC (rev 91344)
@@ -56,67 +56,28 @@
/** The graph component factory */
private GraphComponentFactory factory = GrapherConstants.COMPONENT_FACTORY;
- public JGraph createGraph(KernelController controller)
+ public JGraph createGraph(KernelController controller, Class<? extends ControllerContext>... excludedTypes)
{
Map attributes = new HashMap();
ConnectionSet cs = new ConnectionSet();
- Object[] cells = createCells(controller, attributes, cs);
+ Object[] cells = createCells(controller, attributes, cs, excludedTypes);
return createGraph(cells, attributes, cs);
}
/**
- * Create graph.
- *
- * @param cells the graph cells
- * @param attributes the graph attributes
- * @param cs the connection set
- * @return new jgraph instance
- */
- protected JGraph createGraph(Object[] cells, Map attributes, ConnectionSet cs)
- {
- log.info("Creating graph from " + cells.length + " objects.");
- if (log.isTraceEnabled())
- log.trace("Graph objects: " + Arrays.asList(cells));
-
- GraphModel model = new ModifiedGraphModel();
- //create simple layout
- GraphSettings.layout(cells, attributes);
- // insert cells
- model.insert(cells, attributes, cs, null, null);
- JGraph graph = new JGraph(model);
- applySwingHack(graph);
- return graph;
- }
-
- /**
- * Apply swing hack.
- *
- * @param graph the graph
- */
- protected void applySwingHack(JGraph graph)
- {
- JPanel panel = new JPanel();
- panel.setDoubleBuffered(false);// always turn double buffering off when exporting
- panel.add(graph);
- panel.setVisible(true);
- panel.setEnabled(true);
- panel.addNotify();// workaround to pack() on a JFrame
- panel.validate();
- }
-
- /**
* Create cells.
*
* @param controller the controller
* @param attributes the attributes
* @param cs the connection set
+ * @param excludedTypes the excluded component types
* @return graph cells
*/
- protected Object[] createCells(KernelController controller, Map attributes, ConnectionSet cs)
+ protected Object[] createCells(KernelController controller, Map attributes, ConnectionSet cs, Class<? extends ControllerContext>... excludedTypes)
{
Map<Object, GraphCell> cells = new HashMap<Object, GraphCell>();
Set<Object> objects = new HashSet<Object>();
- createCells(controller, cells, objects, attributes, cs);
+ createCells(controller, cells, objects, attributes, cs, excludedTypes);
// change to array
Object[] graph = new Object[objects.size()];
@@ -135,21 +96,11 @@
* @param objects the graph's objects
* @param attributes the graph attributes
* @param cs the connection set
+ * @param excludedTypes the excluded component types
*/
- protected abstract void createCells(KernelController controller, Map<Object, GraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs);
+ protected abstract void createCells(KernelController controller, Map<Object, GraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs, Class<? extends ControllerContext>... excludedTypes);
/**
- * Create the cell.
- *
- * @param label the cell's label
- * @return new cell instance
- */
- protected GraphCell createCell(Object label)
- {
- return factory.createVertex(label);
- }
-
- /**
* Do we recurse into context.
*
* @param context the context to examine
@@ -169,10 +120,19 @@
* @param attributes the graph attributes
* @param cs the connection set
* @param context the context to render
+ * @param excludedTypes the excluded component types
*/
@SuppressWarnings({"UnusedDeclaration"})
- protected void handleContext(KernelController controller, Map<Object, GraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs, ControllerContext context)
+ protected void handleContext(KernelController controller, Map<Object, GraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs, ControllerContext context, Class<? extends ControllerContext>... excludedTypes)
{
+ if (isComponentExcluded(context, excludedTypes))
+ {
+ if (log.isTraceEnabled())
+ log.trace("Component is excluded [" + Arrays.asList(excludedTypes) + "]: " + context);
+
+ return;
+ }
+
GraphCell owner = getCell(cells, objects, context);
DependencyInfo info = context.getDependencyInfo();
@@ -184,11 +144,19 @@
Object iDependOn = item.getIDependOn();
GraphCell dependency = cells.get(iDependOn);
ControllerContext dependant = null;
- if (dependency == null)
+ if (dependency == null || (excludedTypes != null && excludedTypes.length > 0))
{
dependant = controller.getContext(iDependOn, null);
if (dependant != null)
{
+ if (isComponentExcluded(dependant, excludedTypes))
+ {
+ if (log.isTraceEnabled())
+ log.trace("Component is excluded [" + Arrays.asList(excludedTypes) + "]: " + dependant);
+
+ return;
+ }
+
dependency = getCell(cells, objects, dependant);
}
else
@@ -210,6 +178,80 @@
}
/**
+ * Is the context excluded.
+ *
+ * @param context the context
+ * @param excludedTypes the excluded types
+ * @return true if excluded, false otherwise
+ */
+ protected boolean isComponentExcluded(ControllerContext context, Class<? extends ControllerContext>... excludedTypes)
+ {
+ if (context == null)
+ return true;
+
+ if (excludedTypes == null || excludedTypes.length == 0)
+ return false;
+
+ for (Class<? extends ControllerContext> excluded : excludedTypes)
+ {
+ if (excluded.isInstance(context))
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Create graph.
+ *
+ * @param cells the graph cells
+ * @param attributes the graph attributes
+ * @param cs the connection set
+ * @return new jgraph instance
+ */
+ protected JGraph createGraph(Object[] cells, Map attributes, ConnectionSet cs)
+ {
+ log.info("Creating graph from " + cells.length + " objects.");
+ if (log.isTraceEnabled())
+ log.trace("Graph objects: " + Arrays.asList(cells));
+
+ GraphModel model = new ModifiedGraphModel();
+ //create simple layout
+ GraphSettings.layout(cells, attributes);
+ // insert cells
+ model.insert(cells, attributes, cs, null, null);
+ JGraph graph = new JGraph(model);
+ applySwingHack(graph);
+ return graph;
+ }
+
+ /**
+ * Apply swing hack.
+ *
+ * @param graph the graph
+ */
+ protected void applySwingHack(JGraph graph)
+ {
+ JPanel panel = new JPanel();
+ panel.setDoubleBuffered(false);// always turn double buffering off when exporting
+ panel.add(graph);
+ panel.setVisible(true);
+ panel.setEnabled(true);
+ panel.addNotify();// workaround to pack() on a JFrame
+ panel.validate();
+ }
+
+ /**
+ * Create the cell.
+ *
+ * @param label the cell's label
+ * @return new cell instance
+ */
+ protected GraphCell createCell(Object label)
+ {
+ return factory.createVertex(label);
+ }
+
+ /**
* Get the cell for the param context.
*
* @param cells the current cells
Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AllGraphCreator.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AllGraphCreator.java 2009-07-16 13:14:43 UTC (rev 91343)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AllGraphCreator.java 2009-07-16 13:51:40 UTC (rev 91344)
@@ -38,7 +38,7 @@
*/
public class AllGraphCreator extends AbstractGraphCreator
{
- protected void createCells(KernelController controller, Map<Object, GraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs)
+ protected void createCells(KernelController controller, Map<Object, GraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs, Class<? extends ControllerContext>... excludedTypes)
{
ControllerStateModel model = controller.getStates();
for (ControllerState state : model)
@@ -46,7 +46,7 @@
Set<ControllerContext> contexts = controller.getContextsByState(state);
for (ControllerContext context : contexts)
{
- handleContext(controller, cells, objects, attributes, cs, context);
+ handleContext(controller, cells, objects, attributes, cs, context, excludedTypes);
}
}
}
Modified: 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/BeanGraphCreator.java 2009-07-16 13:14:43 UTC (rev 91343)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/BeanGraphCreator.java 2009-07-16 13:51:40 UTC (rev 91344)
@@ -46,13 +46,13 @@
this.bean = bean;
}
- protected void createCells(KernelController controller, Map<Object, GraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs)
+ protected void createCells(KernelController controller, Map<Object, GraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs, Class<? extends ControllerContext>... excludedTypes)
{
ControllerContext context = controller.getContext(bean, null);
if (context == null)
throw new IllegalArgumentException("No such context: " + bean);
- handleContext(controller, cells, objects, attributes, cs, context);
+ handleContext(controller, cells, objects, attributes, cs, context, excludedTypes);
}
@Override
Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GraphCreator.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GraphCreator.java 2009-07-16 13:14:43 UTC (rev 91343)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GraphCreator.java 2009-07-16 13:51:40 UTC (rev 91344)
@@ -21,6 +21,7 @@
*/
package org.jboss.mctools.grapher.graph;
+import org.jboss.dependency.spi.ControllerContext;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jgraph.JGraph;
@@ -37,7 +38,8 @@
* Create graph.
*
* @param controller the controller
+ * @param excludedTypes the excluded component types
* @return new jgraph instance
*/
- JGraph createGraph(KernelController controller);
+ JGraph createGraph(KernelController controller, Class<? extends ControllerContext>... excludedTypes);
}
Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/TreeGraphCreator.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/TreeGraphCreator.java 2009-07-16 13:14:43 UTC (rev 91343)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/TreeGraphCreator.java 2009-07-16 13:51:40 UTC (rev 91344)
@@ -49,13 +49,13 @@
visited = new HashSet<Object>();
}
- protected void createCells(KernelController controller, Map<Object, GraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs)
+ protected void createCells(KernelController controller, Map<Object, GraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs, Class<? extends ControllerContext>... excludedTypes)
{
ControllerContext context = controller.getContext(root, null);
if (context == null)
throw new IllegalArgumentException("No such context: " + root);
- handleContext(controller, cells, objects, attributes, cs, context);
+ handleContext(controller, cells, objects, attributes, cs, context, excludedTypes);
}
@Override
Added: 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 (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/ExcludeTypes.java 2009-07-16 13:51:40 UTC (rev 91344)
@@ -0,0 +1,124 @@
+/*
+ * 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
+ {
+ map.put("pojo", AbstractKernelControllerContext.class);
+ map.put("alias", AliasControllerContext.class);
+ map.put("ext", AbstractKernelRegistryEntry.class);
+ map.put("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 className the class name
+ */
+ protected static void mapControllerContextClass(String key, String className)
+ {
+ 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-16 13:14:43 UTC (rev 91343)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/graph/test/GraphCreatorTestCase.java 2009-07-16 13:51:40 UTC (rev 91344)
@@ -24,10 +24,13 @@
import java.util.Arrays;
import junit.framework.Test;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
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.mctools.grapher.map.ExcludeTypes;
import org.jboss.test.mctools.grapher.GrapherTest;
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultGraphCell;
@@ -55,9 +58,10 @@
return "Owner";
}
- protected void assertGraphCreator(GraphCreator creator, int vertices, int edges)
+ protected void assertGraphCreator(GraphCreator creator, int vertices, int edges, String... excludes)
{
- JGraph graph = creator.createGraph(getKernelController());
+ Class<? extends ControllerContext>[] excluded = ExcludeTypes.createExcludedTypes(false, excludes);
+ JGraph graph = creator.createGraph(getKernelController(), excluded);
Object[] roots = graph.getRoots();
assertNotNull(roots);
// make sure we just have vertices and edges
@@ -87,4 +91,32 @@
{
assertGraphCreator(new TreeGraphCreator("Dep2"), 3, 3);
}
+
+ public void testExcludePojos() throws Throwable
+ {
+ Controller controller = getKernelController();
+ controller.addAlias("ExtAlias", "Owner");
+ try
+ {
+ assertGraphCreator(new AllGraphCreator(), 1, 0, "pojo");
+ }
+ finally
+ {
+ controller.removeAlias("ExtAlias");
+ }
+ }
+
+ public void testExcludeAlias() throws Throwable
+ {
+ Controller controller = getKernelController();
+ controller.addAlias("ExtAlias", "Owner");
+ try
+ {
+ assertGraphCreator(new AllGraphCreator(), 3, 3, "alias");
+ }
+ finally
+ {
+ controller.removeAlias("ExtAlias");
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list