geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1144044 - /geronimo/tck/branches/3.0/geronimo-porting/src/main/java/org/apache/geronimo/test/tck/BeansImpl.java
Date Thu, 07 Jul 2011 21:17:25 GMT
Author: dblevins
Date: Thu Jul  7 21:17:25 2011
New Revision: 1144044

URL: http://svn.apache.org/viewvc?rev=1144044&view=rev
Log:
Use the Thread context classloader when deserializing

Modified:
    geronimo/tck/branches/3.0/geronimo-porting/src/main/java/org/apache/geronimo/test/tck/BeansImpl.java

Modified: geronimo/tck/branches/3.0/geronimo-porting/src/main/java/org/apache/geronimo/test/tck/BeansImpl.java
URL: http://svn.apache.org/viewvc/geronimo/tck/branches/3.0/geronimo-porting/src/main/java/org/apache/geronimo/test/tck/BeansImpl.java?rev=1144044&r1=1144043&r2=1144044&view=diff
==============================================================================
--- geronimo/tck/branches/3.0/geronimo-porting/src/main/java/org/apache/geronimo/test/tck/BeansImpl.java
(original)
+++ geronimo/tck/branches/3.0/geronimo-porting/src/main/java/org/apache/geronimo/test/tck/BeansImpl.java
Thu Jul  7 21:17:25 2011
@@ -18,13 +18,16 @@
  */
 package org.apache.geronimo.test.tck;
 
+import org.jboss.jsr299.tck.spi.Beans;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-
-import org.jboss.jsr299.tck.spi.Beans;
+import java.io.ObjectStreamClass;
+import java.lang.reflect.Proxy;
 
 public class BeansImpl implements Beans {
 
@@ -46,8 +49,51 @@ public class BeansImpl implements Beans 
     @Override
     public Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
         ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
-        ObjectInputStream is = new ObjectInputStream(bais);
+        ObjectInputStream is = new BeanObjectInputStream(bais);
         return is.readObject();
     }
 
+
+    public static class BeanObjectInputStream extends ObjectInputStream {
+
+        public BeanObjectInputStream(InputStream in) throws IOException {
+            super(in);
+        }
+
+        protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException
{
+            try {
+                return Class.forName(classDesc.getName(), false, getClassloader());
+            } catch (ClassNotFoundException e) {
+                String n = classDesc.getName();
+                if (n.equals("boolean")) return boolean.class;
+                if (n.equals("byte")) return byte.class;
+                if (n.equals("char")) return char.class;
+                if (n.equals("short")) return short.class;
+                if (n.equals("int")) return int.class;
+                if (n.equals("long")) return long.class;
+                if (n.equals("float")) return float.class;
+                if (n.equals("double")) return double.class;
+
+                throw e;
+            }
+        }
+
+        protected Class resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException
{
+            Class[] cinterfaces = new Class[interfaces.length];
+            for (int i = 0; i < interfaces.length; i++)
+                cinterfaces[i] = getClassloader().loadClass(interfaces[i]);
+
+            try {
+                return Proxy.getProxyClass(getClassloader(), cinterfaces);
+            } catch (IllegalArgumentException e) {
+                throw new ClassNotFoundException(null, e);
+            }
+        }
+
+        ClassLoader getClassloader() {
+            return Thread.currentThread().getContextClassLoader();
+        }
+    }
+
+
 }



Mime
View raw message