KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > jbi > JbiMessageAdapter


1 /*
2  * $Id: JbiMessageAdapter.java 3982 2006-11-22 14:28:01Z lajos $
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 MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.jbi;
12
13 import org.mule.providers.AbstractMessageAdapter;
14 import org.mule.umo.MessagingException;
15 import org.mule.umo.provider.MessageTypeNotSupportedException;
16
17 import javax.activation.DataHandler JavaDoc;
18 import javax.jbi.messaging.NormalizedMessage;
19
20 import java.util.Iterator JavaDoc;
21 import java.util.Set JavaDoc;
22
23 /**
24  * <code>JbiMessageAdapter</code> translates a JBI NormalizedMessage to a
25  * UMOMessage
26  *
27  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
28  * @version $Revision: 3982 $
29  */

30
31 public class JbiMessageAdapter extends AbstractMessageAdapter
32 {
33     /**
34      * Serial version
35      */

36     private static final long serialVersionUID = 642776588124612798L;
37
38     private final NormalizedMessage message;
39
40     public JbiMessageAdapter(Object JavaDoc message) throws MessagingException
41     {
42         if (message instanceof NormalizedMessage)
43         {
44             this.message = (NormalizedMessage)message;
45             for (Iterator JavaDoc iterator = this.message.getPropertyNames().iterator(); iterator.hasNext();)
46             {
47                 String JavaDoc key = (String JavaDoc)iterator.next();
48                 Object JavaDoc value = this.message.getProperty(key);
49                 if (value != null)
50                 {
51                     setProperty(key, value);
52                 }
53             }
54         }
55         else
56         {
57             throw new MessageTypeNotSupportedException(message, getClass());
58         }
59     }
60
61     public void setProperty(Object JavaDoc key, Object JavaDoc value)
62     {
63         message.setProperty(key.toString(), value);
64     }
65
66     /**
67      * Converts the message implementation into a String representation
68      *
69      * @param encoding The encoding to use when transforming the message (if
70      * necessary). The parameter is used when converting from a byte array
71      * @return String representation of the message payload
72      * @throws Exception Implementation may throw an endpoint specific exception
73      */

74     public String JavaDoc getPayloadAsString(String JavaDoc encoding) throws Exception JavaDoc
75     {
76         throw new UnsupportedOperationException JavaDoc("getPayloadAsString");
77     }
78
79     /**
80      * Converts the message implementation into a String representation
81      *
82      * @return String representation of the message
83      * @throws Exception Implemetation may throw an endpoint specific exception
84      */

85     public byte[] getPayloadAsBytes() throws Exception JavaDoc
86     {
87         throw new UnsupportedOperationException JavaDoc("getPayloadAsBytes");
88     }
89
90     public Object JavaDoc getPayload()
91     {
92         return message;
93     }
94
95     public Object JavaDoc getProperty(Object JavaDoc key)
96     {
97         return message.getProperty(key.toString());
98     }
99
100     public void addAttachment(String JavaDoc name, DataHandler JavaDoc dataHandler) throws Exception JavaDoc
101     {
102         message.addAttachment(name, dataHandler);
103     }
104
105     public void removeAttachment(String JavaDoc name) throws Exception JavaDoc
106     {
107         message.removeAttachment(name);
108     }
109
110     public DataHandler JavaDoc getAttachment(String JavaDoc name)
111     {
112         return message.getAttachment(name);
113     }
114
115     public Set JavaDoc getAttachmentNames()
116     {
117         return message.getAttachmentNames();
118     }
119
120 }
121
Popular Tags