Coverage Report - org.mule.components.simple.StaticComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
StaticComponent
0%
0/27
0%
0/8
1.7
 
 1  
 /*
 2  
  * $Id: StaticComponent.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.components.simple;
 12  
 
 13  
 import org.mule.umo.UMOEventContext;
 14  
 import org.mule.umo.lifecycle.Callable;
 15  
 import org.mule.umo.lifecycle.Initialisable;
 16  
 import org.mule.umo.lifecycle.InitialisationException;
 17  
 import org.mule.util.IOUtils;
 18  
 
 19  
 import java.io.IOException;
 20  
 
 21  
 /**
 22  
  * A component that will return a static data object as a result. This is useful for
 23  
  * testing with expected results. The data returned can be read from a file or set as
 24  
  * a property on this component.
 25  
  */
 26  0
 public class StaticComponent implements Callable, Initialisable
 27  
 {
 28  
 
 29  
     private Object data;
 30  
     private String dataFile;
 31  
     private String prefix;
 32  
     private String postfix;
 33  
 
 34  
     public void initialise() throws InitialisationException
 35  
     {
 36  0
         if (dataFile != null)
 37  
         {
 38  
             try
 39  
             {
 40  0
                 data = IOUtils.getResourceAsString(dataFile, getClass());
 41  
             }
 42  0
             catch (IOException e)
 43  
             {
 44  0
                 throw new InitialisationException(e, this);
 45  0
             }
 46  
         }
 47  0
     }
 48  
 
 49  
     public Object getData()
 50  
     {
 51  0
         return data;
 52  
     }
 53  
 
 54  
     public void setData(Object data)
 55  
     {
 56  0
         this.data = data;
 57  0
     }
 58  
 
 59  
     public String getDataFile()
 60  
     {
 61  0
         return dataFile;
 62  
     }
 63  
 
 64  
     public void setDataFile(String dataFile)
 65  
     {
 66  0
         this.dataFile = dataFile;
 67  0
     }
 68  
 
 69  
     public String getPrefix()
 70  
     {
 71  0
         return prefix;
 72  
     }
 73  
 
 74  
     public void setPrefix(String prefix)
 75  
     {
 76  0
         this.prefix = prefix;
 77  0
     }
 78  
 
 79  
     public String getPostfix()
 80  
     {
 81  0
         return postfix;
 82  
     }
 83  
 
 84  
     public void setPostfix(String postfix)
 85  
     {
 86  0
         this.postfix = postfix;
 87  0
     }
 88  
 
 89  
     public Object onCall(UMOEventContext eventContext) throws Exception
 90  
     {
 91  0
         if (data != null)
 92  
         {
 93  0
             return data;
 94  
         }
 95  
 
 96  0
         String eventData = eventContext.getTransformedMessageAsString();
 97  
 
 98  0
         if (prefix != null)
 99  
         {
 100  0
             eventData = prefix + eventData;
 101  
         }
 102  
 
 103  0
         if (postfix != null)
 104  
         {
 105  0
             eventData += postfix;
 106  
         }
 107  
 
 108  0
         return eventData;
 109  
     }
 110  
 }