You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2010/03/10 17:50:51 UTC
svn commit: r921447 - in
/camel/trunk/camel-core/src/main/java/org/apache/camel/view:
GraphGeneratorSupport.java GraphSupport.java RouteDotGenerator.java
Author: jstrachan
Date: Wed Mar 10 16:50:51 2010
New Revision: 921447
URL: http://svn.apache.org/viewvc?rev=921447&view=rev
Log:
minor refactor of the Graph visualisation code making it easier to reuse the code without necessarily creating a text output file from the EIP model
Added:
camel/trunk/camel-core/src/main/java/org/apache/camel/view/GraphSupport.java (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/view/GraphGeneratorSupport.java
camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/view/GraphGeneratorSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/view/GraphGeneratorSupport.java?rev=921447&r1=921446&r2=921447&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/view/GraphGeneratorSupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/view/GraphGeneratorSupport.java Wed Mar 10 16:50:51 2010
@@ -42,14 +42,11 @@ import org.apache.commons.logging.LogFac
/**
* @version $Revision$
*/
-public abstract class GraphGeneratorSupport {
- protected final transient Log log = LogFactory.getLog(getClass());
+public abstract class GraphGeneratorSupport extends GraphSupport {
protected String dir;
protected int clusterCounter;
protected String extension;
- private final String imagePrefix = "http://camel.apache.org/images/eip/";
- private final Map<Object, NodeData> nodeMap = new HashMap<Object, NodeData>();
private final boolean makeParentDirs = true;
private Map<String, List<RouteDefinition>> routeGroupMap;
@@ -112,61 +109,4 @@ public abstract class GraphGeneratorSupp
protected abstract void generateFile(PrintWriter writer, Map<String, List<RouteDefinition>> map);
- protected boolean isMulticastNode(ProcessorDefinition node) {
- return node instanceof MulticastDefinition || node instanceof ChoiceDefinition;
- }
-
- protected String getLabel(List<ExpressionDefinition> expressions) {
- CollectionStringBuffer buffer = new CollectionStringBuffer();
- for (ExpressionDefinition expression : expressions) {
- buffer.append(getLabel(expression));
- }
- return buffer.toString();
- }
-
- protected String getLabel(ExpressionDefinition expression) {
- if (expression != null) {
- return expression.getLabel();
- }
- return "";
- }
-
- protected NodeData getNodeData(Object node) {
- Object key = node;
- if (node instanceof FromDefinition) {
- FromDefinition fromType = (FromDefinition) node;
- key = fromType.getUriOrRef();
- } else if (node instanceof ToDefinition) {
- ToDefinition toType = (ToDefinition) node;
- key = toType.getUriOrRef();
- }
- NodeData answer = nodeMap.get(key);
- if (answer == null) {
- String id = "node" + (nodeMap.size() + 1);
- answer = new NodeData(id, node, imagePrefix);
- nodeMap.put(key, answer);
- }
- return answer;
- }
-
- protected Map<String, List<RouteDefinition>> createRouteGroupMap(List<RouteDefinition> routes) {
- Map<String, List<RouteDefinition>> map = new HashMap<String, List<RouteDefinition>>();
- for (RouteDefinition route : routes) {
- addRouteToMap(map, route);
- }
- return map;
- }
-
- protected void addRouteToMap(Map<String, List<RouteDefinition>> map, RouteDefinition route) {
- String group = route.getGroup();
- if (group == null) {
- group = "Camel Routes";
- }
- List<RouteDefinition> list = map.get(group);
- if (list == null) {
- list = new ArrayList<RouteDefinition>();
- map.put(group, list);
- }
- list.add(route);
- }
}
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/view/GraphSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/view/GraphSupport.java?rev=921447&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/view/GraphSupport.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/view/GraphSupport.java Wed Mar 10 16:50:51 2010
@@ -0,0 +1,134 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.view;
+
+import org.apache.camel.model.ChoiceDefinition;
+import org.apache.camel.model.FromDefinition;
+import org.apache.camel.model.MulticastDefinition;
+import org.apache.camel.model.PipelineDefinition;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.ToDefinition;
+import org.apache.camel.model.language.ExpressionDefinition;
+import org.apache.camel.util.CollectionStringBuffer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A base class for Graph processing code of Camel EIPs contianing a number of helper methods
+ *
+ * @version $Revision: 1.1 $
+ */
+public class GraphSupport {
+ protected final transient Log log = LogFactory.getLog(getClass());
+ private String imagePrefix = "http://camel.apache.org/images/eip/";
+ protected final Map<Object, NodeData> nodeMap = new HashMap<Object, NodeData>();
+
+ protected String getLabel(List<ExpressionDefinition> expressions) {
+ CollectionStringBuffer buffer = new CollectionStringBuffer();
+ for (ExpressionDefinition expression : expressions) {
+ buffer.append(getLabel(expression));
+ }
+ return buffer.toString();
+ }
+
+ protected String getLabel(ExpressionDefinition expression) {
+ if (expression != null) {
+ return expression.getLabel();
+ }
+ return "";
+ }
+
+ protected NodeData getNodeData(Object node) {
+ Object key = node;
+ if (node instanceof FromDefinition) {
+ FromDefinition fromType = (FromDefinition) node;
+ key = fromType.getUriOrRef();
+ } else if (node instanceof ToDefinition) {
+ ToDefinition toType = (ToDefinition) node;
+ key = toType.getUriOrRef();
+ }
+ NodeData answer = nodeMap.get(key);
+ if (answer == null) {
+ String id = "node" + (nodeMap.size() + 1);
+ answer = new NodeData(id, node, imagePrefix);
+ nodeMap.put(key, answer);
+ }
+ return answer;
+ }
+
+ protected Map<String, List<RouteDefinition>> createRouteGroupMap(List<RouteDefinition> routes) {
+ Map<String, List<RouteDefinition>> map = new HashMap<String, List<RouteDefinition>>();
+ for (RouteDefinition route : routes) {
+ addRouteToMap(map, route);
+ }
+ return map;
+ }
+
+ protected void addRouteToMap(Map<String, List<RouteDefinition>> map, RouteDefinition route) {
+ String group = route.getGroup();
+ if (group == null) {
+ group = "Camel Routes";
+ }
+ List<RouteDefinition> list = map.get(group);
+ if (list == null) {
+ list = new ArrayList<RouteDefinition>();
+ map.put(group, list);
+ }
+ list.add(route);
+ }
+
+ protected boolean isMulticastNode(ProcessorDefinition node) {
+ return node instanceof MulticastDefinition || node instanceof ChoiceDefinition;
+ }
+
+ /**
+ * Is the given node a pipeline
+ */
+ protected boolean isPipeline(ProcessorDefinition node) {
+ if (node instanceof MulticastDefinition) {
+ return false;
+ }
+ if (node instanceof PipelineDefinition) {
+ return true;
+ }
+ if (node.getOutputs().size() > 1) {
+ // is pipeline if there is more than 1 output and they are all To types
+ for (Object type : node.getOutputs()) {
+ if (!(type instanceof ToDefinition)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public String getImagePrefix() {
+ return imagePrefix;
+ }
+
+ public void setImagePrefix(String imagePrefix) {
+ this.imagePrefix = imagePrefix;
+ }
+}
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/view/GraphSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java?rev=921447&r1=921446&r2=921447&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java Wed Mar 10 16:50:51 2010
@@ -173,26 +173,5 @@ public class RouteDotGenerator extends G
writer.println("}");
}
- /**
- * Is the given node a pipeline
- */
- private static boolean isPipeline(ProcessorDefinition node) {
- if (node instanceof MulticastDefinition) {
- return false;
- }
- if (node instanceof PipelineDefinition) {
- return true;
- }
- if (node.getOutputs().size() > 1) {
- // is pipeline if there is more than 1 output and they are all To types
- for (Object type : node.getOutputs()) {
- if (!(type instanceof ToDefinition)) {
- return false;
- }
- }
- return true;
- }
- return false;
- }
}