Coverage Report - org.mule.tools.visualizer.processor.OutBoundRoutersProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
OutBoundRoutersProcessor
74%
39/53
39%
11/28
4.5
 
 1  
 /*
 2  
  * $Id: OutBoundRoutersProcessor.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.tools.visualizer.processor;
 12  
 
 13  
 import org.mule.tools.visualizer.config.ColorRegistry;
 14  
 import org.mule.tools.visualizer.config.GraphEnvironment;
 15  
 import org.mule.tools.visualizer.util.MuleTag;
 16  
 
 17  
 import com.oy.shared.lm.graph.Graph;
 18  
 import com.oy.shared.lm.graph.GraphNode;
 19  
 
 20  
 import java.util.Iterator;
 21  
 import java.util.List;
 22  
 
 23  
 import org.jdom.Element;
 24  
 
 25  
 public class OutBoundRoutersProcessor extends TagProcessor
 26  
 {
 27  
 
 28  
     public OutBoundRoutersProcessor(GraphEnvironment environment)
 29  
     {
 30  4
         super(environment);
 31  4
     }
 32  
 
 33  
     public void process(Graph graph, Element currentElement, GraphNode parent)
 34  
     {
 35  6
         Element outboundRouter = currentElement.getChild(MuleTag.ELEMENT_OUTBOUND_ROUTER);
 36  
 
 37  6
         if (outboundRouter != null)
 38  
         {
 39  6
             String componentName = parent.getInfo().getHeader();
 40  6
             List routers = outboundRouter.getChildren(MuleTag.ELEMENT_ROUTER);
 41  6
             ExceptionStrategyProcessor processor = new ExceptionStrategyProcessor(getEnvironment());
 42  6
             processor.process(graph, outboundRouter, parent);
 43  
 
 44  6
             for (Iterator iterator = routers.iterator(); iterator.hasNext();)
 45  
             {
 46  6
                 Element router = (Element) iterator.next();
 47  
 
 48  6
                 if (router != null)
 49  
                 {
 50  6
                     GraphNode routerNode = graph.addNode();
 51  6
                     routerNode.getInfo().setHeader(router.getAttributeValue(MuleTag.ATTRIBUTE_CLASS_NAME));
 52  6
                     routerNode.getInfo().setFillColor(ColorRegistry.COLOR_ROUTER);
 53  
 
 54  6
                     addRelation(graph, parent, routerNode, "outbound router");
 55  
 
 56  
                     // TODO dead code ? but how to handle filter condition
 57  
                     /*
 58  
                      * Element endpointEl = router.getChild("endpoint"); if
 59  
                      * (endpointEl != null) { String endpointAdress = endpointEl
 60  
                      * .getAttributeValue("address"); GraphNode endpoint =
 61  
                      * endpointRegistry.getEndpoint( endpointAdress, componentName);
 62  
                      * if (endpoint == null) { endpoint = graph.addNode();
 63  
                      * endpoint.getInfo().setHeader(endpointAdress);
 64  
                      * endpointRegistry.addEndpoint(endpointAdress, endpoint); }
 65  
                      * outboundFilterProcessor.process(graph, router, endpoint,
 66  
                      * routerNode); }else {
 67  
                      */
 68  
 
 69  6
                     OutBoundRouterEndpointsHandler processor2 = new OutBoundRouterEndpointsHandler(
 70  
                         getEnvironment(), componentName);
 71  6
                     processor2.process(graph, router, routerNode);
 72  
 
 73  6
                     processReplyTOasElement(graph, router, routerNode, componentName);
 74  6
                     processReplyTOasProperty(graph, router, routerNode, componentName);
 75  
 
 76  6
                     GraphNode[] virtual = getEnvironment().getEndpointRegistry().getVirtualEndpoint(
 77  
                         componentName + "." + router.getAttributeValue(MuleTag.ATTRIBUTE_CLASS_NAME));
 78  6
                     if (virtual.length > 0)
 79  
                     {
 80  0
                         for (int i = 0; i < virtual.length; i++)
 81  
                         {
 82  0
                             addRelation(graph, routerNode, virtual[i], "out (dynamic)");
 83  
                         }
 84  
                     }
 85  
 
 86  
                 }
 87  6
             }
 88  
 
 89  6
             GraphNode[] virtual = getEnvironment().getEndpointRegistry().getVirtualEndpoint(componentName);
 90  6
             if (virtual.length > 0)
 91  
             {
 92  0
                 for (int i = 0; i < virtual.length; i++)
 93  
                 {
 94  0
                     addRelation(graph, parent, virtual[i], "out (dynamic)");
 95  
                 }
 96  
             }
 97  
 
 98  
         }
 99  6
     }
 100  
 
 101  
     private void processReplyTOasElement(Graph graph,
 102  
                                          Element router,
 103  
                                          GraphNode routerNode,
 104  
                                          String componentName)
 105  
     {
 106  6
         Element replyToElement = router.getChild(MuleTag.ELEMENT_REPLY_TO);
 107  6
         if (replyToElement != null)
 108  
         {
 109  2
             String replyTo = replyToElement.getAttributeValue(MuleTag.ATTRIBUTE_ADDRESS);
 110  2
             if (replyTo != null)
 111  
             {
 112  2
                 GraphNode out = getEnvironment().getEndpointRegistry().getEndpoint(replyTo, componentName);
 113  2
                 if (null == out)
 114  
                 {
 115  2
                     out = graph.addNode();
 116  2
                     out.getInfo().setCaption(replyTo);
 117  2
                     getEnvironment().getEndpointRegistry().addEndpoint(replyTo, out);
 118  
                 }
 119  2
                 addRelation(graph, routerNode, out, "sets");
 120  
             }
 121  
         }
 122  6
     }
 123  
 
 124  
     private void processReplyTOasProperty(Graph graph,
 125  
                                           Element router,
 126  
                                           GraphNode routerNode,
 127  
                                           String componentName)
 128  
     {
 129  6
         Element propertiesEl = router.getChild(MuleTag.ELEMENT_PROPERTIES);
 130  6
         if (propertiesEl != null)
 131  
         {
 132  0
             List properties = propertiesEl.getChildren(MuleTag.ELEMENT_PROPERTY);
 133  0
             for (Iterator iterator = properties.iterator(); iterator.hasNext();)
 134  
             {
 135  0
                 Element property = (Element) iterator.next();
 136  0
                 String propertyName = property.getAttributeValue(MuleTag.ATTRIBUTE_NAME);
 137  0
                 if ("replyTo".equals(propertyName))
 138  
                 {
 139  0
                     String replyTo = property.getAttributeValue(MuleTag.ATTRIBUTE_VALUE);
 140  0
                     if (replyTo != null)
 141  
                     {
 142  0
                         GraphNode out = getEnvironment().getEndpointRegistry().getEndpoint(replyTo, componentName);
 143  0
                         addRelation(graph, routerNode, out, "sets");
 144  
                     }
 145  
                 }
 146  0
             }
 147  
         }
 148  6
     }
 149  
 }