Jumbo patch:

* Imported beans and serialization
* Updated IA-64 port
* Miscellaneous bug fixes

From-SVN: r34028
This commit is contained in:
Tom Tromey 2000-05-19 17:55:34 +00:00
parent 021c89ed68
commit 6c80c45e30
125 changed files with 18458 additions and 560 deletions

View file

@ -0,0 +1,39 @@
/* BlockDataException.java -- Class used to store name and class of fields
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
//TODO: check 1.2 API to make sure this mathces
class BlockDataException extends IOException
{
public BlockDataException( int bytes )
{
super( bytes + " bytes are available in the next data block" );
}
}

View file

@ -0,0 +1,98 @@
/* Externalizable.java -- Interface for saving and restoring object data
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
/**
* This interface provides a way that classes can completely control how
* the data of their object instances are written and read to and from
* streams. It has two methods which are used to write the data to a stream
* and to read the data from a stream. The read method must read the data
* in exactly the way it was written by the write method.
* <p>
* Note that classes which implement this interface must take into account
* that all superclass data must also be written to the stream as well.
* The class implementing this interface must figure out how to make that
* happen.
* <p>
* This interface can be used to provide object persistence. When an
* object is to be stored externally, the <code>writeExternal</code> method is
* called to save state. When the object is restored, an instance is
* created using the default no-argument constructor and the
* <code>readExternal</code> method is used to restore the state.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public abstract interface Externalizable extends Serializable
{
/**
* This method restores an object's state by reading in the instance data
* for the object from the passed in stream. Note that this stream is not
* a subclass of <code>InputStream</code>, but rather is a class that implements
* the <code>ObjectInput</code> interface. That interface provides a mechanism for
* reading in Java data types from a stream.
* <p>
* Note that this method must be compatible with <code>writeExternal</code>.
* It must read back the exact same types that were written by that
* method in the exact order they were written.
* <p>
* If this method needs to read back an object instance, then the class
* for that object must be found and loaded. If that operation fails,
* then this method throws a <code>ClassNotFoundException</code>
*
* @param in An <code>ObjectInput</code> instance for reading in the object state
*
* @exception ClassNotFoundException If the class of an object being restored cannot be found
* @exception IOException If any other error occurs
*/
public abstract void
readExternal(ObjectInput in) throws ClassNotFoundException, IOException;
/*************************************************************************/
/**
* This method is responsible for writing the instance data of an object
* to the passed in stream. Note that this stream is not a subclass of
* <code>OutputStream</code>, but rather is a class that implements the
* <code>ObjectOutput</code> interface. That interface provides a number of methods
* for writing Java data values to a stream.
* <p>
* Not that the implementation of this method must be coordinated with
* the implementation of <code>readExternal</code>.
*
* @param out An <code>ObjectOutput</code> instance for writing the object state
*
* @exception IOException If an error occurs
*/
public abstract void
writeExternal(ObjectOutput out) throws IOException;
} // interface Externalizable

View file

@ -0,0 +1,110 @@
/* InvalidClassException.java -- An I/O operation was interrupted.
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
/**
* This exception is thrown when there is some sort of problem with a
* class during a serialization operation. This could be that the
* versions don't match, that there are unknown datatypes in the class
* or that the class doesn't have a default no-arg constructor.
* <p>
* The field <code>classname</code> will contain the name of the
* class that caused the problem if known. The getMessage() method
* for this exception will always include the name of that class
* if known.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public class InvalidClassException extends ObjectStreamException
{
/*
* Instance Variables
*/
/**
* The name of the class which encountered the error.
*/
public String classname;
/*************************************************************************/
/*
* Constructors
*/
/**
* Create a new InvalidClassException with a descriptive error message String
*
* @param message The descriptive error message
*/
public
InvalidClassException(String message)
{
super(message);
}
/*************************************************************************/
/**
* Create a new InvalidClassException with a descriptive error message
* String, and the name of the class that caused the problem.
*
* @param classname The number of bytes tranferred before the interruption
* @param message The descriptive error message
*/
public
InvalidClassException(String classname, String message)
{
super(message);
this.classname = classname;
}
/*************************************************************************/
/*
* Instance Methods
*/
/**
* Returns the descriptive error message for this exception. It will
* include the class name that caused the problem if known. This method
* overrides Throwable.getMessage()
*
* @return A descriptive error message
*/
public String
getMessage()
{
return(super.getMessage() + ": " + classname);
}
} // class InvalidClassException

View file

