View Javadoc

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          super(environment);
31      }
32  
33      public void process(Graph graph, Element currentElement, GraphNode parent)
34      {
35          Element outboundRouter = currentElement.getChild(MuleTag.ELEMENT_OUTBOUND_ROUTER);
36  
37          if (outboundRouter != null)
38          {
39              String componentName = parent.getInfo().getHeader();
40              List routers = outboundRouter.getChildren(MuleTag.ELEMENT_ROUTER);
41              ExceptionStrategyProcessor processor = new ExceptionStrategyProcessor(getEnvironment());
42              processor.process(graph, outboundRouter, parent);
43  
44              for (Iterator iterator = routers.iterator(); iterator.hasNext();)
45              {
46                  Element router = (Element) iterator.next();
47  
48                  if (router != null)
49                  {
50                      GraphNode routerNode = graph.addNode();
51                      routerNode.getInfo().setHeader(router.getAttributeValue(MuleTag.ATTRIBUTE_CLASS_NAME));
52                      routerNode.getInfo().setFillColor(ColorRegistry.COLOR_ROUTER);
53  
54                      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                      OutBoundRouterEndpointsHandler processor2 = new OutBoundRouterEndpointsHandler(
70                          getEnvironment(), componentName);
71                      processor2.process(graph, router, routerNode);
72  
73                      processReplyTOasElement(graph, router, routerNode, componentName);
74                      processReplyTOasProperty(graph, router, routerNode, componentName);
75  
76                      GraphNode[] virtual = getEnvironment().getEndpointRegistry().getVirtualEndpoint(
77                          componentName + "." + router.getAttributeValue(MuleTag.ATTRIBUTE_CLASS_NAME));
78                      if (virtual.length > 0)
79                      {
80                          for (int i = 0; i < virtual.length; i++)
81                          {
82                              addRelation(graph, routerNode, virtual[i], "out (dynamic)");
83                          }
84                      }
85  
86                  }
87              }
88  
89              GraphNode[] virtual = getEnvironment().getEndpointRegistry().getVirtualEndpoint(componentName);
90              if (virtual.length > 0)
91              {
92                  for (int i = 0; i < virtual.length; i++)
93                  {
94                      addRelation(graph, parent, virtual[i], "out (dynamic)");
95                  }
96              }
97  
98          }
99      }
100 
101     private void processReplyTOasElement(Graph graph,
102                                          Element router,
103                                          GraphNode routerNode,
104                                          String componentName)
105     {
106         Element replyToElement = router.getChild(MuleTag.ELEMENT_REPLY_TO);
107         if (replyToElement != null)
108         {
109             String replyTo = replyToElement.getAttributeValue(MuleTag.ATTRIBUTE_ADDRESS);
110             if (replyTo != null)
111             {
112                 GraphNode out = getEnvironment().getEndpointRegistry().getEndpoint(replyTo, componentName);
113                 if (null == out)
114                 {
115                     out = graph.addNode();
116                     out.getInfo().setCaption(replyTo);
117                     getEnvironment().getEndpointRegistry().addEndpoint(replyTo, out);
118                 }
119                 addRelation(graph, routerNode, out, "sets");
120             }
121         }
122     }
123 
124     private void processReplyTOasProperty(Graph graph,
125                                           Element router,
126                                           GraphNode routerNode,
127                                           String componentName)
128     {
129         Element propertiesEl = router.getChild(MuleTag.ELEMENT_PROPERTIES);
130         if (propertiesEl != null)
131         {
132             List properties = propertiesEl.getChildren(MuleTag.ELEMENT_PROPERTY);
133             for (Iterator iterator = properties.iterator(); iterator.hasNext();)
134             {
135                 Element property = (Element) iterator.next();
136                 String propertyName = property.getAttributeValue(MuleTag.ATTRIBUTE_NAME);
137                 if ("replyTo".equals(propertyName))
138                 {
139                     String replyTo = property.getAttributeValue(MuleTag.ATTRIBUTE_VALUE);
140                     if (replyTo != null)
141                     {
142                         GraphNode out = getEnvironment().getEndpointRegistry().getEndpoint(replyTo, componentName);
143                         addRelation(graph, routerNode, out, "sets");
144                     }
145                 }
146             }
147         }
148     }
149 }