View Javadoc

1   /*
2    * $Id: MuleRequestMessage.java 19500 2010-09-09 17:29:17Z dzapata $
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.module.ibeans.spi;
11  
12  import org.mule.api.MuleMessage;
13  import org.mule.api.MuleRuntimeException;
14  import org.mule.api.transport.PropertyScope;
15  
16  import java.util.Set;
17  
18  import javax.activation.DataHandler;
19  
20  import org.ibeans.api.IBeanInvocationData;
21  import org.ibeans.api.Request;
22  
23  /**
24   * An implementation of an IBeans {@link org.ibeans.api.Request} that adapts to a {@link org.mule.api.MuleMessage}
25   */
26  public class MuleRequestMessage implements Request
27  {
28      private MuleMessage message;
29      private int timeout = 0;
30      private IBeanInvocationData data;
31  
32      public MuleRequestMessage(IBeanInvocationData data, MuleMessage message)
33      {
34          this.message = message;
35          this.data = data;
36      }
37  
38      public Object getPayload()
39      {
40          return message.getPayload();
41      }
42  
43      public void setPayload(Object payload)
44      {
45          message.setPayload(payload);
46      }
47  
48      public void addHeader(String name, Object value)
49      {
50          message.setOutboundProperty(name, value);
51      }
52  
53      public Object removeHeader(String name)
54      {
55          return message.removeProperty(name, PropertyScope.OUTBOUND);
56      }
57  
58      public Object getHeader(String name)
59      {
60          return message.getOutboundProperty(name);
61      }
62  
63      public Set<String> getHeaderNames()
64      {
65          return message.getOutboundPropertyNames();
66      }
67  
68      public void addAttachment(String name, DataHandler handler)
69      {
70          try
71          {
72              message.addOutboundAttachment(name, handler);
73          }
74          catch (Exception e)
75          {
76              throw new MuleRuntimeException(e);
77          }
78      }
79  
80      public DataHandler removeAttachment(String name)
81      {
82          DataHandler dh = message.getOutboundAttachment(name);
83          try
84          {
85              if(dh!=null)
86              message.removeOutboundAttachment(name);
87          }
88          catch (Exception e)
89          {
90              throw new MuleRuntimeException(e);
91          }
92          return dh;
93      }
94  
95      public DataHandler getAttachment(String name)
96      {
97          return message.getOutboundAttachment(name);
98      }
99  
100     public Set<String> getAttachmentNames()
101     {
102         return message.getOutboundAttachmentNames();
103     }
104 
105     public int getTimeout()
106     {
107         return timeout;
108     }
109 
110     public void setTimeout(int timeout)
111     {
112         this.timeout = timeout;
113     }
114 
115     public IBeanInvocationData getIBeanInvocationData()
116     {
117         return data;
118     }
119 
120     public MuleMessage getMessage()
121     {
122         return message;
123     }
124 }