Coverage Report - org.apache.camel.view.RouteDotGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
RouteDotGenerator
0% 
0% 
0
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.camel.view;
 19  
 
 20  
 import org.apache.camel.CamelContext;
 21  
 import org.apache.camel.Endpoint;
 22  
 import org.apache.camel.Processor;
 23  
 import org.apache.camel.Route;
 24  
 import org.apache.camel.impl.EventDrivenConsumerRoute;
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 
 28  
 import java.io.FileWriter;
 29  
 import java.io.IOException;
 30  
 import java.io.PrintWriter;
 31  
 import java.util.List;
 32  
 
 33  
 /**
 34  
  * A <a href="http://www.graphviz.org/">DOT</a> file creator plugin which
 35  
  * creates a DOT file showing the current routes
 36  
  *
 37  
  * @version $Revision: 523881 $
 38  
  */
 39  0
 public class RouteDotGenerator {
 40  0
     private static final transient Log log = LogFactory.getLog(RouteDotGenerator.class);
 41  0
     private String file = "CamelRoutes.dot";
 42  
 
 43  
     public String getFile() {
 44  0
         return file;
 45  
     }
 46  
 
 47  
     /**
 48  
      * Sets the destination file name to create the destination diagram
 49  
      */
 50  
     public void setFile(String file) {
 51  0
         this.file = file;
 52  0
     }
 53  
 
 54  
     public void drawRoutes(CamelContext context) throws IOException {
 55  0
         PrintWriter writer = new PrintWriter(new FileWriter(file));
 56  0
         generateFile(writer, context);
 57  0
     }
 58  
 
 59  
     protected void generateFile(PrintWriter writer, CamelContext context) {
 60  0
         writer.println("digraph \"Camel Routes\" {");
 61  0
         writer.println();
 62  0
         writer.println("label=\"Camel Container: " + context + "\"];");
 63  0
         writer.println();
 64  0
         writer.println("node [style = \"rounded,filled\", fillcolor = yellow, fontname=\"Helvetica-Oblique\"];");
 65  0
         writer.println();
 66  0
         printRoutes(writer, context.getRoutes());
 67  0
     }
 68  
 
 69  
     protected void printRoutes(PrintWriter writer, List<Route> routes) {
 70  0
         for (Route r : routes) {
 71  0
             Endpoint end = r.getEndpoint();
 72  0
             writer.print(end.getEndpointUri());
 73  0
             writer.print(" -> ");
 74  0
             writer.print(r);
 75  0
             writer.print(" -> ");
 76  0
             if (r instanceof EventDrivenConsumerRoute) {
 77  0
                 EventDrivenConsumerRoute consumerRoute = (EventDrivenConsumerRoute) r;
 78  0
                 Processor p = consumerRoute.getProcessor();
 79  0
                 writer.println(p);
 80  
             }
 81  0
         }
 82  0
     }
 83  
 }