KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > oracle > jms > transformers > StringToXMLMessage


1 /*
2  * $Id: StringToXMLMessage.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.transformers;
12
13 import javax.jms.Session JavaDoc;
14
15 import oracle.jms.AdtMessage;
16 import oracle.xdb.XMLType;
17
18 import org.mule.config.i18n.Message;
19 import org.mule.providers.oracle.jms.OracleJmsConnector;
20 import org.mule.transformers.AbstractEventAwareTransformer;
21 import org.mule.umo.UMOEventContext;
22 import org.mule.umo.transformer.TransformerException;
23
24 /**
25  * Transformer for use with the Oracle Jms Connector. Expects a string containing
26  * properly-formed XML. Creates a JMS message whose payload is Oracle's native XML
27  * data type.
28  *
29  * @author <a HREF="mailto:carlson@hotpop.com">Travis Carlson</a>
30  * @see XMLMessageToString
31  * @see OracleJmsConnector
32  * @see <a HREF="http://otn.oracle.com/pls/db102/">XML DB Developer's Guide</a>
33  */

34 public class StringToXMLMessage extends AbstractEventAwareTransformer
35 {
36
37     private static final long serialVersionUID = 8476470235704172556L;
38
39     public StringToXMLMessage()
40     {
41         super();
42         registerSourceType(String JavaDoc.class);
43         registerSourceType(byte[].class);
44         setReturnClass(AdtMessage.class);
45     }
46
47     /**
48      * @param src - String or byte[] containing properly-formed XML.
49      * @return JMS message whose payload is Oracle's native XML data type
50      */

51     public Object JavaDoc transform(Object JavaDoc src, String JavaDoc encoding, UMOEventContext context) throws TransformerException
52     {
53         Session JavaDoc session = null;
54         AdtMessage message = null;
55         XMLType xmltype = null;
56
57         throw new TransformerException(
58             Message.createStaticMessage("This transformer is currently unsupported until issue MULE-1079 is resolved."),
59             this);
60         /*
61          * try { // Get the Oracle AQ session for this event. // TODO This property
62          * is no longer set by JmsMessageDispatcher, see MULE-1079 session =
63          * (Session)
64          * context.getMessage().getProperty(MuleProperties.MULE_JMS_SESSION); if
65          * (session == null) { throw new
66          * TransformerException(Message.createStaticMessage("The current JMS session
67          * should have been stored as a property for this event."), this); } if
68          * ((session instanceof AQjmsSession) == false) { throw new
69          * TransformerException(Message.createStaticMessage("Endpoint must be an
70          * OracleAQ session."), this); } // Prepare the XML string. String xml; if
71          * (src instanceof byte[]) { xml = new String((byte[]) src, encoding); } else
72          * if (src instanceof String) { xml = (String) src; } else throw new
73          * TransformerException(Message.createStaticMessage("Object to transform is
74          * not one of the supported types for this transformer."), this);
75          * logger.debug("Creating an Oracle XMLType based on the following XML:\n" +
76          * StringMessageUtils.truncate(xml, 200, false)); // Create a temporary CLOB
77          * and pass this to the XMLType.createXML() factory. // Note: if we pass the
78          * xml string directly to XMLType.createXML() as a // parameter, the
79          * character set is not preserved properly (probably a bug // in the Oracle
80          * library). CLOB clob = CLOB.createTemporary(((AQjmsSession)
81          * session).getDBConnection(), true, CLOB.DURATION_SESSION); try { Writer
82          * clobStream = clob.getCharacterOutputStream(); try { clobStream.write(xml); }
83          * finally { clobStream.close(); } xmltype =
84          * XMLType.createXML(((AQjmsSession) session).getDBConnection(), clob); //
85          * Create the JMS message. message = ((AQjmsSession)
86          * session).createAdtMessage(); message.setAdtPayload(xmltype); return
87          * message; } finally { // TODO Need to put this somewhere but apparently not
88          * here... //clob.freeTemporary(); } } catch (JMSException e) { throw new
89          * TransformerException(this, e); } catch (SQLException e) { throw new
90          * TransformerException(this, e); } catch (IOException e) { throw new
91          * TransformerException(this, e); }
92          */

93     }
94 }
95
Popular Tags