1 24 package org.objectweb.joram.client.jms; 25 26 import org.objectweb.joram.shared.excepts.*; 27 28 import java.io.*; 29 30 import javax.jms.JMSException ; 31 import javax.jms.MessageFormatException ; 32 import javax.jms.MessageNotWriteableException ; 33 34 37 public final class ObjectMessage extends Message implements javax.jms.ObjectMessage { 38 41 ObjectMessage() { 42 super(); 43 momMsg.type = momMsg.OBJECT; 44 } 45 46 53 ObjectMessage(Session session, 54 org.objectweb.joram.shared.messages.Message momMsg) { 55 super(session, momMsg); 56 } 57 58 65 public void setObject(Serializable obj) throws JMSException { 66 if (RObody) 67 throw new MessageNotWriteableException ("Can't set an object as the" 68 + " message body is read-only."); 69 70 try { 71 clearBody(); 72 momMsg.setObject(obj); 73 } catch (Exception exc) { 74 throw new MessageFormatException ("Object serialization failed: " + exc); 75 } 76 } 77 78 84 public Serializable getObject() throws MessageFormatException { 85 if (momMsg.body == null) return null; 86 87 try { 88 return momMsg.getObject(); 89 } catch (ClassNotFoundException cnfexc) { 90 ByteArrayInputStream bais = null; 91 ObjectInputStream ois = null; 92 93 try { 94 class Specialized_OIS extends ObjectInputStream { 97 Specialized_OIS(InputStream is) throws IOException { 98 super(is); 99 } 100 101 protected Class resolveClass(ObjectStreamClass osc) 102 throws IOException, ClassNotFoundException { 103 String n = osc.getName(); 104 return Class.forName(n, false, 105 Thread.currentThread().getContextClassLoader()); 106 } 107 } 108 109 bais = new ByteArrayInputStream(momMsg.body); 110 ois = new Specialized_OIS(bais); 111 return (Serializable) ois.readObject(); 112 } catch (Exception exc) { 113 MessageFormatException jE = 114 new MessageFormatException ("Error while deserializing the wrapped object: " + exc); 115 throw jE; 116 } finally { 117 try { 118 ois.close(); 119 } catch (Exception e) {} 120 try { 121 bais.close(); 122 } catch (Exception e) {} 123 } 124 } catch (Exception exc) { 125 MessageFormatException jE = 126 new MessageFormatException ("Error while deserializing the wrapped object: " + exc); 127 throw jE; 128 } 129 } 130 } 131 | Popular Tags |