View Javadoc

1   /*
2    * $Id: OutBoundRouterEndpointsHandler.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.GraphEnvironment;
14  import org.mule.tools.visualizer.util.MuleTag;
15  
16  import com.oy.shared.lm.graph.Graph;
17  import com.oy.shared.lm.graph.GraphNode;
18  
19  import java.util.Iterator;
20  import java.util.List;
21  
22  import org.jdom.Element;
23  
24  public class OutBoundRouterEndpointsHandler extends TagProcessor
25  {
26  
27      private String componentName;
28  
29      public OutBoundRouterEndpointsHandler(GraphEnvironment environment, String componentName)
30      {
31          super(environment);
32          this.componentName = componentName;
33      }
34  
35      public void process(Graph graph, Element currentElement, GraphNode parent)
36      {
37          List epList = currentElement.getChildren(MuleTag.ELEMENT_ENDPOINT);
38          process(graph, epList, parent);
39  
40          epList = currentElement.getChildren(MuleTag.ELEMENT_GLOBAL_ENDPOINT);
41          process(graph, epList, parent);
42      }
43  
44      public void process(Graph graph, List epList, GraphNode parent)
45      {
46          int x = 1;
47          for (Iterator iterator = epList.iterator(); iterator.hasNext(); x++)
48          {
49              Element outEndpoint = (Element) iterator.next();
50  
51              String url = outEndpoint.getAttributeValue(MuleTag.ATTRIBUTE_ADDRESS);
52              if (url == null)
53              {
54                  url = outEndpoint.getAttributeValue(MuleTag.ATTRIBUTE_NAME);
55              }
56  
57              if (url != null)
58              {
59                  GraphNode out = getEnvironment().getEndpointRegistry().getEndpoint(url, componentName);
60                  if (out == null)
61                  {
62                      out = graph.addNode();
63                      StringBuffer caption = new StringBuffer();
64                      // caption.append(url).append("\n");
65                      appendProperties(outEndpoint, caption);
66                      appendDescription(outEndpoint, caption);
67                      out.getInfo().setCaption(caption.toString());
68                      getEnvironment().getEndpointRegistry().addEndpoint(url, out);
69                      processOutboundFilter(graph, outEndpoint, out, parent);
70                  }
71                  else
72                  {
73                      String caption = "out";
74                      if (epList.size() > 1)
75                      {
76                          caption += " (" + x + " of " + epList.size() + ")";
77                      }
78                      addEdge(graph, parent, out, caption, isTwoWay(outEndpoint));
79  
80                  }
81              }
82  
83              GraphNode[] virtual = getEnvironment().getEndpointRegistry().getVirtualEndpoint(componentName);
84              if (virtual.length > 0)
85              {
86                  for (int i = 0; i < virtual.length; i++)
87                  {
88                      addEdge(graph, parent, virtual[i], "out (dynamic)", isTwoWay(outEndpoint));
89                  }
90              }
91          }
92      }
93  
94      private void processOutboundFilter(Graph graph, Element outEndpoint, GraphNode out, GraphNode routerNode)
95      {
96  
97          OutboundFilterProcessor processor = new OutboundFilterProcessor(getEnvironment(), out);
98          processor.process(graph, outEndpoint, routerNode);
99      }
100 
101 }