@ -0,0 +1,57 @@
/* InvalidObjectException.java -- An I/O operation was interrupted.
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
/**
* This exception is thrown when an object fails a validation test
* during serialization.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public class InvalidObjectException extends ObjectStreamException
{
/*
* Constructors
*/
/**
* Create a new InvalidObjectException with a descriptive error message String
*
* @param message The descriptive error message
*/
public
InvalidObjectException(String message)
{
super(message);
}
} // class InvalidObjectException

View file

@ -0,0 +1,68 @@
/* NotActiveException.java -- Unexpected end of file exception
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
/**
* This exception is thrown when a problem occurs due to the fact that
* serialization is not active.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public class NotActiveException extends ObjectStreamException
{
/*
* Constructors
*/
/**
* Create a new NotActiveException without a descriptive error message
*/
public
NotActiveException()
{
super();
}
/*************************************************************************/
/**
* Create a new NotActiveException with a descriptive error message String
*
* @param message The descriptive error message
*/
public
NotActiveException(String message)
{
super(message);
}
} // class NotActiveException

View file

@ -0,0 +1,69 @@
/* NotSerializableException.java -- Unexpected end of file exception
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
/**
* This exception is thrown when a class may not be serialized. The
* descriptive message will consist of the name of the class in question.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public class NotSerializableException extends ObjectStreamException
{
/*
* Constructors
*/
/**
* Create a new NotSerializableException without a descriptive error message
*/
public
NotSerializableException()
{
super();
}
/*************************************************************************/
/**
* Create a new NotSerializableException with a descriptive error message String
* This should be the name of the class that cannot be serialized.
*
* @param message The descriptive error message
*/
public
NotSerializableException(String message)
{
super(message);
}
} // class NotSerializableException

View file

@ -0,0 +1,147 @@
/* ObjectInput.java -- Read object data from a stream
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
/**
* This interface extends the <code>DataInput</code> interface to provide a
* facility to read objects as well as primitive types from a stream. It
* also has methods that allow input to be done in a manner similar to
* <code>InputStream</code>
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public abstract interface ObjectInput extends DataInput
{
/**
* This method returns the number of bytes that can be read without
* blocking.
*
* @return The number of bytes available before blocking
*
* @exception IOException If an error occurs
*/
public abstract int
available() throws IOException;
/*************************************************************************/
/**
* This method reading a byte of data from a stream. It returns that byte
* as an int. This method blocks if no data is available to be read.
*
* @return The byte of data read
*
* @exception IOException If an error occurs
*/
public abstract int
read() throws IOException;
/*************************************************************************/
/**
* This method reads raw bytes and stores them them a byte array buffer.
* Note that this method will block if no data is available. However,
* it will not necessarily block until it fills the entire buffer. That is,
* a "short count" is possible.
*
* @param buf The byte array to receive the data read
*
* @return The actual number fo bytes read or -1 if end of stream
*
* @exception IOException If an error occurs
*/
public abstract int
read(byte[] buf) throws IOException;
/*************************************************************************/
/**
* This method reads raw bytes and stores them in a byte array buffer
* <code>buf</code> starting at position <code>offset</code> into the buffer. A
* maximum of <code>len</code> bytes will be read. Note that this method
* blocks if no data is available, but will not necessarily block until
* it can read <code>len</code> bytes of data. That is, a "short count" is
* possible.
*
* @param buf The byte array to receive the data read
* @param offset The offset into @code{buf} to start storing data
* @param len The maximum number of bytes to read
*
* @return The actual number fo bytes read or -1 if end of stream
*
* @exception IOException If an error occurs
*/
public abstract int
read(byte[] buf, int offset, int len) throws IOException;
/*************************************************************************/
/**
* Reads an object instance and returns it. If the class for the object
* being read cannot be found, then a ClassNotFoundException will
* be thrown.
*
* @return The object instance that was read
*
* @exception ClassNotFoundException If a class for the object cannot be found
* @exception IOException If an error occurs
*/
public abstract Object
readObject() throws ClassNotFoundException, IOException;
/*************************************************************************/
/**
* This method causes the specified number of bytes to be read and
* discarded. It is possible that fewer than the requested number of bytes
* will actually be skipped.
*
* @param num_bytes The number of bytes to skip
*
* @return The actual number of bytes skipped
*
* @exception IOException If an error occurs
*/
public abstract long
skip(long num_bytes) throws IOException;
/*************************************************************************/
/**
* This method closes the input source
*
* @exception IOException If an error occurs
*/
public abstract void
close() throws IOException;
} // interface ObjectInput

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,50 @@
/* ObjectInputValidation.java -- Validate an object
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
/**
* What does this interface really do?
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public abstract interface ObjectInputValidation
{
/**
* This method is called to validate an object. If the object is invalid
* an exception is thrown.
*
* @exception InvalidObjectException If the object is invalid
*/
public abstract void
validateObject() throws InvalidObjectException;
} // interface ObjectInputValidation

