[jboss-cvs] JBossAS SVN: r91434 - 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
Mon Jul 20 14:31:46 EDT 2009
Author: alesj
Date: 2009-07-20 14:31:46 -0400 (Mon, 20 Jul 2009)
New Revision: 91434
Added:
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/AbstractGraphComponentMapper.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultGraphLayoutMapper.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultRendererMapper.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/GraphComponentMapper.java
Removed:
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/GraphCreatorMapper.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/GraphLayoutMapping.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/map/DefaultGraphCreatorMapper.java
projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/RendererTestCase.java
projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/Write2FileTestCase.java
Log:
Have single mapper api.
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-20 18:31:01 UTC (rev 91433)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherConstants.java 2009-07-20 18:31:46 UTC (rev 91434)
@@ -25,10 +25,14 @@
import org.jboss.mctools.grapher.graph.DefaultGraphComponentFactory;
import org.jboss.mctools.grapher.graph.GraphComponentFactory;
+import org.jboss.mctools.grapher.graph.GraphCreator;
import org.jboss.mctools.grapher.layout.DefaultGraphLayout;
import org.jboss.mctools.grapher.layout.GraphLayout;
import org.jboss.mctools.grapher.map.DefaultGraphCreatorMapper;
-import org.jboss.mctools.grapher.map.GraphCreatorMapper;
+import org.jboss.mctools.grapher.map.DefaultGraphLayoutMapper;
+import org.jboss.mctools.grapher.map.DefaultRendererMapper;
+import org.jboss.mctools.grapher.map.GraphComponentMapper;
+import org.jboss.mctools.grapher.render.Renderer;
import org.jboss.mctools.grapher.routing.ParallelSplineRouter;
import org.jgraph.graph.Edge;
@@ -46,12 +50,18 @@
/** The default format */
public static final String FORMAT = "gif";
- /** The default mapper */
- public static final GraphCreatorMapper MAPPER = new DefaultGraphCreatorMapper();
+ /** The default creator mapper */
+ public static final GraphComponentMapper<GraphCreator> CREATOR_MAPPER = new DefaultGraphCreatorMapper();
/** The default layout */
public static final GraphLayout LAYOUT = new DefaultGraphLayout();
+ /** The default layout mapper */
+ public static final GraphComponentMapper<GraphLayout> LAYOUT_MAPPER = new DefaultGraphLayoutMapper();
+
+ /** The default renderer mapper */
+ public static final GraphComponentMapper<Renderer> RENDERER_MAPPER = new DefaultRendererMapper();
+
/** 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-20 18:31:01 UTC (rev 91433)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherServlet.java 2009-07-20 18:31:46 UTC (rev 91434)
@@ -23,8 +23,7 @@
import java.io.IOException;
import java.io.OutputStream;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Collections;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@@ -37,14 +36,9 @@
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.GraphLayoutMapping;
-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;
+import org.jboss.mctools.grapher.map.GraphComponentMapper;
import org.jboss.mctools.grapher.render.Renderer;
-import org.jboss.mctools.grapher.render.SVGRenderer;
import org.jgraph.JGraph;
/**
@@ -67,16 +61,13 @@
private String previous;
private KernelController controller;
- private GraphCreatorMapper mapper;
- private GraphLayout layout;
- /**
- * The default renderer
- */
- private Renderer renderer;
- private Map<String, Renderer> renderers;
+ private GraphComponentMapper<GraphCreator> creatorMapper;
+ private GraphComponentMapper<GraphLayout> layoutMapper;
+ private GraphComponentMapper<Renderer> rendererMapper;
@Override
+ @SuppressWarnings("unchecked")
public void init(ServletConfig config) throws ServletException
{
ServletContext context = config.getServletContext();
@@ -86,24 +77,12 @@
controller = connector.getUtility();
- mapper = createInstance(config.getInitParameter("mapper"), GrapherConstants.MAPPER, GraphCreatorMapper.class);
- layout = createInstance(config.getInitParameter("layout"), GrapherConstants.LAYOUT, GraphLayout.class);
+ creatorMapper = createMapper(config.getInitParameter("creator"), GrapherConstants.CREATOR_MAPPER, GraphCreator.class);
+ layoutMapper = createMapper(config.getInitParameter("layout"), GrapherConstants.LAYOUT_MAPPER, GraphLayout.class);
- renderers = new HashMap<String, Renderer>();
- renderers.put("svg", new SVGRenderer());
- renderers.put("jpg", new JPGRenderer());
- renderers.put("png", new PNGRenderer());
- renderers.put("gif", new GIFRenderer());
+ rendererMapper = createMapper(config.getInitParameter("renderer"), GrapherConstants.RENDERER_MAPPER, Renderer.class);
+ rendererMapper.init(Collections.singletonMap("format", config.getInitParameter("format")));
- // do we have short extension
- String defaultRenderer = config.getInitParameter("renderer");
- if (defaultRenderer != null)
- renderer = renderers.get(defaultRenderer);
-
- // or is this a new impl
- if (renderer == null)
- renderer = createInstance(defaultRenderer, renderers.get(GrapherConstants.FORMAT), Renderer.class);
-
// apply headless graphics
previous = System.setProperty(AWT_HEADLESS_FLAG, "true");
if ("false".equals(previous))
@@ -122,24 +101,6 @@
}
/**
- * Get renderer.
- *
- * @param key the key
- * @return current renderer
- */
- protected Renderer getRenderer(String key)
- {
- if (key == null)
- return renderer;
-
- Renderer current = renderers.get(key);
- if (current == null)
- current = renderer;
-
- return current;
- }
-
- /**
* Do render MC graph.
*
* @param request the http request
@@ -149,7 +110,7 @@
*/
protected void doRenderGraph(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
- GraphCreator creator = mapGraphCreator(request);
+ GraphCreator creator = creatorMapper.mapComponent(request);
if (log.isTraceEnabled())
log.trace("Invoking creator: " + creator);
@@ -157,10 +118,10 @@
JGraph graph = creator.createGraph(controller, ExcludeTypes.createExcludedTypes(request));
// apply layout
- GraphLayout currentLayout = mapGraphLayout(request);
+ GraphLayout currentLayout = layoutMapper.mapComponent(request);
currentLayout.applyLayout(graph);
- Renderer currentRenderer = getRenderer(request.getParameter("renderer"));
+ Renderer currentRenderer = rendererMapper.mapComponent(request);
if (log.isTraceEnabled())
log.trace("Using renderer: " + currentRenderer);
@@ -175,32 +136,6 @@
}
}
- /**
- * Map graph creator from request.
- *
- * @param request the current http request
- * @return graph creator instance
- */
- protected GraphCreator mapGraphCreator(HttpServletRequest request)
- {
- return mapper.mapFromRequest(request);
- }
-
- /**
- * Map graph layout.
- *
- * @param request the current http request
- * @return
- */
- protected GraphLayout mapGraphLayout(HttpServletRequest request)
- {
- String layoutKey = request.getParameter("layout");
- if (layoutKey == null)
- return layout;
-
- return GraphLayoutMapping.getLayout(layoutKey);
- }
-
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
@@ -214,7 +149,7 @@
}
/**
- * Create new instance.
+ * Create new mapper.
*
* @param reference the class name reference
* @param defaultInstance the default instance
@@ -222,7 +157,7 @@
* @param <T> the expected type
* @return new instance or default for any error
*/
- protected <T> T createInstance(String reference, T defaultInstance, Class<T> expectedClass)
+ protected <T> GraphComponentMapper<T> createMapper(String reference, GraphComponentMapper<T> defaultInstance, Class<T> expectedClass)
{
if (reference == null)
return defaultInstance;
@@ -231,7 +166,8 @@
{
Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(reference);
Object object = clazz.newInstance();
- return expectedClass.cast(object);
+ //noinspection unchecked
+ return GraphComponentMapper.class.cast(object);
}
catch (Exception e)
{
@@ -239,4 +175,4 @@
}
return defaultInstance;
}
- }
+}
Added: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/AbstractGraphComponentMapper.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/AbstractGraphComponentMapper.java (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/AbstractGraphComponentMapper.java 2009-07-20 18:31:46 UTC (rev 91434)
@@ -0,0 +1,72 @@
+/*
+ * 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.Map;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * The abstract type mapper.
+ *
+ * @param <T> component type
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractGraphComponentMapper<T> implements GraphComponentMapper<T>
+{
+ public void init(Map<String, String> config)
+ {
+ }
+
+ /**
+ * Get key parameter name.
+ *
+ * @return the key parameter name
+ */
+ protected abstract String getKey();
+
+ /**
+ * Should we skip null value.
+ *
+ * @return true if we skip null, false otherwise
+ */
+ protected boolean skipNull()
+ {
+ return true;
+ }
+
+ public T mapComponent(HttpServletRequest request)
+ {
+ String key = getKey();
+ String value = request.getParameter(key);
+ return (value == null && skipNull()) ? getDefault() : mapComponent(key, value);
+ }
+
+ /**
+ * Get default impl.
+ *
+ * @return the default impl
+ */
+ protected T getDefault()
+ {
+ return null;
+ }
+}
\ 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-20 18:31:01 UTC (rev 91433)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultGraphCreatorMapper.java 2009-07-20 18:31:46 UTC (rev 91434)
@@ -21,22 +21,31 @@
*/
package org.jboss.mctools.grapher.map;
+import java.util.Map;
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.TreeGraphCreator;
import org.jboss.mctools.grapher.graph.DeploymentGraphCreator;
+import org.jboss.mctools.grapher.graph.AllGraphCreator;
/**
* Default graph creator mapper.
*
* @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*/
-public class DefaultGraphCreatorMapper implements GraphCreatorMapper
+public class DefaultGraphCreatorMapper implements GraphComponentMapper<GraphCreator>
{
- public GraphCreator mapFromRequest(HttpServletRequest request)
+ /** The default grapf creator */
+ public static final GraphCreator ALL = new AllGraphCreator();
+
+ public void init(Map<String, String> config)
{
+ }
+
+ public GraphCreator mapComponent(HttpServletRequest request)
+ {
String bean = request.getParameter("bean");
if (bean != null)
return new BeanGraphCreator(bean);
@@ -50,11 +59,37 @@
{
String type = request.getParameter("folder");
if (type == null)
- type = "deploy";
+ type = getFolder();
return new DeploymentGraphCreator(type, deployment, Boolean.valueOf(request.getParameter("recurse")));
}
return ALL;
}
+
+ /**
+ * Get default folder.
+ *
+ * @return the folder
+ */
+ protected String getFolder()
+ {
+ return "deploy";
+ }
+
+ public GraphCreator mapComponent(String key, String value)
+ {
+ if ("bean".equals(key))
+ return new BeanGraphCreator(value);
+
+ if ("root".equals(key))
+ return new TreeGraphCreator(value);
+
+ if ("deployment".equals(key))
+ {
+ return new DeploymentGraphCreator(getFolder(), value);
+ }
+
+ return ALL;
+ }
}
Copied: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultGraphLayoutMapper.java (from rev 91428, projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/GraphLayoutMapping.java)
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultGraphLayoutMapper.java (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultGraphLayoutMapper.java 2009-07-20 18:31:46 UTC (rev 91434)
@@ -0,0 +1,104 @@
+/*
+ * 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.Map;
+import java.util.HashMap;
+
+import org.jboss.mctools.grapher.GrapherConstants;
+import org.jboss.mctools.grapher.layout.GraphLayout;
+import org.jboss.mctools.grapher.layout.ReflectionGraphLayout;
+
+/**
+ * Map simple name to full layout class name.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public final class DefaultGraphLayoutMapper extends AbstractGraphComponentMapper<GraphLayout>
+{
+ private static final Map<String, String> map = new HashMap<String, String>();
+
+ static
+ {
+ // a ctor hack
+ map.put("simple0", "com.jgraph.layout.graph.JGraphSimpleLayout");
+ map.put("simple1", "com.jgraph.layout.graph.JGraphSimpleLayout");
+ map.put("simple2", "com.jgraph.layout.graph.JGraphSimpleLayout");
+
+ map.put("tree", "com.jgraph.layout.tree.JGraphTreeLayout");
+ map.put("spring", "com.jgraph.layout.graph.JGraphSpringLayout");
+ map.put("hierarchical", "com.jgraph.layout.hierarchical.JGrapHierarchicalhLayout");
+ map.put("compound", "com.jgraph.layout.JGraphCompoundLayout");
+ map.put("compact", "com.jgraph.layout.tree.JGraphCompactTreeLayout");
+ map.put("moen", "com.jgraph.layout.graph.JGraphMoenLayout");
+ map.put("radial", "com.jgraph.layout.graph.JGraphRadialTreeLayout");
+ map.put("annealing", "com.jgraph.layout.graph.JGraphAnnealingLayout");
+ map.put("fr", "com.jgraph.layout.graph.JGraphFRLayout");
+ map.put("organic", "com.jgraph.layout.organic.JGraphOrganicLayout");
+ map.put("self", "com.jgraph.layout.organic.JGraphSelfOrganizingOrganicLayout");
+ map.put("isom", "com.jgraph.layout.graph.JGraphISOMLayout");
+ map.put("org", "com.jgraph.layout.tree.OrganizationalLayout");
+ }
+
+ protected String getKey()
+ {
+ return "layout";
+ }
+
+ @Override
+ protected boolean skipNull()
+ {
+ return false;
+ }
+
+ public GraphLayout mapComponent(String key, String value)
+ {
+ return getLayout(value);
+ }
+
+ /**
+ * Get layout.
+ *
+ * @param key the layout key
+ * @return the layout
+ */
+ static GraphLayout getLayout(String key)
+ {
+ if (key == null)
+ return GrapherConstants.LAYOUT;
+
+ String className = map.get(key);
+ if (className == null)
+ return GrapherConstants.LAYOUT;
+
+ // treat simple differently
+ if (key.startsWith("simple"))
+ {
+ int arg = Integer.parseInt(key.substring("simple".length()));
+ return new ReflectionGraphLayout(className, new Class<?>[]{int.class}, new Object[]{arg});
+ }
+ else
+ {
+ return new ReflectionGraphLayout(className);
+ }
+ }
+}
Copied: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultRendererMapper.java (from rev 91383, 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/DefaultRendererMapper.java (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultRendererMapper.java 2009-07-20 18:31:46 UTC (rev 91434)
@@ -0,0 +1,83 @@
+/*
+ * 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.HashMap;
+import java.util.Map;
+
+import org.jboss.mctools.grapher.render.GIFRenderer;
+import org.jboss.mctools.grapher.render.JPGRenderer;
+import org.jboss.mctools.grapher.render.PNGRenderer;
+import org.jboss.mctools.grapher.render.Renderer;
+import org.jboss.mctools.grapher.render.SVGRenderer;
+import org.jboss.mctools.grapher.GrapherConstants;
+
+/**
+ * Default graph creator mapper.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DefaultRendererMapper extends AbstractGraphComponentMapper<Renderer>
+{
+ /**
+ * The default renderer
+ */
+ private Renderer defaultRenderer;
+ private Map<String, Renderer> renderers;
+
+ public DefaultRendererMapper()
+ {
+ renderers = new HashMap<String, Renderer>();
+ renderers.put("svg", new SVGRenderer());
+ renderers.put("jpg", new JPGRenderer());
+ renderers.put("png", new PNGRenderer());
+ renderers.put("gif", new GIFRenderer());
+ }
+
+ @Override
+ public void init(Map<String, String> config)
+ {
+ String format = (config != null) ? config.get("format") : null;
+ if (format != null)
+ defaultRenderer = renderers.get(format);
+
+ if (defaultRenderer == null)
+ defaultRenderer = renderers.get(GrapherConstants.FORMAT);
+ }
+
+ protected String getKey()
+ {
+ return "renderer";
+ }
+
+ public Renderer mapComponent(String key, String value)
+ {
+ Renderer renderer = renderers.get(value);
+ return (renderer != null) ? renderer : defaultRenderer;
+ }
+
+ @Override
+ protected Renderer getDefault()
+ {
+ return defaultRenderer;
+ }
+}
\ No newline at end of file
Added: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/GraphComponentMapper.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/GraphComponentMapper.java (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/GraphComponentMapper.java 2009-07-20 18:31:46 UTC (rev 91434)
@@ -0,0 +1,58 @@
+/*
+ * 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.Map;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * The type mapper.
+ *
+ * @param <T> component type
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface GraphComponentMapper<T>
+{
+ /**
+ * Initialize.
+ *
+ * @param config the config map
+ */
+ void init(Map<String, String> config);
+
+ /**
+ * Map component from request.
+ *
+ * @param request the request
+ * @return mapped component
+ */
+ T mapComponent(HttpServletRequest request);
+
+ /**
+ * Map component to the key.
+ *
+ * @param key the key
+ * @param value the value
+ * @return mapped component
+ */
+ T mapComponent(String key, String value);
+}
Deleted: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/GraphCreatorMapper.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/GraphCreatorMapper.java 2009-07-20 18:31:01 UTC (rev 91433)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/GraphCreatorMapper.java 2009-07-20 18:31:46 UTC (rev 91434)
@@ -1,46 +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 javax.servlet.http.HttpServletRequest;
-
-import org.jboss.mctools.grapher.graph.GraphCreator;
-import org.jboss.mctools.grapher.graph.AllGraphCreator;
-
-/**
- * Map servlet request to GraphCreator instance.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-public interface GraphCreatorMapper
-{
- /** The default grapf creator */
- static final GraphCreator ALL = new AllGraphCreator();
-
- /**
- * Map graph creator from request.
- *
- * @param request current servlet request
- * @return grapf creator instance
- */
- GraphCreator mapFromRequest(HttpServletRequest request);
-}
Deleted: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/GraphLayoutMapping.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/GraphLayoutMapping.java 2009-07-20 18:31:01 UTC (rev 91433)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/GraphLayoutMapping.java 2009-07-20 18:31:46 UTC (rev 91434)
@@ -1,88 +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.Map;
-import java.util.HashMap;
-
-import org.jboss.mctools.grapher.GrapherConstants;
-import org.jboss.mctools.grapher.layout.GraphLayout;
-import org.jboss.mctools.grapher.layout.ReflectionGraphLayout;
-
-/**
- * Map simple name to full layout class name.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-public final class GraphLayoutMapping
-{
- private static final Map<String, String> map = new HashMap<String, String>();
-
- static
- {
- // a ctor hack
- map.put("simple0", "com.jgraph.layout.graph.JGraphSimpleLayout");
- map.put("simple1", "com.jgraph.layout.graph.JGraphSimpleLayout");
- map.put("simple2", "com.jgraph.layout.graph.JGraphSimpleLayout");
-
- map.put("tree", "com.jgraph.layout.tree.JGraphTreeLayout");
- map.put("spring", "com.jgraph.layout.graph.JGraphSpringLayout");
- map.put("hierarchical", "com.jgraph.layout.hierarchical.JGrapHierarchicalhLayout");
- map.put("compound", "com.jgraph.layout.JGraphCompoundLayout");
- map.put("compact", "com.jgraph.layout.tree.JGraphCompactTreeLayout");
- map.put("moen", "com.jgraph.layout.graph.JGraphMoenLayout");
- map.put("radial", "com.jgraph.layout.graph.JGraphRadialTreeLayout");
- map.put("annealing", "com.jgraph.layout.graph.JGraphAnnealingLayout");
- map.put("fr", "com.jgraph.layout.graph.JGraphFRLayout");
- map.put("organic", "com.jgraph.layout.organic.JGraphOrganicLayout");
- map.put("self", "com.jgraph.layout.organic.JGraphSelfOrganizingOrganicLayout");
- map.put("isom", "com.jgraph.layout.graph.JGraphISOMLayout");
- map.put("org", "com.jgraph.layout.tree.OrganizationalLayout");
- }
-
- /**
- * Get layout.
- *
- * @param key the layout key
- * @return the layout
- */
- public static GraphLayout getLayout(String key)
- {
- if (key == null)
- return GrapherConstants.LAYOUT;
-
- String className = map.get(key);
- if (className == null)
- return GrapherConstants.LAYOUT;
-
- // treat simple differently
- if (key.startsWith("simple"))
- {
- int arg = Integer.parseInt(key.substring("simple".length()));
- return new ReflectionGraphLayout(className, new Class<?>[]{int.class}, new Object[]{arg});
- }
- else
- {
- return new ReflectionGraphLayout(className);
- }
- }
-}
Modified: projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/RendererTestCase.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/RendererTestCase.java 2009-07-20 18:31:01 UTC (rev 91433)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/RendererTestCase.java 2009-07-20 18:31:46 UTC (rev 91434)
@@ -25,7 +25,7 @@
import junit.framework.Test;
import org.jboss.mctools.grapher.graph.GraphCreator;
-import org.jboss.mctools.grapher.map.GraphCreatorMapper;
+import org.jboss.mctools.grapher.map.DefaultGraphCreatorMapper;
import org.jgraph.JGraph;
/**
@@ -63,7 +63,7 @@
public JGraph createGraph()
{
- GraphCreator creator = GraphCreatorMapper.ALL;
+ GraphCreator creator = DefaultGraphCreatorMapper.ALL;
return creator.createGraph(getKernelController());
}
}
\ No newline at end of file
Modified: projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/Write2FileTestCase.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/Write2FileTestCase.java 2009-07-20 18:31:01 UTC (rev 91433)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/Write2FileTestCase.java 2009-07-20 18:31:46 UTC (rev 91434)
@@ -29,7 +29,7 @@
import junit.framework.Test;
import org.jboss.mctools.grapher.graph.GraphCreator;
-import org.jboss.mctools.grapher.map.GraphCreatorMapper;
+import org.jboss.mctools.grapher.map.DefaultGraphCreatorMapper;
import org.jgraph.JGraph;
/**
@@ -82,7 +82,7 @@
public JGraph createGraph()
{
- GraphCreator creator = GraphCreatorMapper.ALL;
+ GraphCreator creator = DefaultGraphCreatorMapper.ALL;
return creator.createGraph(getKernelController());
}
More information about the jboss-cvs-commits
mailing list