KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > transport > ObjectSerializer


1 /**
2  * PETALS: PETALS Services Platform
3  * Copyright (C) 2006 EBM WebSourcing
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): EBM WebSourcing
21  * --------------------------------------------------------------------------
22  * $Id: ObjectSerializer.java,v 0.3 2005/07/22 10:24:27 alouis Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.petals.jbi.transport;
27
28 import javax.jbi.JBIException;
29 import javax.jms.JMSException JavaDoc;
30 import javax.jms.Message JavaDoc;
31 import javax.jms.ObjectMessage JavaDoc;
32 import javax.jms.Session JavaDoc;
33
34 import org.objectweb.petals.jbi.messaging.MessageExchangeImpl;
35
36 /**
37  * This class is used to transform a <code>MessageExchangeImpl</code> into an
38  * <code>jms.ObjectMessage</code>. Serialization mechanism is used; so the
39  * <code>MessageExchangeImpl</code> object has to be fully (de)serialized.
40  *
41  * @version $Rev: 477 $ $Date: 2006-05-29 17:18:07 +0200 (lun., 29 mai 2006) $
42  * @since Petals 1.0
43  * @author alouis
44  */

45 public class ObjectSerializer implements Serializer {
46
47     public Message JavaDoc jbi2jms(MessageExchangeImpl jbi, Session JavaDoc session)
48         throws TransportException {
49         ObjectMessage JavaDoc jms;
50         try {
51             jms = session.createObjectMessage(jbi);
52         } catch (JMSException JavaDoc e) {
53             if(e.getMessage().indexOf("org.xml.sax.SAXParseException")>0){
54                 if(e.getMessage().indexOf("Content is not allowed in prolog")>0){
55                     throw new TransportException("The Normalized Message is not a valid XML document.",e);
56                 }else if (e.getMessage().indexOf("Invalid byte")>0){
57                     throw new TransportException("The Normalized Message contains invalid characters.",e);
58                 }
59             }
60             throw new TransportException(e);
61         }
62         return jms;
63     }
64
65     public MessageExchangeImpl jms2jbi(Message JavaDoc jms) throws JBIException {
66         try {
67             return (MessageExchangeImpl) ((ObjectMessage JavaDoc) jms).getObject();
68         } catch (JMSException JavaDoc e) {
69             throw new JBIException(e);
70         }
71
72     }
73
74 }
75
Popular Tags