View file

@ -0,0 +1,116 @@
/* ObjectOutput.java -- Interface for writing objects to a stream
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
/**
* This interface extends <code>DataOutput</code> to provide the additional
* facility of writing object instances to a stream. It also adds some
* additional methods to make the interface more <code>OutputStream</code> like.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public abstract interface ObjectOutput extends DataOutput
{
/**
* This method writes the specified byte to the output stream.
*
* @param b The byte to write.
*
* @exception IOException If an error occurs.
*/
public abstract void
write(int b) throws IOException;
/*************************************************************************/
/**
* This method writes all the bytes in the specified byte array to the
* output stream.
*
* @param buf The array of bytes to write.
*
* @exception IOException If an error occurs.
*/
public abstract void
write(byte[] buf) throws IOException;
/*************************************************************************/
/**
* This method writes <code>len</code> bytes from the specified array
* starting at index <code>offset</code> into that array.
*
* @param buf The byte array to write from.
* @param offset The index into the byte array to start writing from.
* @param len The number of bytes to write.
*
* @exception IOException If an error occurs.
*/
public abstract void
write(byte[] buf, int offset, int len) throws IOException;
/*************************************************************************/
/**
* This method writes a object instance to a stream. The format of the
* data written is determined by the actual implementation of this method
*
* @param obj The object to write
*
* @exception IOException If an error occurs
*/
public abstract void
writeObject(Object obj) throws IOException;
/*************************************************************************/
/**
* This method causes any buffered data to be flushed out to the underlying
* stream
*
* @exception IOException If an error occurs
*/
public abstract void
flush() throws IOException;
/*************************************************************************/
/**
* This method closes the underlying stream.
*
* @exception IOException If an error occurs
*/
public abstract void
close() throws IOException;
} // interface ObjectOutput

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,666 @@
/* ObjectStreamClass.java -- Class used to write class information
about serialized objects.
Copyright (C) 1998, 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Hashtable;
import java.util.Vector;
import gnu.java.io.NullOutputStream;
import gnu.java.lang.reflect.TypeSignature;
import gnu.gcj.io.SimpleSHSStream;
public class ObjectStreamClass implements Serializable
{
/**
Returns the <code>ObjectStreamClass</code> for <code>cl</code>.
If <code>cl</code> is null, or is not <code>Serializable</code>,
null is returned. <code>ObjectStreamClass</code>'s are memoized;
later calls to this method with the same class will return the
same <code>ObjectStreamClass</code> object and no recalculation
will be done.
@see java.io.Serializable
*/
public static ObjectStreamClass lookup (Class cl)
{
if (cl == null)
return null;
ObjectStreamClass osc = (ObjectStreamClass)classLookupTable.get (cl);
if (osc != null)
return osc;
else if (! (Serializable.class).isAssignableFrom (cl))
return null;
else
{
osc = new ObjectStreamClass (cl);
classLookupTable.put (cl, osc);
return osc;
}
}
/**
Returns the name of the class that this
<code>ObjectStreamClass</code> represents.
*/
public String getName ()
{
return name;
}
/**
Returns the class that this <code>ObjectStreamClass</code>
represents. Null could be returned if this
<code>ObjectStreamClass</code> was read from an
<code>ObjectInputStream</code> and the class it represents cannot
be found or loaded.
@see java.io.ObjectInputStream
*/
public Class forClass ()
{
return clazz;
}
/**
Returns the serial version stream-unique identifier for the class
represented by this <code>ObjectStreamClass</code>. This SUID is
either defined by the class as <code>static final long
serialVersionUID</code> or is calculated as specified in
Javasoft's "Object Serialization Specification" XXX: add reference
*/
public long getSerialVersionUID ()
{
return uid;
}
// Returns the serializable (non-static and non-transient) Fields
// of the class represented by this ObjectStreamClass. The Fields
// are sorted by name.
// XXX doc
public ObjectStreamField[] getFields ()
{
ObjectStreamField[] copy = new ObjectStreamField[ fields.length ];
System.arraycopy (fields, 0, copy, 0, fields.length);
return copy;
}
// XXX doc
// Can't do binary search since fields is sorted by name and
// primitiveness.
public ObjectStreamField getField (String name)
{
for (int i=0; i < fields.length; i++)
if (fields[i].getName ().equals (name))
return fields[i];
return null;
}
/**
Returns a textual representation of this
<code>ObjectStreamClass</code> object including the name of the
class it represents as well as that class's serial version
stream-unique identifier.
@see getSerialVersionUID ()
@see getName ()
*/
public String toString ()
{
return "java.io.ObjectStreamClass< " + name + ", " + uid + " >";
}
// Returns true iff the class that this ObjectStreamClass represents
// has the following method:
//
// private void writeObject (ObjectOutputStream)
//
// This method is used by the class to override default
// serialization behaivior.
boolean hasWriteMethod ()
{
return (flags & ObjectStreamConstants.SC_WRITE_METHOD) != 0;
}
// Returns true iff the class that this ObjectStreamClass represents
// implements Serializable but does *not* implement Externalizable.
boolean isSerializable ()
{
return (flags & ObjectStreamConstants.SC_SERIALIZABLE) != 0;
}
// Returns true iff the class that this ObjectStreamClass represents
// implements Externalizable.
boolean isExternalizable ()
{
return (flags & ObjectStreamConstants.SC_EXTERNALIZABLE) != 0;
}
// Returns the <code>ObjectStreamClass</code> that represents the
// class that is the superclass of the class this
// <code>ObjectStreamClass</cdoe> represents. If the superclass is
// not Serializable, null is returned.
ObjectStreamClass getSuper ()
{
return superClass;
}
// returns an array of ObjectStreamClasses that represent the super
// classes of CLAZZ and CLAZZ itself in order from most super to
// CLAZZ. ObjectStreamClass[0] is the highest superclass of CLAZZ
// that is serializable.
static ObjectStreamClass[] getObjectStreamClasses (Class clazz)
{
ObjectStreamClass osc = ObjectStreamClass.lookup (clazz);
ObjectStreamClass[] ret_val;
if (osc == null)
return new ObjectStreamClass[0];
else
{
Vector oscs = new Vector ();
while (osc != null)
{
oscs.addElement (osc);
osc = osc.getSuper ();
}
int count = oscs.size ();
ObjectStreamClass[] sorted_oscs = new ObjectStreamClass[ count ];
for (int i = count - 1; i >= 0; i--)
sorted_oscs[ count - i - 1 ] = (ObjectStreamClass)oscs.elementAt (i);
return sorted_oscs;
}
}
// Returns an integer that consists of bit-flags that indicate
// properties of the class represented by this ObjectStreamClass.
// The bit-flags that could be present are those defined in
// ObjectStreamConstants that begin with `SC_'
int getFlags ()
{
return flags;
}
ObjectStreamClass (String name, long uid, byte flags,
ObjectStreamField[] fields)
{
this.name = name;
this.uid = uid;
this.flags = flags;
this.fields = fields;
}
void setClass (Class clazz)
{
this.clazz = clazz;
}
void setSuperclass (ObjectStreamClass osc)
{
superClass = osc;
}
void calculateOffsets ()
{
int i;
ObjectStreamField field;
primFieldSize = 0;
int fcount = fields.length;
for (i = 0; i < fcount; ++ i)
{
field = fields[i];
if (! field.isPrimitive ())
break;
field.setOffset (primFieldSize);
switch (field.getTypeCode ())
{
case 'B':
case 'Z':
++ primFieldSize;
break;
case 'C':
case 'S':
primFieldSize += 2;
break;
case 'I':
case 'F':
primFieldSize += 4;
break;
case 'D':
case 'J':
primFieldSize += 8;
break;
}
}
for (objectFieldCount = 0; i < fcount; ++ i)
fields[i].setOffset (objectFieldCount++);
}
private ObjectStreamClass (Class cl)
{
uid = 0;
flags = 0;
clazz = cl;
name = cl.getName ();
setFlags (cl);
setFields (cl);
setUID (cl);
superClass = lookup (cl.getSuperclass ());
}
// Sets bits in flags according to features of CL.
private void setFlags (Class cl)
{
if ((java.io.Externalizable.class).isAssignableFrom (cl))
flags |= ObjectStreamConstants.SC_EXTERNALIZABLE;
else if ((java.io.Serializable.class).isAssignableFrom (cl))
// only set this bit if CL is NOT Externalizable
flags |= ObjectStreamConstants.SC_SERIALIZABLE;
try
{
Method writeMethod = cl.getDeclaredMethod ("writeObject",
writeMethodArgTypes);
int modifiers = writeMethod.getModifiers ();
if (writeMethod.getReturnType () == Void.TYPE
&& Modifier.isPrivate (modifiers)
&& !Modifier.isStatic (modifiers))
flags |= ObjectStreamConstants.SC_WRITE_METHOD;
}
catch (NoSuchMethodException oh_well)
{}
}
// Sets fields to be a sorted array of the serializable fields of
// clazz.
private void setFields (Class cl)
{
if (! isSerializable () || isExternalizable ())
{
fields = NO_FIELDS;
return;
}
try
{
Field serialPersistantFields
= cl.getDeclaredField ("serialPersistantFields");
int modifiers = serialPersistantFields.getModifiers ();
if (Modifier.isStatic (modifiers)
&& Modifier.isFinal (modifiers)
&& Modifier.isPrivate (modifiers))
{
fields = getSerialPersistantFields (cl);
Arrays.sort (fields);
calculateOffsets ();
return;
}
}
catch (NoSuchFieldException ignore)
{}
int num_good_fields = 0;
Field[] all_fields = cl.getDeclaredFields ();
int modifiers;
// set non-serializable fields to null in all_fields
for (int i=0; i < all_fields.length; i++)
{
modifiers = all_fields[i].getModifiers ();
if (Modifier.isTransient (modifiers)
|| Modifier.isStatic (modifiers))
all_fields[i] = null;
else
num_good_fields++;
}
// make a copy of serializable (non-null) fields
fields = new ObjectStreamField[ num_good_fields ];
for (int from=0, to=0; from < all_fields.length; from++)
if (all_fields[from] != null)
{
Field f = all_fields[from];
fields[to] = new ObjectStreamField (f.getName (), f.getType ());
to++;
}
Arrays.sort (fields);
calculateOffsets ();
}
// Sets uid be serial version UID defined by class, or if that
// isn't present, calculates value of serial version UID.
private void setUID (Class cl)
{
try
{
Field suid = cl.getDeclaredField ("serialVersionUID");
int modifiers = suid.getModifiers ();
if (Modifier.isStatic (modifiers)
&& Modifier.isFinal (modifiers))
{
uid = getDefinedSUID (cl);
return;
}
}
catch (NoSuchFieldException ignore)
{}
// cl didn't define serialVersionUID, so we have to compute it
try
{
MessageDigest md = null;
DigestOutputStream digest_out = null;
DataOutputStream data_out = null;
SimpleSHSStream simple = null;
try
{
md = MessageDigest.getInstance ("SHA");
digest_out = new DigestOutputStream (nullOutputStream, md);
data_out = new DataOutputStream (digest_out);
}
catch (NoSuchAlgorithmException e)
{
simple = new SimpleSHSStream (nullOutputStream);
data_out = new DataOutputStream (simple);
}
data_out.writeUTF (cl.getName ());
int modifiers = cl.getModifiers ();
// just look at interesting bits
modifiers = modifiers & (Modifier.ABSTRACT | Modifier.FINAL
| Modifier.INTERFACE | Modifier.PUBLIC);
data_out.writeInt (modifiers);
Class[] interfaces = cl.getInterfaces ();
Arrays.sort (interfaces, interfaceComparator);
for (int i=0; i < interfaces.length; i++)
data_out.writeUTF (interfaces[i].getName ());
Field field;
Field[] fields = cl.getDeclaredFields ();
Arrays.sort (fields, memberComparator);
for (int i=0; i < fields.length; i++)
{
field = fields[i];
modifiers = field.getModifiers ();
if (Modifier.isPrivate (modifiers)
&& (Modifier.isStatic (modifiers)
|| Modifier.isTransient (modifiers)))
continue;
data_out.writeUTF (field.getName ());
data_out.writeInt (modifiers);
data_out.writeUTF (TypeSignature.getEncodingOfClass (field.getType ()));
}
// write class initializer method if present
boolean has_init;
try
{
has_init = hasClassInitializer (cl);
}
catch (NoSuchMethodError e)
{
has_init = false;
}
if (has_init)
{
data_out.writeUTF ("<clinit>");
data_out.writeInt (Modifier.STATIC);
data_out.writeUTF ("()V");
}
Constructor constructor;
Constructor[] constructors = cl.getDeclaredConstructors ();
Arrays.sort (constructors, memberComparator);
for (int i=0; i < constructors.length; i++)
{
constructor = constructors[i];
modifiers = constructor.getModifiers ();
if (Modifier.isPrivate (modifiers))
continue;
data_out.writeUTF ("<init>");
data_out.writeInt (modifiers);
// the replacement of '/' with '.' was needed to make computed
// SUID's agree with those computed by JDK
data_out.writeUTF (
TypeSignature.getEncodingOfConstructor (constructor).replace ('/','.'));
}
Method method;
Method[] methods = cl.getDeclaredMethods ();
Arrays.sort (methods, memberComparator);
for (int i=0; i < methods.length; i++)
{
method = methods[i];
modifiers = method.getModifiers ();
if (Modifier.isPrivate (modifiers))
continue;
data_out.writeUTF (method.getName ());
data_out.writeInt (modifiers);
// the replacement of '/' with '.' was needed to make computed
// SUID's agree with those computed by JDK
data_out.writeUTF (
TypeSignature.getEncodingOfMethod (method).replace ('/', '.'));
}
data_out.close ();
byte[] sha = md != null ? md.digest () : simple.digest ();
long result = 0;
int len = sha.length < 8 ? sha.length : 8;
for (int i=0; i < len; i++)
result += (long)(sha[i] & 0xFF) << (8 * i);
uid = result;
}
catch (NoSuchAlgorithmException e)
{
throw new RuntimeException ("The SHA algorithm was not found to use in computing the Serial Version UID for class "
+ cl.getName ());
}
catch (IOException ioe)
{
throw new RuntimeException (ioe.getMessage ());
}
}
// Returns the value of CLAZZ's final static long field named
// `serialVersionUID'.
private long getDefinedSUID (Class clazz)
{
long l = 0;
try
{
// Use getDeclaredField rather than getField, since serialVersionUID
// may not be public AND we only want the serialVersionUID of this
// class, not a superclass or interface.
Field f = clazz.getDeclaredField ("serialVersionUID");
l = f.getLong (null);
}
catch (java.lang.NoSuchFieldException e)
{
}
catch (java.lang.IllegalAccessException e)
{
}
return l;
}
// Returns the value of CLAZZ's private static final field named
// `serialPersistantFields'.
private ObjectStreamField[] getSerialPersistantFields (Class clazz)
{
ObjectStreamField[] o = null;
try
{
// Use getDeclaredField rather than getField for the same reason
// as above in getDefinedSUID.
Field f = clazz.getDeclaredField ("getSerialPersistantFields");
o = (ObjectStreamField[])f.get (null);
}
catch (java.lang.NoSuchFieldException e)
{
}
catch (java.lang.IllegalAccessException e)
{
}
return o;
}
// Returns true if CLAZZ has a static class initializer
// (a.k.a. <clinit>).
//
// A NoSuchMethodError is raised if CLAZZ has no such method.
private static boolean hasClassInitializer (Class clazz)
throws java.lang.NoSuchMethodError
{
Method m = null;
try
{
Class classArgs[] = {};
m = clazz.getMethod ("<clinit>", classArgs);
}
catch (java.lang.NoSuchMethodException e)
{
throw new java.lang.NoSuchMethodError ();
}
return m != null;
}
public static final ObjectStreamField[] NO_FIELDS = {};
private static Hashtable classLookupTable = new Hashtable ();
private static final NullOutputStream nullOutputStream = new NullOutputStream ();
private static final Comparator interfaceComparator = new InterfaceComparator ();
private static final Comparator memberComparator = new MemberComparator ();
private static final
Class[] writeMethodArgTypes = { java.io.ObjectOutputStream.class };
private ObjectStreamClass superClass;
private Class clazz;
private String name;
private long uid;
private byte flags;
// this field is package protected so that ObjectInputStream and
// ObjectOutputStream can access it directly
ObjectStreamField[] fields;
// these are accessed by ObjectIn/OutputStream
int primFieldSize = -1; // -1 if not yet calculated
int objectFieldCount;
}
// interfaces are compared only by name
class InterfaceComparator implements Comparator
{
public int compare (Object o1, Object o2)
{
return ((Class)o1).getName ().compareTo (((Class)o2).getName ());
}
}
// Members (Methods and Constructors) are compared first by name,
// conflicts are resolved by comparing type signatures
class MemberComparator implements Comparator
{
public int compare (Object o1, Object o2)
{
Member m1 = (Member)o1;
Member m2 = (Member)o2;
int comp = m1.getName ().compareTo (m2.getName ());
if (comp == 0)
return TypeSignature.getEncodingOfMember (m1).
compareTo (TypeSignature.getEncodingOfMember (m2));
else
return comp;
}
}

