The SerializeHelper is used to make implementing custom serialization
handlers easier. Handlers for certain object types need to be added to
this helper before this implementation is usable.
| Method from org.jfree.report.util.SerializerHelper Detail: |
protected ClassComparator getComparator() {
return comparator;
}
Returns the class comparator instance used to find correct super classes. |
public static synchronized SerializerHelper getInstance() {
if (singleton == null)
{
singleton = new SerializerHelper();
singleton.registerMethod(new BasicStrokeSerializer());
singleton.registerMethod(new ColorSerializer());
singleton.registerMethod(new Dimension2DSerializer());
singleton.registerMethod(new Ellipse2DSerializer());
singleton.registerMethod(new Line2DSerializer());
singleton.registerMethod(new Point2DSerializer());
singleton.registerMethod(new Rectangle2DSerializer());
singleton.registerMethod(new BandLayoutManagerSerializer());
singleton.registerMethod(new PageFormatSerializer());
}
return singleton;
}
Returns or creates a new SerializerHelper. When a new instance is
created by this method, all known SerializeMethods are registered. |
protected HashMap getMethods() {
return methods;
}
Returns the collection of all registered serialize methods. |
protected SerializeMethod getSerializer(Class c) {
final SerializeMethod sm = (SerializeMethod) methods.get(c);
if (sm != null)
{
return sm;
}
return getSuperClassObjectDescription(c, null);
}
Looks up the SerializeMethod for the given class or null if there is no
SerializeMethod for the given class. |
protected SerializeMethod getSuperClassObjectDescription(Class d,
SerializeMethod knownSuperClass) {
final Iterator keys = methods.keySet().iterator();
while (keys.hasNext())
{
final Class keyClass = (Class) keys.next();
if (keyClass.isAssignableFrom(d))
{
final SerializeMethod od = (SerializeMethod) methods.get(keyClass);
if (knownSuperClass == null)
{
knownSuperClass = od;
}
else
{
if (comparator.isComparable
(knownSuperClass.getObjectClass(), od.getObjectClass()))
{
if (comparator.compare
(knownSuperClass.getObjectClass(), od.getObjectClass()) < 0)
{
knownSuperClass = od;
}
}
}
}
}
return knownSuperClass;
}
Looks up the SerializeMethod for the given class or null if there is no
SerializeMethod for the given class. This method searches all superclasses. |
public Object readObject(ObjectInputStream in) throws ClassNotFoundException, IOException {
final int type = in.readByte();
if (type == 0)
{
return null;
}
if (type == 1)
{
return in.readObject();
}
final Class c = (Class) in.readObject();
final SerializeMethod m = getSerializer(c);
if (m == null)
{
throw new NotSerializableException(c.getName());
}
return m.readObject(in);
}
Reads the object from the object input stream. This object selects the best
serializer to read the object.
Make sure, that you use the same configuration (library and class versions,
registered methods in the SerializerHelper) for reading as you used for writing. |
public void registerMethod(SerializeMethod method) {
this.methods.put(method.getObjectClass(), method);
}
Registers a new SerializeMethod with this SerializerHelper. |
protected static void setInstance(SerializerHelper helper) {
singleton = helper;
}
This method can be used to replace the singleton instance of this helper. |
public void unregisterMethod(SerializeMethod method) {
this.methods.remove(method.getObjectClass());
}
Deregisters a new SerializeMethod with this SerializerHelper. |
public void writeObject(Object o,
ObjectOutputStream out) throws IOException {
if (o == null)
{
out.writeByte(0);
return;
}
if (o instanceof Serializable)
{
out.writeByte(1);
out.writeObject(o);
return;
}
final SerializeMethod m = getSerializer(o.getClass());
if (m == null)
{
throw new NotSerializableException(o.getClass().getName());
}
out.writeByte(2);
out.writeObject(m.getObjectClass());
m.writeObject(o, out);
}
Writes a serializable object description to the given object output stream.
This method selects the best serialize helper method for the given object. |