Let's do this delayed marshaller initialization slightly differently, so that
only CustomClassStreamer needs to know about it. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6558 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -323,18 +323,10 @@ public abstract class Streamer
|
|||||||
{
|
{
|
||||||
/** Constructor. */
|
/** Constructor. */
|
||||||
protected ClassStreamer (Class<?> target)
|
protected ClassStreamer (Class<?> target)
|
||||||
{
|
|
||||||
this(target, true); // initialize now, we'll need them and we want to fail fast
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Constructor. */
|
|
||||||
protected ClassStreamer (Class<?> target, boolean initMarshallers)
|
|
||||||
{
|
{
|
||||||
_target = target;
|
_target = target;
|
||||||
if (initMarshallers) {
|
|
||||||
initMarshallers();
|
initMarshallers();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeObject (Object object, ObjectOutputStream out, boolean useWriter)
|
public void writeObject (Object object, ObjectOutputStream out, boolean useWriter)
|
||||||
@@ -528,10 +520,7 @@ public abstract class Streamer
|
|||||||
/** Constructor. */
|
/** Constructor. */
|
||||||
protected CustomClassStreamer (Class<?> target, Method reader, Method writer)
|
protected CustomClassStreamer (Class<?> target, Method reader, Method writer)
|
||||||
{
|
{
|
||||||
super(target, false); // we will lazy-initialize the marshallers only if needed
|
super(target);
|
||||||
// (It's possible there is only a writer method, but the object is never read
|
|
||||||
// from clients, so don't get cute and set up the marshallers now if one of the
|
|
||||||
// methods is null).
|
|
||||||
_reader = reader;
|
_reader = reader;
|
||||||
_writer = writer;
|
_writer = writer;
|
||||||
}
|
}
|
||||||
@@ -542,7 +531,7 @@ public abstract class Streamer
|
|||||||
{
|
{
|
||||||
// we need to initialize in order to access the constructor
|
// we need to initialize in order to access the constructor
|
||||||
if (_marshallers == null) {
|
if (_marshallers == null) {
|
||||||
initMarshallers();
|
super.initMarshallers();
|
||||||
}
|
}
|
||||||
return super.createObject(in);
|
return super.createObject(in);
|
||||||
}
|
}
|
||||||
@@ -575,7 +564,7 @@ public abstract class Streamer
|
|||||||
|
|
||||||
// otherwise, ensure the marshallers are initialized and call super
|
// otherwise, ensure the marshallers are initialized and call super
|
||||||
if (_marshallers == null) {
|
if (_marshallers == null) {
|
||||||
initMarshallers();
|
super.initMarshallers();
|
||||||
}
|
}
|
||||||
super.writeObject(object, out, useWriter);
|
super.writeObject(object, out, useWriter);
|
||||||
}
|
}
|
||||||
@@ -613,11 +602,19 @@ public abstract class Streamer
|
|||||||
|
|
||||||
// otherwise, ensure the marshallers are iniitalized and call super
|
// otherwise, ensure the marshallers are iniitalized and call super
|
||||||
if (_marshallers == null) {
|
if (_marshallers == null) {
|
||||||
initMarshallers();
|
super.initMarshallers();
|
||||||
}
|
}
|
||||||
super.readObject(object, in, useReader);
|
super.readObject(object, in, useReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void initMarshallers ()
|
||||||
|
{
|
||||||
|
// we will lazy-initialize the marshallers only if needed, so we don't call super
|
||||||
|
// (It's possible there is only a writer method, but the object is never read from
|
||||||
|
// clients, so don't get cute and set up the marshallers at construct time if one of
|
||||||
|
// the methods is null).
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Objects.ToStringHelper toStringHelper (Objects.ToStringHelper otsh)
|
protected Objects.ToStringHelper toStringHelper (Objects.ToStringHelper otsh)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user