View file

@ -0,0 +1,74 @@
/* ObjectStreamConstants.java -- Interface containing constant values
used in reading and writing serialized objects
Copyright (C) 1998, 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
/**
This interface contains constants that are used in object
serialization. This interface is used by ObjectOutputStream,
ObjectInputStream, ObjectStreamClass, and possibly other classes.
The values for these constants are specified in Javasoft's "Object
Serialization Specification" TODO: add reference
*/
public interface ObjectStreamConstants
{
public final static int PROTOCOL_VERSION_1 = 1;
public final static int PROTOCOL_VERSION_2 = 2;
final static short STREAM_MAGIC = (short)0xaced;
final static short STREAM_VERSION = 5;
final static byte TC_NULL = (byte)112;
final static byte TC_REFERENCE = (byte)113;
final static byte TC_CLASSDESC = (byte)114;
final static byte TC_OBJECT = (byte)115;
final static byte TC_STRING = (byte)116;
final static byte TC_ARRAY = (byte)117;
final static byte TC_CLASS = (byte)118;
final static byte TC_BLOCKDATA = (byte)119;
final static byte TC_ENDBLOCKDATA = (byte)120;
final static byte TC_RESET = (byte)121;
final static byte TC_BLOCKDATALONG = (byte)122;
final static byte TC_EXCEPTION = (byte)123;
final static byte TC_BASE = TC_NULL;
final static byte TC_MAX = TC_EXCEPTION;
final static int baseWireHandle = 0x7e0000;
final static byte SC_WRITE_METHOD = 0x01;
final static byte SC_SERIALIZABLE = 0x02;
final static byte SC_EXTERNALIZABLE = 0x04;
final static byte SC_BLOCK_DATA = 0x08;
final static SerializablePermission SUBSTITUTION_PERMISSION
= new SerializablePermission("enableSubstitution");
final static SerializablePermission SUBCLASS_IMPLEMENTATION_PERMISSION
= new SerializablePermission("enableSubclassImplementation");
}

