From 61810baf638c3ba9564f01f6c80fc09d429a128d Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 22 Jan 2008 01:58:06 +0000 Subject: Filter and FilterValues are now Serializable. --- .../com/amazon/carbonado/info/ChainedProperty.java | 9 ++++- .../carbonado/info/StorableIntrospector.java | 39 ++++++++++++++++++++++ .../amazon/carbonado/info/StorableProperty.java | 3 +- 3 files changed, 49 insertions(+), 2 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/info') diff --git a/src/main/java/com/amazon/carbonado/info/ChainedProperty.java b/src/main/java/com/amazon/carbonado/info/ChainedProperty.java index 71f1ba5..d30fc8f 100644 --- a/src/main/java/com/amazon/carbonado/info/ChainedProperty.java +++ b/src/main/java/com/amazon/carbonado/info/ChainedProperty.java @@ -19,6 +19,7 @@ package com.amazon.carbonado.info; import java.io.IOException; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -36,7 +37,9 @@ import com.amazon.carbonado.util.Appender; * * @author Brian S O'Neill */ -public class ChainedProperty implements Appender { +public class ChainedProperty implements Serializable, Appender { + private static final long serialVersionUID = 1L; + static WeakCanonicalSet cCanonical = new WeakCanonicalSet(); /** @@ -578,4 +581,8 @@ public class ChainedProperty implements Appender { app.append(')'); } } + + private Object readResolve() { + return cCanonical.put(this); + } } diff --git a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java index 7e8fbf8..fdfb51f 100644 --- a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java +++ b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java @@ -18,7 +18,10 @@ package com.amazon.carbonado.info; +import java.io.Externalizable; import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.lang.annotation.Annotation; import java.lang.ref.Reference; import java.lang.ref.SoftReference; @@ -2080,6 +2083,42 @@ public class StorableIntrospector { return derivedToSet.size() > originalSize; } + + // Package-private in order to be inherited by subclasses. + Object writeReplace() { + return new NaET(mName, mEnclosingType); + } + + // Name and Enclosing Type + private static class NaET implements Externalizable { + private static final long serialVersionUID = 1L; + + private String mName; + private Class mEnclosingType; + + // Required for Externalizable. + public NaET() { + } + + NaET(String name, Class enclosingType) { + mName = name; + mEnclosingType = enclosingType; + } + + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(mName); + out.writeObject(mEnclosingType); + } + + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + mName = (String) in.readObject(); + mEnclosingType = (Class) in.readObject(); + } + + private Object readResolve() { + return StorableIntrospector.examine(mEnclosingType).getAllProperties().get(mName); + } + } } private static final class JoinProperty extends SimpleProperty { diff --git a/src/main/java/com/amazon/carbonado/info/StorableProperty.java b/src/main/java/com/amazon/carbonado/info/StorableProperty.java index 53b5098..0d77481 100644 --- a/src/main/java/com/amazon/carbonado/info/StorableProperty.java +++ b/src/main/java/com/amazon/carbonado/info/StorableProperty.java @@ -18,6 +18,7 @@ package com.amazon.carbonado.info; +import java.io.Serializable; import java.lang.reflect.Method; import com.amazon.carbonado.Storable; import com.amazon.carbonado.util.Appender; @@ -28,7 +29,7 @@ import com.amazon.carbonado.util.Appender; * @author Brian S O'Neill * @see StorableIntrospector */ -public interface StorableProperty extends Appender { +public interface StorableProperty extends Serializable, Appender { /** * Returns the name of this property. */ -- cgit v1.2.3