View Javadoc

1   /*
2    * $Id: InboundFilterProcessor.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 org.jdom.Element;
21  
22  public class InboundFilterProcessor extends TagProcessor
23  {
24  
25      private GraphNode endpointNode;
26  
27      public InboundFilterProcessor(GraphEnvironment environment, GraphNode endpointNode)
28      {
29          super(environment);
30          this.endpointNode = endpointNode;
31      }
32  
33      public void process(Graph graph, Element currentElement, GraphNode parent)
34      {
35          processInboundFilter(graph, currentElement, endpointNode, parent);
36      }
37  
38      public void processInboundFilter(Graph graph, Element endpoint, GraphNode endpointNode, GraphNode parent)
39      {
40          Element filter = endpoint.getChild(MuleTag.ELEMENT_FILTER);
41          boolean conditional = false;
42  
43          if (filter == null)
44          {
45              filter = endpoint.getChild(MuleTag.ELEMENT_LEFT_FILTER);
46              conditional = filter != null;
47          }
48  
49          if (filter != null)
50          {
51  
52              GraphNode filterNode = graph.addNode();
53              filterNode.getInfo().setHeader(filter.getAttributeValue(MuleTag.ATTRIBUTE_CLASS_NAME));
54              filterNode.getInfo().setFillColor(ColorRegistry.COLOR_FILTER);
55              StringBuffer caption = new StringBuffer();
56              appendProperties(filter, caption);
57              filterNode.getInfo().setCaption(caption.toString());
58              // this is a hack to pick up and/or filter conditions
59              // really we need a nice recursive way of doing this
60              if (conditional)
61              {
62                  filter = endpoint.getChild(MuleTag.ELEMENT_RIGHT_FILTER);
63                  GraphNode filterNode2 = graph.addNode();
64                  filterNode2.getInfo().setHeader(filter.getAttributeValue(MuleTag.ATTRIBUTE_CLASS_NAME));
65                  filterNode2.getInfo().setFillColor(ColorRegistry.COLOR_FILTER);
66                  StringBuffer caption2 = new StringBuffer();
67                  appendProperties(filter, caption2);
68                  filterNode2.getInfo().setCaption(caption2.toString());
69                  addEdge(graph, endpointNode, filterNode2, "filters on", isTwoWay(endpoint));
70              }
71              processInboundFilter(graph, filter, filterNode, parent);
72  
73              addEdge(graph, endpointNode, filterNode, "filters on", isTwoWay(endpoint));
74          }
75          else
76          {
77              addEdge(graph, endpointNode, parent, "in", isTwoWay(endpoint));
78          }
79      }
80  
81  }