View file

@ -0,0 +1,99 @@
/* ObjectStreamField.java -- Class used to store name and class of fields
Copyright (C) 1998, 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
import gnu.java.lang.reflect.TypeSignature;
// XXX doc
public class ObjectStreamField implements java.lang.Comparable
{
public ObjectStreamField (String name, Class type)
{
this.name = name;
this.type = type;
}
public String getName ()
{
return name;
}
public Class getType ()
{
return type;
}
public char getTypeCode ()
{
return TypeSignature.getEncodingOfClass (type).charAt (0);
}
public String getTypeString ()
{
return TypeSignature.getEncodingOfClass (type);
}
public int getOffset ()
{
return offset;
}
protected void setOffset (int off)
{
offset = off;
}
public boolean isPrimitive ()
{
return type.isPrimitive ();
}
public int compareTo (Object o)
{
ObjectStreamField f = (ObjectStreamField)o;
boolean this_is_primitive = isPrimitive ();
boolean f_is_primitive = f.isPrimitive ();
if (this_is_primitive && !f_is_primitive)
return -1;
if (!this_is_primitive && f_is_primitive)
return 1;
return getName ().compareTo (f.getName ());
}
public String toString ()
{
return "ObjectStreamField< " + type + " " + name + " >";
}
private String name;
private Class type;
private int offset = -1; // XXX make sure this is correct
}

View file

@ -0,0 +1,54 @@
/* Replaceable.java -- Replace an object with another object
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
/**
* This interface is used to indicate that an object may want to have
* another object serialized instead of itself. It contains one method
* that is to be called when an object is to be serialized. That method
* is reponsible for returning the real object that should be serialized
* instead of object being queried.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public interface Replaceable extends Serializable
{
/**
* This method returns the object that should be serialized instead of
* this object
*
* @return The real object that should be serialized
*/
public abstract Object
writeReplace();
} // interface Replaceable

