[jboss-svn-commits] JBoss Common SVN: r2044 - common-core/trunk/src/main/java/org/jboss/util/stream
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Sep 19 18:37:27 EDT 2006
Author: bstansberry at jboss.com
Date: 2006-09-19 18:37:25 -0400 (Tue, 19 Sep 2006)
New Revision: 2044
Added:
common-core/trunk/src/main/java/org/jboss/util/stream/MarshalledValueInputStream.java
common-core/trunk/src/main/java/org/jboss/util/stream/MarshalledValueOutputStream.java
Log:
[JBCOMMON-8] Port MarshalledValueInputStream/MarshalledValueOutputStream from AS aop module
Added: common-core/trunk/src/main/java/org/jboss/util/stream/MarshalledValueInputStream.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/stream/MarshalledValueInputStream.java 2006-09-18 14:42:14 UTC (rev 2043)
+++ common-core/trunk/src/main/java/org/jboss/util/stream/MarshalledValueInputStream.java 2006-09-19 22:37:25 UTC (rev 2044)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.util.stream;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+
+/**
+ * An ObjectInputStream subclass used by the MarshalledValue class to
+ * ensure the classes and proxies are loaded using the thread context
+ * class loader.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 37406 $
+ */
+public class MarshalledValueInputStream
+ extends ObjectInputStream
+{
+ /**
+ * Creates a new instance of MarshalledValueOutputStream
+ */
+ public MarshalledValueInputStream(InputStream is) throws IOException
+ {
+ super(is);
+ }
+
+ /**
+ * Use the thread context class loader to resolve the class
+ *
+ * @throws java.io.IOException Any exception thrown by the underlying OutputStream.
+ */
+ protected Class resolveClass(ObjectStreamClass v)
+ throws IOException, ClassNotFoundException
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ String className = v.getName();
+ return loader.loadClass(className);
+ }
+
+ protected Class resolveProxyClass(String[] interfaces)
+ throws IOException, ClassNotFoundException
+ {
+ // Load the interfaces from the thread context class loader
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Class[] ifaceClasses = new Class[interfaces.length];
+ for (int i = 0; i < interfaces.length; i++)
+ {
+ ifaceClasses[i] = loader.loadClass(interfaces[i]);
+ }
+
+ return java.lang.reflect.Proxy.getProxyClass(loader, ifaceClasses);
+ }
+}
Added: common-core/trunk/src/main/java/org/jboss/util/stream/MarshalledValueOutputStream.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/stream/MarshalledValueOutputStream.java 2006-09-18 14:42:14 UTC (rev 2043)
+++ common-core/trunk/src/main/java/org/jboss/util/stream/MarshalledValueOutputStream.java 2006-09-19 22:37:25 UTC (rev 2044)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.util.stream;
+
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.rmi.Remote;
+import java.rmi.server.RemoteObject;
+import java.rmi.server.RemoteStub;
+
+/**
+ * An ObjectOutputStream subclass used by the MarshalledValue class to
+ * ensure the classes and proxies are loaded using the thread context
+ * class loader. Currently this does not do anything as neither class or
+ * proxy annotations are used.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 37406 $
+ */
+public class MarshalledValueOutputStream
+ extends ObjectOutputStream
+{
+ /** Creates a new instance of MarshalledValueOutputStream
+ If there is a security manager installed, this method requires a
+ SerializablePermission("enableSubstitution") permission to ensure it's
+ ok to enable the stream to do replacement of objects in the stream.
+ */
+ public MarshalledValueOutputStream(OutputStream os) throws IOException
+ {
+ super(os);
+ enableReplaceObject(true);
+ }
+
+ /**
+ * @throws java.io.IOException Any exception thrown by the underlying OutputStream.
+ */
+ protected void annotateClass(Class cl) throws IOException
+ {
+ super.annotateClass(cl);
+ }
+
+ /**
+ * @throws java.io.IOException Any exception thrown by the underlying OutputStream.
+ */
+ protected void annotateProxyClass(Class cl) throws IOException
+ {
+ super.annotateProxyClass(cl);
+ }
+
+ /** Override replaceObject to check for Remote objects that are
+ not RemoteStubs.
+ */
+ protected Object replaceObject(Object obj) throws IOException
+ {
+ if( (obj instanceof Remote) && !(obj instanceof RemoteStub) )
+ {
+ Remote remote = (Remote) obj;
+ try
+ {
+ obj = RemoteObject.toStub(remote);
+ }
+ catch(IOException ignore)
+ {
+ // Let the Serialization layer try with the orignal obj
+ }
+ }
+ return obj;
+ }
+}
More information about the jboss-svn-commits
mailing list