From 7a1a162a0df9ec7752ad4214add75891ea303e6b Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 17 Jul 2002 23:05:28 +0000 Subject: [PATCH] Changed field marshaller registration to be compatible with DashO-style field renaming. I'm a bad monkey for overusing reflection. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1587 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/presents/io/BooleanFieldMarshaller.java | 9 ++++++--- .../threerings/presents/io/ByteArrayFieldMarshaller.java | 9 ++++++--- .../com/threerings/presents/io/ByteFieldMarshaller.java | 9 ++++++--- .../com/threerings/presents/io/DSetFieldMarshaller.java | 9 ++++++--- .../threerings/presents/io/DoubleFieldMarshaller.java | 9 ++++++--- src/java/com/threerings/presents/io/FieldMarshaller.java | 4 +++- .../threerings/presents/io/FieldMarshallerRegistry.java | 6 +++--- .../com/threerings/presents/io/FloatFieldMarshaller.java | 9 ++++++--- .../threerings/presents/io/IntArrayFieldMarshaller.java | 9 ++++++--- .../com/threerings/presents/io/IntFieldMarshaller.java | 9 ++++++--- .../threerings/presents/io/IntegerFieldMarshaller.java | 9 ++++++--- .../com/threerings/presents/io/LongFieldMarshaller.java | 9 ++++++--- .../threerings/presents/io/OidListFieldMarshaller.java | 9 ++++++--- .../com/threerings/presents/io/ShortFieldMarshaller.java | 9 ++++++--- .../presents/io/StreamableArrayFieldMarshaller.java | 8 +++++++- .../presents/io/StreamableFieldMarshaller.java | 8 +++++++- .../presents/io/StringArrayFieldMarshaller.java | 9 ++++++--- .../threerings/presents/io/StringFieldMarshaller.java | 9 ++++++--- 18 files changed, 104 insertions(+), 48 deletions(-) diff --git a/src/java/com/threerings/presents/io/BooleanFieldMarshaller.java b/src/java/com/threerings/presents/io/BooleanFieldMarshaller.java index ba484b8f7..6c0911524 100644 --- a/src/java/com/threerings/presents/io/BooleanFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/BooleanFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: BooleanFieldMarshaller.java,v 1.6 2002/02/01 23:32:37 mdb Exp $ +// $Id: BooleanFieldMarshaller.java,v 1.7 2002/07/17 23:05:27 mdb Exp $ package com.threerings.presents.io; @@ -10,8 +10,11 @@ import java.lang.reflect.Field; public class BooleanFieldMarshaller implements FieldMarshaller { - /** This is the sort of field that we marshall. */ - public boolean prototype; + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return Boolean.TYPE; + } public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException diff --git a/src/java/com/threerings/presents/io/ByteArrayFieldMarshaller.java b/src/java/com/threerings/presents/io/ByteArrayFieldMarshaller.java index 894d9a410..ec2797fd8 100644 --- a/src/java/com/threerings/presents/io/ByteArrayFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/ByteArrayFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: ByteArrayFieldMarshaller.java,v 1.1 2002/02/07 05:27:07 mdb Exp $ +// $Id: ByteArrayFieldMarshaller.java,v 1.2 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -11,8 +11,11 @@ import java.lang.reflect.Field; public class ByteArrayFieldMarshaller implements FieldMarshaller { - /** This is the sort of field that we marshall. */ - public byte[] prototype; + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return (new byte[0]).getClass(); + } public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException diff --git a/src/java/com/threerings/presents/io/ByteFieldMarshaller.java b/src/java/com/threerings/presents/io/ByteFieldMarshaller.java index 68d09f3d6..c9a5c2e9a 100644 --- a/src/java/com/threerings/presents/io/ByteFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/ByteFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: ByteFieldMarshaller.java,v 1.1 2002/02/03 06:06:10 shaper Exp $ +// $Id: ByteFieldMarshaller.java,v 1.2 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -10,8 +10,11 @@ import java.lang.reflect.Field; public class ByteFieldMarshaller implements FieldMarshaller { - /** This is the sort of field that we marshall. */ - public byte prototype; + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return Byte.TYPE; + } public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException diff --git a/src/java/com/threerings/presents/io/DSetFieldMarshaller.java b/src/java/com/threerings/presents/io/DSetFieldMarshaller.java index 576b8b7dc..be209cd90 100644 --- a/src/java/com/threerings/presents/io/DSetFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/DSetFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: DSetFieldMarshaller.java,v 1.4 2002/02/01 23:32:37 mdb Exp $ +// $Id: DSetFieldMarshaller.java,v 1.5 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -12,8 +12,11 @@ import com.threerings.presents.dobj.DSet; public class DSetFieldMarshaller implements FieldMarshaller { - /** This is the sort of field that we marshall. */ - public DSet prototype; + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return DSet.class; + } public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException diff --git a/src/java/com/threerings/presents/io/DoubleFieldMarshaller.java b/src/java/com/threerings/presents/io/DoubleFieldMarshaller.java index 239eb5a23..2d42b2568 100644 --- a/src/java/com/threerings/presents/io/DoubleFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/DoubleFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: DoubleFieldMarshaller.java,v 1.6 2002/02/01 23:32:37 mdb Exp $ +// $Id: DoubleFieldMarshaller.java,v 1.7 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -10,8 +10,11 @@ import java.lang.reflect.Field; public class DoubleFieldMarshaller implements FieldMarshaller { - /** This is the sort of field that we marshall. */ - public double prototype; + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return Double.TYPE; + } public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException diff --git a/src/java/com/threerings/presents/io/FieldMarshaller.java b/src/java/com/threerings/presents/io/FieldMarshaller.java index c5601c83d..442466ef4 100644 --- a/src/java/com/threerings/presents/io/FieldMarshaller.java +++ b/src/java/com/threerings/presents/io/FieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: FieldMarshaller.java,v 1.6 2002/02/01 23:32:37 mdb Exp $ +// $Id: FieldMarshaller.java,v 1.7 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -15,6 +15,8 @@ import java.lang.reflect.Field; */ public interface FieldMarshaller { + public Class getFieldType (); + public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException; diff --git a/src/java/com/threerings/presents/io/FieldMarshallerRegistry.java b/src/java/com/threerings/presents/io/FieldMarshallerRegistry.java index 4a4fa1056..2a8ff990b 100644 --- a/src/java/com/threerings/presents/io/FieldMarshallerRegistry.java +++ b/src/java/com/threerings/presents/io/FieldMarshallerRegistry.java @@ -1,5 +1,5 @@ // -// $Id: FieldMarshallerRegistry.java,v 1.15 2002/04/17 22:45:32 mdb Exp $ +// $Id: FieldMarshallerRegistry.java,v 1.16 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -62,8 +62,8 @@ public class FieldMarshallerRegistry protected static void registerMarshaller (Class clazz) { try { - _registry.put(clazz.getField("prototype").getType(), - clazz.newInstance()); + FieldMarshaller fm = (FieldMarshaller)clazz.newInstance(); + _registry.put(fm.getFieldType(), fm); } catch (Exception e) { Log.warning("Unable to register field marshaller " + "[class=" + clazz.getName() + "]."); diff --git a/src/java/com/threerings/presents/io/FloatFieldMarshaller.java b/src/java/com/threerings/presents/io/FloatFieldMarshaller.java index 581cfdd3a..2c7896160 100644 --- a/src/java/com/threerings/presents/io/FloatFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/FloatFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: FloatFieldMarshaller.java,v 1.6 2002/02/01 23:32:37 mdb Exp $ +// $Id: FloatFieldMarshaller.java,v 1.7 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -10,8 +10,11 @@ import java.lang.reflect.Field; public class FloatFieldMarshaller implements FieldMarshaller { - /** This is the sort of field that we marshall. */ - public float prototype; + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return Float.TYPE; + } public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException diff --git a/src/java/com/threerings/presents/io/IntArrayFieldMarshaller.java b/src/java/com/threerings/presents/io/IntArrayFieldMarshaller.java index 8f197e9df..cd61a4c5b 100644 --- a/src/java/com/threerings/presents/io/IntArrayFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/IntArrayFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: IntArrayFieldMarshaller.java,v 1.3 2002/02/01 23:32:37 mdb Exp $ +// $Id: IntArrayFieldMarshaller.java,v 1.4 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -10,8 +10,11 @@ import java.lang.reflect.Field; public class IntArrayFieldMarshaller implements FieldMarshaller { - /** This is the sort of field that we marshall. */ - public int[] prototype; + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return (new int[0]).getClass(); + } public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException diff --git a/src/java/com/threerings/presents/io/IntFieldMarshaller.java b/src/java/com/threerings/presents/io/IntFieldMarshaller.java index 202817c13..e91e4da1d 100644 --- a/src/java/com/threerings/presents/io/IntFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/IntFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: IntFieldMarshaller.java,v 1.6 2002/02/01 23:32:37 mdb Exp $ +// $Id: IntFieldMarshaller.java,v 1.7 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -10,8 +10,11 @@ import java.lang.reflect.Field; public class IntFieldMarshaller implements FieldMarshaller { - /** This is the sort of field that we marshall. */ - public int prototype; + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return Integer.TYPE; + } public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException diff --git a/src/java/com/threerings/presents/io/IntegerFieldMarshaller.java b/src/java/com/threerings/presents/io/IntegerFieldMarshaller.java index 8b50c1b4a..bc6858b1e 100644 --- a/src/java/com/threerings/presents/io/IntegerFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/IntegerFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: IntegerFieldMarshaller.java,v 1.1 2002/04/17 22:45:32 mdb Exp $ +// $Id: IntegerFieldMarshaller.java,v 1.2 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -10,8 +10,11 @@ import java.lang.reflect.Field; public class IntegerFieldMarshaller implements FieldMarshaller { - /** This is the sort of field that we marshall. */ - public Integer prototype; + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return Integer.class; + } public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException diff --git a/src/java/com/threerings/presents/io/LongFieldMarshaller.java b/src/java/com/threerings/presents/io/LongFieldMarshaller.java index 68cdd2f65..e1b861753 100644 --- a/src/java/com/threerings/presents/io/LongFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/LongFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: LongFieldMarshaller.java,v 1.6 2002/02/01 23:32:37 mdb Exp $ +// $Id: LongFieldMarshaller.java,v 1.7 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -10,8 +10,11 @@ import java.lang.reflect.Field; public class LongFieldMarshaller implements FieldMarshaller { - /** This is the sort of field that we marshall. */ - public long prototype; + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return Long.TYPE; + } public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException diff --git a/src/java/com/threerings/presents/io/OidListFieldMarshaller.java b/src/java/com/threerings/presents/io/OidListFieldMarshaller.java index 799379042..4139ab9ba 100644 --- a/src/java/com/threerings/presents/io/OidListFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/OidListFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: OidListFieldMarshaller.java,v 1.4 2002/02/01 23:32:37 mdb Exp $ +// $Id: OidListFieldMarshaller.java,v 1.5 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -12,8 +12,11 @@ import com.threerings.presents.dobj.OidList; public class OidListFieldMarshaller implements FieldMarshaller { - /** This is the sort of field that we marshall. */ - public OidList prototype; + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return OidList.class; + } public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException diff --git a/src/java/com/threerings/presents/io/ShortFieldMarshaller.java b/src/java/com/threerings/presents/io/ShortFieldMarshaller.java index eb5a66f97..3317ef10d 100644 --- a/src/java/com/threerings/presents/io/ShortFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/ShortFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: ShortFieldMarshaller.java,v 1.6 2002/02/01 23:32:37 mdb Exp $ +// $Id: ShortFieldMarshaller.java,v 1.7 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -10,8 +10,11 @@ import java.lang.reflect.Field; public class ShortFieldMarshaller implements FieldMarshaller { - /** This is the sort of field that we marshall. */ - public short prototype; + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return Short.TYPE; + } public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException diff --git a/src/java/com/threerings/presents/io/StreamableArrayFieldMarshaller.java b/src/java/com/threerings/presents/io/StreamableArrayFieldMarshaller.java index 3f10190c0..900b6b7a0 100644 --- a/src/java/com/threerings/presents/io/StreamableArrayFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/StreamableArrayFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: StreamableArrayFieldMarshaller.java,v 1.1 2002/03/20 22:58:26 mdb Exp $ +// $Id: StreamableArrayFieldMarshaller.java,v 1.2 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -14,6 +14,12 @@ import com.threerings.presents.io.Streamable; public class StreamableArrayFieldMarshaller implements FieldMarshaller { + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return (new Streamable[0]).getClass(); + } + public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException { diff --git a/src/java/com/threerings/presents/io/StreamableFieldMarshaller.java b/src/java/com/threerings/presents/io/StreamableFieldMarshaller.java index 6ee3b6b83..39fd8ff00 100644 --- a/src/java/com/threerings/presents/io/StreamableFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/StreamableFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: StreamableFieldMarshaller.java,v 1.5 2002/03/06 23:45:01 mdb Exp $ +// $Id: StreamableFieldMarshaller.java,v 1.6 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -15,6 +15,12 @@ import com.threerings.presents.io.Streamable; public class StreamableFieldMarshaller implements FieldMarshaller { + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return Streamable.class; + } + public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException { diff --git a/src/java/com/threerings/presents/io/StringArrayFieldMarshaller.java b/src/java/com/threerings/presents/io/StringArrayFieldMarshaller.java index bb10759bd..056e56841 100644 --- a/src/java/com/threerings/presents/io/StringArrayFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/StringArrayFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: StringArrayFieldMarshaller.java,v 1.4 2002/02/01 23:32:37 mdb Exp $ +// $Id: StringArrayFieldMarshaller.java,v 1.5 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -10,8 +10,11 @@ import java.lang.reflect.Field; public class StringArrayFieldMarshaller implements FieldMarshaller { - /** This is the sort of field that we marshall. */ - public String[] prototype; + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return (new String[0]).getClass(); + } public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException diff --git a/src/java/com/threerings/presents/io/StringFieldMarshaller.java b/src/java/com/threerings/presents/io/StringFieldMarshaller.java index 476e90fcf..de11fad79 100644 --- a/src/java/com/threerings/presents/io/StringFieldMarshaller.java +++ b/src/java/com/threerings/presents/io/StringFieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: StringFieldMarshaller.java,v 1.7 2002/02/01 23:32:37 mdb Exp $ +// $Id: StringFieldMarshaller.java,v 1.8 2002/07/17 23:05:28 mdb Exp $ package com.threerings.presents.io; @@ -10,8 +10,11 @@ import java.lang.reflect.Field; public class StringFieldMarshaller implements FieldMarshaller { - /** This is the sort of field that we marshall. */ - public String prototype; + /** Returns the sort of field that we marshall. */ + public Class getFieldType () + { + return String.class; + } public void writeTo (DataOutputStream out, Field field, Object obj) throws IOException, IllegalAccessException