View file

@ -0,0 +1,52 @@
/* Resolvable.java -- Returns an object to replace the one being de-serialized
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
/**
* This interface is implemented when an object wishes to return another
* object to replace it during de-serialization. It has one method that
* returns the object that should be used to replace the original object.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public interface Resolvable extends Serializable
{
/**
* This method returns the object that should be used to replace the
* original object during de-serialization.
*
* @return The replacement object
*/
public abstract Object
readResolve();
} // interface Resolvable

View file

@ -0,0 +1,106 @@
/* SerializablePermission.java -- Basic permissions related to serialization.
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
import java.security.BasicPermission;
/**
* This class models permissions related to serialization. As a subclass
* of <code>BasicPermission</code>, this class has permissions that have
* a name only. There is no associated action list.
* <p>
* There are currently two allowable permission names for this class:
* <ul>
* <li><code>enableSubclassImplementation</code> - Allows a subclass to
* override the default serialization behavior of objects.
* <li><code>enableSubstitution</code> - Allows substitution of one object
* for another during serialization or deserialization.
* </ul>
*
* @see java.security.BasicPermission
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public final class SerializablePermission extends BasicPermission
{
/*
* Class Variables
*/
public static final String[] legal_names = { "enableSubclassImplementation",
"enableSubstitution" };
/*************************************************************************/
/*
* Constructors
*/
/**
* This method initializes a new instance of <code>SerializablePermission</code>
* that has the specified name.
*
* @param name The name of the permission.
*
* @exception IllegalArgumentException If the name is not valid for this class.
*/
public
SerializablePermission(String name)
{
this(name, null);
}
/*************************************************************************/
/**
* This method initializes a new instance of <code>SerializablePermission</code>
* that has the specified name and action list. Note that the action list
* is unused in this class.
*
* @param name The name of the permission.
* @param actions The action list (unused).
*
* @exception IllegalArgumentException If the name is not valid for this class.
*/
public
SerializablePermission(String name, String actions)
{
super(name, actions);
for (int i = 0; i < legal_names.length; i++)
if (legal_names[i].equals(name))
return;
throw new IllegalArgumentException("Bad permission name: " + name);
}
} // class SerializablePermission

