User: reverbel
Date: 01/11/26 15:36:32
Added: iiop/src/main/org/jboss/ejb/plugins/iiop/server
CustomObjectOutputStream.java
CustomObjectInputStreamWithClassloader.java
Log:
Custom object input/output streams used to (de)serialize entity bean PKs
for embedding them into IOR key fiels. (Right now these classes are under
contrib/iiop in org.jboss.ejb.plugins.iiop.server, but org.jboss.util is
probably a better place.)
Revision Changes Path
1.1
contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/server/CustomObjectOutputStream.java
Index: CustomObjectOutputStream.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.iiop.server;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.io.OutputStream;
/**
* Customized object output stream that redefines
* <code>writeClassDescriptor()</code> in order to write a short class
* descriptor (just the class name) when serializing an object.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Francisco Reverbel</a>
* @version $Revision: 1.1 $
*/
class CustomObjectOutputStream
extends ObjectOutputStream
{
/**
* Constructs a new instance with the given output stream.
*
* @param out stream to write objects to
*/
public CustomObjectOutputStream(OutputStream out)
throws IOException
{
super(out);
}
/**
* Writes just the class name to this output stream.
*
* @param classdesc class description object
*/
protected void writeClassDescriptor(ObjectStreamClass classdesc)
throws IOException
{
writeUTF(classdesc.getName());
}
}
1.1
contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/server/CustomObjectInputStreamWithClassloader.java
Index: CustomObjectInputStreamWithClassloader.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.iiop.server;
import java.io.InputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
import java.lang.reflect.Proxy;
/**
* Customized object input stream that
* <ul>
* <li> redefines <code>readClassDescriptor()</code> in order to read a short
* class descriptor (just the class name) when deserializing an
* object</li>
* <li> takes a class loader in its constructor and uses it to retrieve
* the class definitions.</li>
* </ul>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Rickard Oberg</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Francisco Reverbel</a>
* @version $Revision: 1.1 $
*/
class CustomObjectInputStreamWithClassloader
extends ObjectInputStream
{
/**
* The classloader to use when the default classloader cannot find
* the classes in the stream.
*/
ClassLoader cl;
/**
* Constructs a new instance with the given classloader and input stream.
*
* @param in stream to read objects from
* @param cl classloader to use
*/
public CustomObjectInputStreamWithClassloader(InputStream in,
ClassLoader cl)
throws IOException
{
super(in);
this.cl = cl;
}
/**
* Reads just the class name from this input stream.
*
* @return a class description object
*/
protected ObjectStreamClass readClassDescriptor()
throws IOException, ClassNotFoundException
{
return ObjectStreamClass.lookup(cl.loadClass(readUTF()));
}
/**
* Resolves the class described in the classdesc parameter. First, try the
* default classloader (implemented by the super class). If it cannot
* load the class, try the classloader given to this instance.
*
* @param classdesc class description object
* @return the Class corresponding to class description
* @exception IOException if an I/O error occurs
* @exception ClassNotFoundException if the class cannot be found
* by the classloader
*/
protected Class resolveClass(ObjectStreamClass classdesc)
throws IOException, ClassNotFoundException
{
return cl.loadClass(classdesc.getName());
}
/**
* Resolves the proxy class for the specified array of interfaces.
*
* @param interfaces an array of interfaces
* @return the proxy class
* @exception IOException if an I/O error occurs
* @exception ClassNotFoundException if the class cannot be found
* by the classloader
*/
protected Class resolveProxyClass(String[] interfaces)
throws IOException, ClassNotFoundException
{
Class[] interfacesClass = new Class[interfaces.length];
for( int i=0; i< interfaces.length; i++ ) {
interfacesClass[i] = Class.forName(interfaces[i], false, cl);
}
return Proxy.getProxyClass(cl, interfacesClass);
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development