1 22 package org.jboss.mq.referenceable; 23 24 import java.io.ByteArrayInputStream ; 25 import java.io.ByteArrayOutputStream ; 26 import java.io.ObjectInputStream ; 27 import java.io.ObjectOutputStream ; 28 import java.rmi.MarshalledObject ; 29 30 import javax.naming.RefAddr ; 31 32 40 public class ObjectRefAddr extends RefAddr 41 { 42 43 44 private static final long serialVersionUID = 751863774931559945L; 45 46 private byte[] serialContent; 47 48 55 public ObjectRefAddr(String arg1, Object content) throws javax.naming.NamingException 56 { 57 super(arg1); 58 59 try 60 { 61 java.rmi.MarshalledObject mo = new MarshalledObject (content); 62 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 63 ObjectOutputStream oos = new ObjectOutputStream (baos); 64 oos.writeObject(mo); 65 serialContent = baos.toByteArray(); 66 } 67 catch (java.io.IOException e) 68 { 69 e.printStackTrace(); 70 throw new javax.naming.NamingException ("Could not create a reference: " + e.getMessage()); 71 } 72 } 73 74 79 public Object getContent() 80 { 81 return serialContent; 82 } 83 84 93 public static Object extractObjectRefFrom(javax.naming.Reference ref, String arg1) 94 throws javax.naming.NamingException 95 { 96 97 try 98 { 99 byte[] serialContent = (byte[]) ref.get(arg1).getContent(); 100 ByteArrayInputStream bais = new ByteArrayInputStream (serialContent); 101 ObjectInputStream ois = new ObjectInputStream (bais); 102 java.rmi.MarshalledObject mo = (java.rmi.MarshalledObject ) ois.readObject(); 103 return mo.get(); 104 } 105 catch (Exception e) 106 { 107 throw new javax.naming.NamingException ("Invalid reference. Error: " + e.getMessage()); 108 } 109 110 } 111 } 112 | Popular Tags |