svn commit: r566050 - in /activemq/camel/trunk/camel-core/src/main/java/org/apache/camel: converter/IOConverter.java util/CollectionStringBuffer.java view/RouteDotGenerator.java

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r566050 - in /activemq/camel/trunk/camel-core/src/main/java/org/apache/camel: converter/IOConverter.java util/CollectionStringBuffer.java view/RouteDotGenerator.java

jstrachan-2
Author: jstrachan
Date: Wed Aug 15 01:06:48 2007
New Revision: 566050

URL: http://svn.apache.org/viewvc?view=rev&rev=566050
Log:
minor refactor - adding helper class - and added support for more EIP patterns in the DOT generator

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionStringBuffer.java   (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java?view=diff&rev=566050&r1=566049&r2=566050
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java Wed Aug 15 01:06:48 2007
@@ -17,6 +17,7 @@
 package org.apache.camel.converter;
 
 import org.apache.camel.Converter;
+import org.apache.camel.util.CollectionStringBuffer;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -126,17 +127,11 @@
             return null;
         }
         try {
-            StringBuilder builder = new StringBuilder();
-            boolean first = true;
+            CollectionStringBuffer builder = new CollectionStringBuffer("\n");
             while (true) {
                 String line = reader.readLine();
                 if (line == null) {
                     return builder.toString();
-                }
-                if (first) {
-                    first = false;
-                } else {
-                    builder.append("\n");
                 }
                 builder.append(line);
             }

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionStringBuffer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionStringBuffer.java?view=auto&rev=566050
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionStringBuffer.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionStringBuffer.java Wed Aug 15 01:06:48 2007
@@ -0,0 +1,60 @@
+/**
+ *
+ * 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.util;
+
+/**
+ * A little helper class for converting a collection of values to a (usually comma separated) string.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class CollectionStringBuffer {
+    private StringBuffer buffer = new StringBuffer();
+    private String separator;
+    private boolean first = true;
+
+    public CollectionStringBuffer() {
+        this(", ");
+    }
+
+    public CollectionStringBuffer(String separator) {
+        this.separator = separator;
+    }
+
+    @Override
+    public String toString() {
+        return buffer.toString();
+    }
+
+    public void append(Object value) {
+        if (first) {
+            first = false;
+        }
+        else {
+            buffer.append(separator);
+        }
+        buffer.append(value);
+    }
+
+    public String getSeparator() {
+        return separator;
+    }
+
+    public void setSeparator(String separator) {
+        this.separator = separator;
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionStringBuffer.java
------------------------------------------------------------------------------
    svn:eol-style = native

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?view=diff&rev=566050&r1=566049&r2=566050
==============================================================================
--- 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 Wed Aug 15 01:06:48 2007
@@ -18,12 +18,9 @@
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Predicate;
-import org.apache.camel.model.FilterType;
-import org.apache.camel.model.FromType;
-import org.apache.camel.model.ProcessorType;
-import org.apache.camel.model.RouteType;
-import org.apache.camel.model.ToType;
+import org.apache.camel.model.*;
 import org.apache.camel.model.language.ExpressionType;
+import org.apache.camel.util.CollectionStringBuffer;
 import org.apache.camel.util.ObjectHelper;
 import static org.apache.camel.util.ObjectHelper.isNullOrBlank;
 import org.apache.commons.logging.Log;
@@ -45,6 +42,7 @@
 public class RouteDotGenerator {
     private static final transient Log LOG = LogFactory.getLog(RouteDotGenerator.class);
     private String file = "CamelRoutes.dot";
+    private String imagePrefix = "http://www.enterpriseintegrationpatterns.com/img/";
     private Map<Object, String> idMap = new HashMap<Object, String>();
 
     public String getFile() {
@@ -106,20 +104,12 @@
         writer.println("];");
         writer.println();
 
+        // TODO we should add a transactional client / event driven consumer / polling client
+
         List<ProcessorType> outputs = route.getOutputs();
         for (ProcessorType output : outputs) {
             printNode(writer, fromID, output);
         }
-
-/*
-        writer.print(r);
-        writer.print(" -> ");
-        if (r instanceof EventDrivenConsumerRoute) {
-            EventDrivenConsumerRoute consumerRoute = (EventDrivenConsumerRoute)r;
-            Processor p = consumerRoute.getProcessor();
-            writer.println(p);
-        }
-*/
     }
 
     protected String printNode(PrintWriter writer, String fromID, ProcessorType node) {
@@ -170,12 +160,7 @@
     }
 
     protected void configureNodeData(ProcessorType node, NodeData nodeData) {
-        if (node instanceof FilterType) {
-            FilterType filterType = (FilterType) node;
-            nodeData.image = "http://www.enterpriseintegrationpatterns.com/img/MessageFilterIcon.gif";
-            nodeData.label = getLabel(filterType.getExpression());
-        }
-        else if (node instanceof ToType) {
+        if (node instanceof ToType) {
             ToType toType = (ToType) node;
             String ref = toType.getRef();
             if (isNullOrBlank(ref)) {
@@ -183,6 +168,49 @@
             }
             nodeData.label = ref;
         }
+        else if (node instanceof FilterType) {
+            FilterType filterType = (FilterType) node;
+            nodeData.image = imagePrefix + "MessageFilterIcon.gif";
+            nodeData.label = getLabel(filterType.getExpression());
+        }
+        else if (node instanceof ChoiceType) {
+            ChoiceType choiceType = (ChoiceType) node;
+            nodeData.image = imagePrefix + "ContentBasedRouterIcon.gif";
+            CollectionStringBuffer buffer = new CollectionStringBuffer();
+            List<WhenType> list = choiceType.getWhenClauses();
+            for (WhenType whenType : list) {
+                buffer.append(getLabel(whenType.getExpression()));
+            }
+            nodeData.label = buffer.toString();
+        }
+        else if (node instanceof RecipientListType) {
+            RecipientListType recipientListType = (RecipientListType) node;
+            nodeData.image = imagePrefix + "RecipientListIcon.gif";
+            nodeData.label = getLabel(recipientListType.getExpression());
+        }
+        else if (node instanceof SplitterType) {
+            SplitterType splitterType = (SplitterType) node;
+            nodeData.image = imagePrefix + "SplitterIcon.gif";
+            nodeData.label = getLabel(splitterType.getExpression());
+        }
+        else if (node instanceof AggregatorType) {
+            AggregatorType aggregatorType = (AggregatorType) node;
+            nodeData.image = imagePrefix + "AggregatorIcon.gif";
+            nodeData.label = getLabel(aggregatorType.getExpression());
+        }
+        else if (node instanceof ResequencerType) {
+            ResequencerType resequencerType = (ResequencerType) node;
+            nodeData.image = imagePrefix + "ResequencerIcon.gif";
+            nodeData.label = getLabel(resequencerType.getExpressions());
+        }
+    }
+
+    protected String getLabel(List<ExpressionType> expressions) {
+        CollectionStringBuffer buffer = new CollectionStringBuffer();
+        for (ExpressionType expression : expressions) {
+            buffer.append(getLabel(expression));
+        }
+        return buffer.toString();
     }
 
     protected String getLabel(ExpressionType expression) {
@@ -199,10 +227,6 @@
             }
         }
         return "";
-    }
-
-    protected String getImageUrl(ProcessorType node) {
-        return null;
     }
 
     protected String getID(Object node) {