View file

@ -0,0 +1,89 @@
/* WriteAbortedException.java -- An exception occured while writing a
serialization stream
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.io;
/**
* This exception is thrown when one of the other ObjectStreamException
* subclasses was thrown during a serialization write.
*
* @version 0.0
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
public class WriteAbortedException extends ObjectStreamException
{
/*
* Instance Variables
*/
/**
* The detailed exception that caused this exception to be thrown
*/
public Exception detail;
private String message;
/*************************************************************************/
/*
* Constructors
*/
/**
* Create a new WriteAbortedException with an eof parameter indicating
* the detailed Exception that caused this exception to be thrown.
*
* @param detail The exception that caused this exception to be thrown
*/
public
WriteAbortedException(String msg, Exception detail)
{
this.message = msg;
this.detail = detail;
}
/*************************************************************************/
/*
* Instance Variables
*/
/**
* This method returns a message indicating what went wrong, including
* the message text from the initial exception that caused this one to
* be thrown
*/
public String
getMessage()
{
return(message + ": " + detail.getMessage());
}
} // class WriteAbortedException

View file

@ -0,0 +1,78 @@
// natObjectInputStream.cc - Native part of ObjectInputStream class.
/* Copyright (C) 1998, 1999 Free Software Foundation
This ObjectInputStream is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the ObjectInputStream "LIBGCJ_LICENSE" for
details. */
#include <config.h>
#include <gcj/cni.h>
#include <jvm.h>
#include <java/io/ObjectInputStream$GetField.h>
#include <java/io/ObjectInputStream.h>
#include <java/io/IOException.h>
#include <java/lang/Class.h>
#include <java/lang/reflect/Modifier.h>
#include <java/lang/reflect/Method.h>
jobject
java::io::ObjectInputStream::allocateObject (jclass klass)
{
jobject obj = NULL;
using namespace java::lang::reflect;
try
{
JvAssert (klass && ! klass->isArray ());
if (klass->isInterface() || Modifier::isAbstract(klass->getModifiers()))
obj = NULL;
else
{
// FIXME: will this work for String?
obj = JvAllocObject (klass);
}
}
catch (jthrowable t)
{
return NULL;
}
return obj;
}
#define ObjectClass _CL_Q34java4lang6Object
extern java::lang::Class ObjectClass;
#define ClassClass _CL_Q34java4lang5Class
extern java::lang::Class ClassClass;
void
java::io::ObjectInputStream::callConstructor (jclass klass, jobject obj)
{
jstring init_name = JvNewStringLatin1 ("<init>");
JArray<jclass> *arg_types
= (JArray<jclass> *) JvNewObjectArray (0, &ClassClass, NULL);
JArray<jobject> *args
= (JArray<jobject> *) JvNewObjectArray (0, &ObjectClass, NULL);
java::lang::reflect::Method *m = klass->getPrivateMethod (init_name, arg_types);
m->invoke (obj, args);
}
java::lang::reflect::Field *
java::io::ObjectInputStream::getField (jclass klass, jstring name)
{
return klass->getPrivateField (name);
}
java::lang::reflect::Method *
java::io::ObjectInputStream::getMethod (jclass klass, jstring name,
JArray<jclass> *arg_types)
{
return klass->getPrivateMethod (name, arg_types);
}

View file

@ -0,0 +1,33 @@
// natObjectOutputStream.cc - Native part of ObjectOutputStream class.
/* Copyright (C) 1998, 1999 Free Software Foundation
This ObjectOutputStream is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the ObjectOutputStream "LIBGCJ_LICENSE" for
details. */
#include <config.h>
#include <gcj/cni.h>
#include <jvm.h>
#include <java/io/ObjectOutputStream$PutField.h>
#include <java/io/ObjectOutputStream.h>
#include <java/io/IOException.h>
#include <java/lang/Class.h>
java::lang::reflect::Field *
java::io::ObjectOutputStream::getField (jclass klass, jstring name)
{
return klass->getPrivateField (name);
}
java::lang::reflect::Method *
java::io::ObjectOutputStream::getMethod (jclass klass, jstring name,
JArray<jclass> *arg_types)
{
return klass->getPrivateMethod (name, arg_types);
}