Skip to content

Commit

Permalink
CAMEL-1023: camel:dot now draws pipeline correct. Also added labels f…
Browse files Browse the repository at this point in the history
…or choice, filter and when.

git-svn-id: https://svn.apache.org/repos/asf/activemq/camel/trunk@707553 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
davsclaus committed Oct 24, 2008
1 parent 248e36e commit 7d97070
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
Expand Up @@ -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";
Expand Down
20 changes: 3 additions & 17 deletions camel-core/src/main/java/org/apache/camel/view/NodeData.java
@@ -1,19 +1,3 @@
/**
* 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.
*/
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
Expand Down Expand Up @@ -92,10 +76,12 @@ public NodeData(String id, Object node, String imagePrefix) {
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";
Expand All @@ -105,7 +91,7 @@ public NodeData(String id, Object node, String imagePrefix) {
} 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;
Expand Down
Expand Up @@ -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;

Expand All @@ -37,6 +39,7 @@
* @version $Revision$
*/
public class RouteDotGenerator extends GraphGeneratorSupport {

public RouteDotGenerator(String dir) {
super(dir, ".dot");
}
Expand Down Expand Up @@ -96,8 +99,13 @@ protected NodeData printNode(PrintWriter writer, NodeData fromData, ProcessorTyp
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;
}
Expand Down Expand Up @@ -173,4 +181,27 @@ protected void generateFile(PrintWriter writer, Map<String, List<RouteType>> map

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;
}

}
10 changes: 8 additions & 2 deletions camel-core/src/test/java/org/apache/camel/view/DotViewTest.java
Expand Up @@ -38,6 +38,7 @@ protected void setUp() throws Exception {

context.addRoutes(new MulticastRoute());
context.addRoutes(new PipelineRoute());
context.addRoutes(new FromToRoute());
context.addRoutes(new ChoiceRoute());
context.addRoutes(new FilterRoute());
context.addRoutes(new ComplexRoute());
Expand All @@ -52,8 +53,13 @@ public void configure() throws Exception {

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");
}
}

Expand Down

0 comments on commit 7d97070

Please sign in to comment.