Coverage Report - org.mule.tools.visualizer.components.MuleParser
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleParser
90%
37/41
83%
5/6
1.6
 
 1  
 /*
 2  
  * $Id: MuleParser.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.components;
 12  
 
 13  
 import org.mule.tools.visualizer.config.GraphEnvironment;
 14  
 import org.mule.tools.visualizer.postprocessors.ExternalSystemPostProcessor;
 15  
 import org.mule.tools.visualizer.postprocessors.NodeHiderPostProcessor;
 16  
 import org.mule.tools.visualizer.postprocessors.UrlAssignerPostProcessor;
 17  
 import org.mule.tools.visualizer.processor.AgentProcessor;
 18  
 import org.mule.tools.visualizer.processor.ConnectorProcessor;
 19  
 import org.mule.tools.visualizer.processor.EndpointIdentifiersProcessor;
 20  
 import org.mule.tools.visualizer.processor.EndpointsProcessor;
 21  
 import org.mule.tools.visualizer.processor.MuleConfigProcessor;
 22  
 import org.mule.tools.visualizer.processor.MuleModelProcessor;
 23  
 import org.mule.tools.visualizer.processor.TagProcessor;
 24  
 import org.mule.tools.visualizer.processor.TransformerProcessor;
 25  
 
 26  
 import com.oy.shared.lm.graph.Graph;
 27  
 
 28  
 import java.io.File;
 29  
 import java.io.IOException;
 30  
 import java.io.InputStream;
 31  
 import java.util.ArrayList;
 32  
 import java.util.Iterator;
 33  
 import java.util.List;
 34  
 
 35  
 import org.jdom.Document;
 36  
 import org.jdom.Element;
 37  
 import org.jdom.JDOMException;
 38  
 import org.jdom.input.SAXBuilder;
 39  
 
 40  
 public class MuleParser
 41  
 {
 42  
 
 43  
     private final SAXBuilder builder;
 44  4
     private final List processors = new ArrayList();
 45  4
     private final List postProcessors = new ArrayList();
 46  
     private GraphEnvironment env;
 47  
 
 48  
     public MuleParser(GraphEnvironment env, SAXBuilder builder)
 49  4
     {
 50  4
         this.env = env;
 51  4
         this.builder = builder;
 52  4
         processors.add(new MuleConfigProcessor(env));
 53  4
         processors.add(new EndpointIdentifiersProcessor(env));
 54  4
         processors.add(new EndpointsProcessor(env));
 55  4
         processors.add(new ConnectorProcessor(env));
 56  4
         processors.add(new MuleModelProcessor(env));
 57  4
         processors.add(new TransformerProcessor(env));
 58  4
         processors.add(new AgentProcessor(env));
 59  
 
 60  4
         postProcessors.add(new UrlAssignerPostProcessor());
 61  4
         postProcessors.add(new ExternalSystemPostProcessor());
 62  
         // Always set this to last as deleting nodes earlier seems to have adverse
 63  
         // affects
 64  
         // when adding nodes
 65  4
         postProcessors.add(new NodeHiderPostProcessor());
 66  
 
 67  4
     }
 68  
 
 69  
     public void parseMuleConfig(InputStream in, Graph graph) throws JDOMException, IOException
 70  
     {
 71  0
         Document doc = builder.build(in);
 72  0
         parseMuleConfig(doc, graph);
 73  0
     }
 74  
 
 75  
     public void parseMuleConfig(File myFile, Graph graph) throws JDOMException, IOException
 76  
     {
 77  4
         Document doc = builder.build(myFile);
 78  4
         parseMuleConfig(doc, graph);
 79  4
     }
 80  
 
 81  
     public void parseMuleConfig(Document doc, Graph graph) throws JDOMException, IOException
 82  
     {
 83  4
         Element root = doc.getRootElement();
 84  4
         String caption = root.getAttribute("id").getValue();
 85  4
         if (caption != null)
 86  
         {
 87  4
             caption = caption.replaceAll("_", " ");
 88  
         }
 89  
         else
 90  
         {
 91  0
             caption = "Mule Configuration";
 92  
         }
 93  
 
 94  4
         StringBuffer captionBuffer = new StringBuffer();
 95  4
         captionBuffer.append(caption);
 96  4
         TagProcessor.appendDescription(root, captionBuffer);
 97  4
         graph.getInfo().setCaption(captionBuffer.toString());
 98  
 
 99  4
         for (Iterator iterator = processors.iterator(); iterator.hasNext();)
 100  
         {
 101  28
             TagProcessor tagProcessor = (TagProcessor) iterator.next();
 102  28
             tagProcessor.process(graph, root, null);
 103  28
         }
 104  4
     }
 105  
 
 106  
     public void finalise(Graph graph)
 107  
     {
 108  4
         for (Iterator iter = postProcessors.iterator(); iter.hasNext();)
 109  
         {
 110  12
             PostProcessor postProcessor = (PostProcessor) iter.next();
 111  12
             postProcessor.postProcess(graph, env);
 112  12
         }
 113  4
     }
 114  
 
 115  
 }