org.apache.wicket.util.io
Class SerializableChecker

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.ObjectOutputStream
          extended by org.apache.wicket.util.io.SerializableChecker
All Implemented Interfaces:
java.io.Closeable, java.io.DataOutput, java.io.Flushable, java.io.ObjectOutput, java.io.ObjectStreamConstants

public final class SerializableChecker
extends java.io.ObjectOutputStream

Utility class that analyzes objects for non-serializable nodes. Construct, then call check(Object) with the object you want to check. When a non-serializable object is found, a SerializableChecker.WicketNotSerializableException is thrown with a message that shows the trace up to the not-serializable object. The exception is thrown for the first non-serializable instance it encounters, so multiple problems will not be shown.

As this class depends heavily on JDK's serialization internals using introspection, analyzing may not be possible, for instance when the runtime environment does not have sufficient rights to set fields accessible that would otherwise be hidden. You should call isAvailable() to see whether this class can operate properly. If it doesn't, you should fall back to e.g. re-throwing/ printing the SerializableChecker.WicketNotSerializableException you probably got before using this class.

Author:
eelcohillenius, Al Maw

Nested Class Summary
static class SerializableChecker.WicketNotSerializableException
          Exception that is thrown when a non-serializable object was found.
 
Nested classes/interfaces inherited from class java.io.ObjectOutputStream
java.io.ObjectOutputStream.PutField
 
Field Summary
 
Fields inherited from interface java.io.ObjectStreamConstants
baseWireHandle, PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, SC_BLOCK_DATA, SC_ENUM, SC_EXTERNALIZABLE, SC_SERIALIZABLE, SC_WRITE_METHOD, STREAM_MAGIC, STREAM_VERSION, SUBCLASS_IMPLEMENTATION_PERMISSION, SUBSTITUTION_PERMISSION, TC_ARRAY, TC_BASE, TC_BLOCKDATA, TC_BLOCKDATALONG, TC_CLASS, TC_CLASSDESC, TC_ENDBLOCKDATA, TC_ENUM, TC_EXCEPTION, TC_LONGSTRING, TC_MAX, TC_NULL, TC_OBJECT, TC_PROXYCLASSDESC, TC_REFERENCE, TC_RESET, TC_STRING
 
Constructor Summary
SerializableChecker(java.io.NotSerializableException exception)
          Construct.
 
Method Summary
static boolean isAvailable()
          Gets whether we can execute the tests.
 void reset()
           
protected  void writeObjectOverride(java.lang.Object obj)
           
 
Methods inherited from class java.io.ObjectOutputStream
annotateClass, annotateProxyClass, close, defaultWriteObject, drain, enableReplaceObject, flush, putFields, replaceObject, useProtocolVersion, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeClassDescriptor, writeDouble, writeFields, writeFloat, writeInt, writeLong, writeObject, writeShort, writeStreamHeader, writeUnshared, writeUTF
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerializableChecker

public SerializableChecker(java.io.NotSerializableException exception)
                    throws java.io.IOException
Construct.

Parameters:
exception - exception that should be set as the cause when throwing a new exception
Throws:
java.io.IOException
Method Detail

isAvailable

public static boolean isAvailable()
Gets whether we can execute the tests. If false, calling check(Object) will just return and you are advised to rely on the SerializableChecker.WicketNotSerializableException. Clients are advised to call this method prior to calling the check method.

Returns:
whether security settings and underlying API etc allow for accessing the serialization API using introspection

reset

public void reset()
           throws java.io.IOException
Overrides:
reset in class java.io.ObjectOutputStream
Throws:
java.io.IOException
See Also:
ObjectOutputStream.reset()

writeObjectOverride

protected final void writeObjectOverride(java.lang.Object obj)
                                  throws java.io.IOException
Overrides:
writeObjectOverride in class java.io.ObjectOutputStream
Throws:
java.io.IOException
See Also:
ObjectOutputStream.writeObjectOverride(java.lang.Object)


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.