Author: davsclaus
Date: Thu Oct 23 22:59:58 2008
New Revision: 707553

URL: http://svn.apache.org/viewvc?rev=707553&view=rev
Log:
CAMEL-1023: camel:dot now draws pipeline correct. Also added labels for choice, 
filter and when.

Modified:
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/ModelFileGenerator.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/NodeData.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java
    
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/view/DotViewTest.java

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/ModelFileGenerator.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/ModelFileGenerator.java?rev=707553&r1=707552&r2=707553&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/ModelFileGenerator.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/ModelFileGenerator.java
 Thu Oct 23 22:59:58 2008
@@ -48,9 +48,6 @@
 import org.apache.camel.model.RoutesType;
 import org.apache.camel.util.ObjectHelper;
 
-
-
-
 public class ModelFileGenerator {
 
     private static final String DEFAULT_ROOT_ELEMENT_NAME = "routes";

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/NodeData.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/NodeData.java?rev=707553&r1=707552&r2=707553&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/NodeData.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/NodeData.java
 Thu Oct 23 22:59:58 2008
@@ -14,22 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/**
- * 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 java.util.ArrayList;
@@ -92,10 +76,12 @@
             this.url = 
"http://activemq.apache.org/camel/message-endpoint.html";;
         } else if (node instanceof FilterType) {
             this.image = imagePrefix + "MessageFilterIcon.png";
+            this.label = "Filter";
             this.nodeType = "Message Filter";
         } else if (node instanceof WhenType) {
             this.image = imagePrefix + "MessageFilterIcon.png";
             this.nodeType = "When Filter";
+            this.label = "When";
             this.url = 
"http://activemq.apache.org/camel/content-based-router.html";;
         } else if (node instanceof OtherwiseType) {
             this.nodeType = "Otherwise";
@@ -105,7 +91,7 @@
         } else if (node instanceof ChoiceType) {
             this.image = imagePrefix + "ContentBasedRouterIcon.png";
             this.nodeType = "Content Based Router";
-            this.label = "";
+            this.label = "Choice";
             this.edgeLabel = "";
 
             ChoiceType choice = (ChoiceType)node;

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java?rev=707553&r1=707552&r2=707553&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java
 Thu Oct 23 22:59:58 2008
@@ -26,6 +26,8 @@
 import org.apache.camel.model.MulticastType;
 import org.apache.camel.model.ProcessorType;
 import org.apache.camel.model.RouteType;
+import org.apache.camel.model.PipelineType;
+import org.apache.camel.model.ToType;
 
 import static org.apache.camel.util.ObjectHelper.isNotNullAndNonEmpty;
 
@@ -37,6 +39,7 @@
  * @version $Revision$
  */
 public class RouteDotGenerator extends GraphGeneratorSupport {
+
     public RouteDotGenerator(String dir) {
         super(dir, ".dot");
     }
@@ -96,8 +99,13 @@
         if (node instanceof MulticastType || node instanceof InterceptorRef) {
             // no need for a multicast or interceptor node
             List<ProcessorType> outputs = node.getOutputs();
+            boolean isPipeline = isPipeline(node);
             for (ProcessorType output : outputs) {
-                printNode(writer, fromData, output);
+                NodeData out = printNode(writer, fromData, output);
+                // if in pipeline then we should move the from node to the 
next in the pipeline
+                if (isPipeline) {
+                    fromData = out;
+                }
             }
             return fromData;
         }
@@ -173,4 +181,27 @@
 
         writer.println("}");
     }
+
+    /**
+     * Is the given node a pipeline
+     */
+    private static boolean isPipeline(ProcessorType node) {
+        if (node instanceof MulticastType) {
+            return false;
+        }
+        if (node instanceof PipelineType) {
+            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 ToType)) {
+                    return false;
+                }
+            }
+            return true;
+        }
+        return false;
+    }
+
 }

Modified: 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/view/DotViewTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/view/DotViewTest.java?rev=707553&r1=707552&r2=707553&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/view/DotViewTest.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/view/DotViewTest.java
 Thu Oct 23 22:59:58 2008
@@ -38,6 +38,7 @@
 
         context.addRoutes(new MulticastRoute());
         context.addRoutes(new PipelineRoute());
+        context.addRoutes(new FromToRoute());
         context.addRoutes(new ChoiceRoute());
         context.addRoutes(new FilterRoute());
         context.addRoutes(new ComplexRoute());
@@ -52,8 +53,13 @@
 
     static class PipelineRoute extends RouteBuilder {
         public void configure() throws Exception {
-            from("seda:pipeline.in").
-                    to("seda:pipeline.out1", "seda:pipeline.out2", 
"seda:pipeline.out3");
+            from("seda:pipeline.in").to("seda:pipeline.out1", 
"seda:pipeline.out2", "seda:pipeline.out3");
+        }
+    }
+
+    static class FromToRoute extends RouteBuilder {
+        public void configure() throws Exception {
+            from("seda:foo").to("seda:bar");
         }
     }
 


Reply via email to