Coverage Report - org.mule.message.DefaultMuleMessageDTO
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultMuleMessageDTO
0%
0/35
0%
0/10
0
 
 1  
 /*
 2  
  * $Id: DefaultMuleMessageDTO.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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  
 package org.mule.message;
 11  
 
 12  
 import org.mule.DefaultMuleMessage;
 13  
 import org.mule.api.MuleContext;
 14  
 import org.mule.api.MuleMessage;
 15  
 import org.mule.api.transport.PropertyScope;
 16  
 
 17  
 import java.io.Serializable;
 18  
 
 19  
 /**
 20  
  * A data transfer object representation of a {@link org.mule.api.MuleMessage}. THis object is used when ecoding Mule messages
 21  
  * over the wire using XML, JSON or other serialization.
 22  
  */
 23  
 public class DefaultMuleMessageDTO extends BaseMessageDTO
 24  
 {
 25  
     private String replyTo;
 26  
 
 27  
     public DefaultMuleMessageDTO()
 28  
     {
 29  0
         super();
 30  0
     }
 31  
 
 32  
     public DefaultMuleMessageDTO(Serializable message)
 33  
     {
 34  0
         super(message);
 35  0
     }
 36  
 
 37  
     public DefaultMuleMessageDTO(MuleMessage message)
 38  
     {
 39  0
         super(message.getPayload());
 40  0
         encodePropertiesForScope(PropertyScope.INBOUND, message);
 41  0
         encodePropertiesForScope(PropertyScope.OUTBOUND, message);
 42  0
         encodePropertiesForScope(PropertyScope.INVOCATION, message);
 43  0
         encodePropertiesForScope(PropertyScope.SESSION, message);
 44  0
         if(message.getReplyTo()!=null)
 45  
         {
 46  0
             setReplyTo(message.getReplyTo().toString());
 47  
         }
 48  0
     }
 49  
 
 50  
     protected void encodePropertiesForScope(PropertyScope scope, MuleMessage message)
 51  
     {
 52  0
         for (String key : message.getPropertyNames(scope))
 53  
         {
 54  0
             setProperty(String.format("%s#%s", scope.getScopeName(), key), message.getProperty(key, scope));
 55  
         }
 56  0
     }
 57  
 
 58  
     public String getReplyTo()
 59  
     {
 60  0
         return replyTo;
 61  
     }
 62  
 
 63  
     public void setReplyTo(String replyTo)
 64  
     {
 65  0
         this.replyTo = replyTo;
 66  0
     }
 67  
 
 68  
     public Object getData()
 69  
     {
 70  0
         return getPayload();
 71  
     }
 72  
 
 73  
     public void setData(Object data)
 74  
     {
 75  0
         this.setPayload(data);
 76  0
     }
 77  
 
 78  
     public void addPropertiesTo(MuleMessage message)
 79  
     {
 80  0
         for (String s : properties.keySet())
 81  
         {
 82  0
             int i = s.indexOf("#");
 83  0
             String prefix = s.substring(0, i);
 84  0
             if (prefix.equals(PropertyScope.OUTBOUND.getScopeName()))
 85  
             {
 86  0
                 message.setOutboundProperty(s.substring(i + 1), getProperty(s));
 87  
             }
 88  0
             else if (prefix.equals(PropertyScope.SESSION.getScopeName()))
 89  
             {
 90  0
                 message.setProperty(s.substring(i + 1), getProperty(s), PropertyScope.SESSION);
 91  
             }
 92  
             else
 93  
             {
 94  0
                 message.setInvocationProperty(s.substring(i + 1), getProperty(s));
 95  
             }
 96  0
         }
 97  0
         message.setReplyTo(getReplyTo());
 98  0
     }
 99  
     
 100  
     public MuleMessage toMuleMessage(MuleContext context)
 101  
     {
 102  0
         MuleMessage message = new DefaultMuleMessage(getPayload(), context);
 103  0
         addPropertiesTo(message);
 104  0
         return message;
 105  
     }
 106  
 }