Coverage Report - org.mule.message.BaseMessage
 
Classes in this File Line Coverage Branch Coverage Complexity
BaseMessage
0%
0/16
N/A
1
 
 1  
 /*
 2  
  * $Id: BaseMessage.java 10489 2008-01-23 17:53:38Z dfeist $
 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.message;
 12  
 
 13  
 import java.io.Serializable;
 14  
 import java.util.HashMap;
 15  
 import java.util.Map;
 16  
 
 17  
 /**
 18  
  * <code>BaseMessage</code> A default message implementation used for messages sent
 19  
  * over the wire. client messages should NOT implement MuleMessage.
 20  
  */
 21  
 public class BaseMessage implements Serializable
 22  
 {
 23  
     /**
 24  
      * Serial version
 25  
      */
 26  
     private static final long serialVersionUID = -6105691921086093748L;
 27  
 
 28  
     protected Object message;
 29  
 
 30  
     protected Map context;
 31  
 
 32  
     public BaseMessage(Object message)
 33  0
     {
 34  0
         this.message = message;
 35  0
         context = new HashMap();
 36  0
     }
 37  
 
 38  
     /**
 39  
      * Converts the message implementation into a String representation
 40  
      * 
 41  
      * @return String representation of the message payload
 42  
      * @throws Exception Implementation may throw an endpoint specific exception
 43  
      */
 44  
     public String getPayloadAsString(String encoding) throws Exception
 45  
     {
 46  0
         return message.toString();
 47  
     }
 48  
 
 49  
     /**
 50  
      * Converts the message implementation into a String representation
 51  
      * 
 52  
      * @return String representation of the message
 53  
      * @throws Exception Implemetation may throw an endpoint specific exception
 54  
      */
 55  
     public byte[] getPayloadAsBytes() throws Exception
 56  
     {
 57  0
         return getPayloadAsString(message.toString()).getBytes();
 58  
     }
 59  
 
 60  
     /**
 61  
      * @return the current message
 62  
      */
 63  
     public Object getPayload()
 64  
     {
 65  0
         return message;
 66  
     }
 67  
 
 68  
     /**
 69  
      * Adds a map of properties to associated with this message
 70  
      * 
 71  
      * @param properties the properties add to this message
 72  
      */
 73  
     public void addProperties(Map properties)
 74  
     {
 75  0
         context.putAll(properties);
 76  0
     }
 77  
 
 78  
     /**
 79  
      * Removes all properties on this message
 80  
      */
 81  
     public void clearProperties()
 82  
     {
 83  0
         context.clear();
 84  0
     }
 85  
 
 86  
     /**
 87  
      * Returns a map of all properties on this message
 88  
      * 
 89  
      * @return a map of all properties on this message
 90  
      */
 91  
     public Map getProperties()
 92  
     {
 93  0
         return context;
 94  
     }
 95  
 
 96  
     public void setProperty(Object key, Object value)
 97  
     {
 98  0
         context.put(key, value);
 99  0
     }
 100  
 
 101  
     public Object getProperty(Object key)
 102  
     {
 103  0
         return context.get(key);
 104  
     }
 105  
 
 106  
     public String toString()
 107  
     {
 108  0
         return "BaseMessage{" + "message=" + message + ", context=" + context + "}";
 109  
     }
 110  
 }