1 7 package org.jboss.remoting.marshal.serializable; 8 9 import java.io.IOException ; 10 import java.io.InputStream ; 11 import java.io.ObjectInputStream ; 12 import java.util.Map ; 13 import org.jboss.remoting.loading.ObjectInputStreamWithClassLoader; 14 import org.jboss.remoting.marshal.UnMarshaller; 15 16 21 public class SerializableUnMarshaller implements UnMarshaller 22 { 23 static final long serialVersionUID = -1554017376768780738L; 24 25 public final static String DATATYPE = "serializable"; 26 27 protected ClassLoader customClassLoader = null; 28 29 45 public Object read(InputStream inputStream, Map metadata) throws IOException , ClassNotFoundException 46 { 47 ObjectInputStream objInputStream = null; 48 Object obj = null; 49 if(inputStream instanceof ObjectInputStreamWithClassLoader) 50 { 51 if(((ObjectInputStreamWithClassLoader) inputStream).getClassLoader() == null) 52 { 53 ((ObjectInputStreamWithClassLoader) inputStream).setClassLoader(customClassLoader); 54 } 55 objInputStream = (ObjectInputStream ) inputStream; 56 } 57 else if(inputStream instanceof ObjectInputStream ) 58 { 59 objInputStream = (ObjectInputStream ) inputStream; 60 } 61 else 62 { 63 if(customClassLoader != null) 64 { 65 objInputStream = new ObjectInputStreamWithClassLoader(inputStream, customClassLoader); 66 } 67 else 68 { 69 objInputStream = new ObjectInputStream (inputStream); 70 } 71 } 72 73 obj = objInputStream.readObject(); 74 75 try 76 { 77 objInputStream.readObject(); } 79 catch(Exception e) 80 { 81 85 } 86 return obj; 87 } 88 89 95 public void setClassLoader(ClassLoader classloader) 96 { 97 this.customClassLoader = classloader; 98 } 99 100 public UnMarshaller cloneUnMarshaller() 101 throws CloneNotSupportedException 102 { 103 SerializableUnMarshaller unmarshaller = new SerializableUnMarshaller(); 104 unmarshaller.setClassLoader(this.customClassLoader); 105 return unmarshaller; 106 } 107 108 } | Popular Tags |