KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > oracle > jms > OracleJmsMessageAdapter


1 /*
2  * $Id: OracleJmsMessageAdapter.java 3798 2006-11-04 04:07:14Z aperepel $
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.oracle.jms;
12
13 import oracle.jms.AdtMessage;
14 import oracle.xdb.XMLType;
15
16 import org.mule.providers.jms.JmsMessageAdapter;
17 import org.mule.umo.MessagingException;
18
19 /**
20  * If the message payload is XML, returns the XML as a string. If the message payload
21  * is an ADT, simply returns {@code Object.toString()} in order to avoid a null
22  * pointer exception. Any other message is handled by the standard
23  * {@code JmsMessageAdapter}.
24  */

25 public class OracleJmsMessageAdapter extends JmsMessageAdapter
26 {
27
28     /**
29      * Serial version
30      */

31     private static final long serialVersionUID = -5304537031626649816L;
32
33     public OracleJmsMessageAdapter(Object JavaDoc message) throws MessagingException
34     {
35         super(message);
36     }
37
38     /**
39      * If the message payload is XML, returns the XML as an array of bytes. If the
40      * message payload is an ADT, simply returns {@code Object.toString().getBytes()}
41      * in order to avoid a null pointer exception. Any other message is handled by
42      * the standard {@code JmsMessageAdapter}
43      *
44      * @see JmsMessageAdapter#getPayloadAsBytes
45      */

46     public byte[] getPayloadAsBytes() throws Exception JavaDoc
47     {
48         Object JavaDoc jmsMessage = getPayload();
49         if (jmsMessage instanceof AdtMessage)
50         {
51             Object JavaDoc adtMessage = ((AdtMessage)jmsMessage).getAdtPayload();
52             if (adtMessage instanceof XMLType)
53             {
54                 return ((XMLType)adtMessage).getBytesValue();
55             }
56             else
57             {
58                 return adtMessage.toString().getBytes(getEncoding());
59             }
60         }
61         else
62         {
63             return super.getPayloadAsBytes();
64         }
65     }
66
67     /**
68      * Converts the message implementation into a String representation
69      *
70      * @param encoding The encoding to use when transforming the message (if
71      * necessary). The parameter is used when converting from a byte array
72      * @return String representation of the message payload
73      * @throws Exception Implementation may throw an endpoint specific exception
74      */

75     public String JavaDoc getPayloadAsString(String JavaDoc encoding) throws Exception JavaDoc
76     {
77         Object JavaDoc jmsMessage = getPayload();
78         if (jmsMessage instanceof AdtMessage)
79         {
80             Object JavaDoc adtMessage = ((AdtMessage)jmsMessage).getAdtPayload();
81             if (adtMessage instanceof XMLType)
82             {
83                 return ((XMLType)adtMessage).getStringVal();
84             }
85             else
86             {
87                 return adtMessage.toString();
88             }
89         }
90         else
91         {
92             return super.getPayloadAsString(encoding);
93         }
94     }
95
96 }
97
Popular Tags