Charlie's change violates the new design, which is that we figure out
how we're going to stream a class and then create the right streamer for it. Using the ClassStreamer for an interface and then not doing any of the ClassStreamer stuff means: don't use a ClassStreamer. I went in here intending to find or create a dummy Streamable streamer that all interfaces could share... But, as it turns out, non-final arrays don't need a delegate streamer, so I can just remove that and interface types will never create a Streamer. (Interfaces can never be final.) So: the problem just goes away and everything gets cleaner. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6563 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -135,18 +135,19 @@ public abstract class Streamer
|
|||||||
|
|
||||||
Streamer stream = _streamers.get(target);
|
Streamer stream = _streamers.get(target);
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
// see if it's a collection type
|
// Get or create a streamer for the class, and cache it.
|
||||||
|
// First, see if it's a collection type...
|
||||||
Class<?> collClass = getCollectionClass(target);
|
Class<?> collClass = getCollectionClass(target);
|
||||||
if (collClass != null) {
|
if (collClass != null) {
|
||||||
stream = getStreamer(collClass);
|
stream = getStreamer(collClass);
|
||||||
|
|
||||||
|
// otherwise make sure it's a streamable class
|
||||||
|
} else if (!isStreamable(target)) {
|
||||||
|
throw new IOException(
|
||||||
|
"Requested to stream invalid class '" + target.getName() + "'");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// otherwise make sure this is a streamable class
|
// create a new streamer for the class
|
||||||
if (!isStreamable(target)) {
|
|
||||||
throw new IOException(
|
|
||||||
"Requested to stream invalid class '" + target.getName() + "'");
|
|
||||||
}
|
|
||||||
// create a streamer for this class and cache it
|
|
||||||
if (ObjectInputStream.STREAM_DEBUG) {
|
if (ObjectInputStream.STREAM_DEBUG) {
|
||||||
log.info("Creating a streamer for '" + target.getName() + "'.");
|
log.info("Creating a streamer for '" + target.getName() + "'.");
|
||||||
}
|
}
|
||||||
@@ -245,18 +246,18 @@ public abstract class Streamer
|
|||||||
// create streamers for array types
|
// create streamers for array types
|
||||||
if (target.isArray()) {
|
if (target.isArray()) {
|
||||||
Class<?> componentType = target.getComponentType();
|
Class<?> componentType = target.getComponentType();
|
||||||
Streamer delegate = Streamer.getStreamer(componentType);
|
|
||||||
// sanity check
|
|
||||||
if (delegate == null) {
|
|
||||||
String errmsg = "Aiya! Streamer created for array type but we have no registered " +
|
|
||||||
"streamer for the element type [type=" + target.getName() + "]";
|
|
||||||
throw new RuntimeException(errmsg);
|
|
||||||
}
|
|
||||||
if (Modifier.isFinal(componentType.getModifiers())) {
|
if (Modifier.isFinal(componentType.getModifiers())) {
|
||||||
return new FinalArrayStreamer(componentType, delegate);
|
Streamer delegate = Streamer.getStreamer(componentType);
|
||||||
} else {
|
if (delegate != null) {
|
||||||
return new ArrayStreamer(componentType, delegate);
|
return new FinalArrayStreamer(componentType, delegate);
|
||||||
|
} // else: error, below
|
||||||
|
|
||||||
|
} else if (isStreamable(componentType)) {
|
||||||
|
return new ArrayStreamer(componentType);
|
||||||
}
|
}
|
||||||
|
String errmsg = "Aiya! Streamer created for array type but we have no registered " +
|
||||||
|
"streamer for the element type [type=" + target.getName() + "]";
|
||||||
|
throw new RuntimeException(errmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create streamers for enum types
|
// create streamers for enum types
|
||||||
@@ -325,9 +326,6 @@ public abstract class Streamer
|
|||||||
protected ClassStreamer (Class<?> target)
|
protected ClassStreamer (Class<?> target)
|
||||||
{
|
{
|
||||||
_target = target;
|
_target = target;
|
||||||
if (_target.isInterface()) {
|
|
||||||
return;// Don't try to find a constructor if we don't have one
|
|
||||||
}
|
|
||||||
initConstructor();
|
initConstructor();
|
||||||
initMarshallers();
|
initMarshallers();
|
||||||
}
|
}
|
||||||
@@ -633,10 +631,9 @@ public abstract class Streamer
|
|||||||
protected static class ArrayStreamer extends Streamer
|
protected static class ArrayStreamer extends Streamer
|
||||||
{
|
{
|
||||||
/** Constructor. */
|
/** Constructor. */
|
||||||
protected ArrayStreamer (Class<?> componentType, Streamer delegate)
|
protected ArrayStreamer (Class<?> componentType)
|
||||||
{
|
{
|
||||||
_componentType = componentType;
|
_componentType = componentType;
|
||||||
_delegate = delegate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -681,15 +678,11 @@ public abstract class Streamer
|
|||||||
protected Objects.ToStringHelper toStringHelper (Objects.ToStringHelper otsh)
|
protected Objects.ToStringHelper toStringHelper (Objects.ToStringHelper otsh)
|
||||||
{
|
{
|
||||||
return super.toStringHelper(otsh)
|
return super.toStringHelper(otsh)
|
||||||
.add("componentType", _componentType.getName())
|
.add("componentType", _componentType.getName());
|
||||||
.add("delegate", _delegate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The class of our component type. */
|
/** The class of our component type. */
|
||||||
protected Class<?> _componentType;
|
protected Class<?> _componentType;
|
||||||
|
|
||||||
/** Our delegate streamer. */
|
|
||||||
protected Streamer _delegate;
|
|
||||||
} // end: static class ArrayStreamer
|
} // end: static class ArrayStreamer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -700,7 +693,8 @@ public abstract class Streamer
|
|||||||
/** Constructor. */
|
/** Constructor. */
|
||||||
protected FinalArrayStreamer (Class<?> componentType, Streamer delegate)
|
protected FinalArrayStreamer (Class<?> componentType, Streamer delegate)
|
||||||
{
|
{
|
||||||
super(componentType, delegate);
|
super(componentType);
|
||||||
|
_delegate = delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -754,6 +748,16 @@ public abstract class Streamer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Objects.ToStringHelper toStringHelper (Objects.ToStringHelper otsh)
|
||||||
|
{
|
||||||
|
return super.toStringHelper(otsh)
|
||||||
|
.add("delegate", _delegate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Our delegate streamer. */
|
||||||
|
protected Streamer _delegate;
|
||||||
} // end: static class FinalArrayStreamer
|
} // end: static class FinalArrayStreamer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user