diff options
author | jfrijters <jfrijters> | 2009-07-29 13:36:56 +0400 |
---|---|---|
committer | jfrijters <jfrijters> | 2009-07-29 13:36:56 +0400 |
commit | 43fd0daf0719910095a4f3acffabe0efc85875a4 (patch) | |
tree | 080060099226afed0de23b6fdc996d6b6c470cdc /openjdk | |
parent | 03892b621b949b016e034415ccd18f0e95e3f330 (diff) |
Implemented support for .NET serialization of Java enums.
(The CreateEnumEnum move in FakeTypes.cs is because java.lang.Enum now has a dependency on custom attribute annotations.)
Diffstat (limited to 'openjdk')
-rw-r--r-- | openjdk/java/lang/Enum.java | 35 | ||||
-rw-r--r-- | openjdk/map.xml | 3 |
2 files changed, 38 insertions, 0 deletions
diff --git a/openjdk/java/lang/Enum.java b/openjdk/java/lang/Enum.java index 175b4021..e14a2884 100644 --- a/openjdk/java/lang/Enum.java +++ b/openjdk/java/lang/Enum.java @@ -30,6 +30,10 @@ import java.io.IOException; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.ObjectStreamException; +import cli.System.Runtime.Serialization.IObjectReference; +import cli.System.Runtime.Serialization.SerializationException; +import cli.System.Runtime.Serialization.SerializationInfo; +import cli.System.Runtime.Serialization.StreamingContext; /** * This is the common base class of all Java language enumeration types. @@ -39,6 +43,7 @@ import java.io.ObjectStreamException; * @see Class#getEnumConstants() * @since 1.5 */ +@cli.System.SerializableAttribute.Annotation public abstract class Enum<E extends Enum<E>> implements Comparable<E>, Serializable { /** @@ -231,4 +236,34 @@ public abstract class Enum<E extends Enum<E>> private void readObjectNoData() throws ObjectStreamException { throw new InvalidObjectException("can't deserialize enum"); } + + // [IKVM] .NET serialization support starts here + // Note that we don't have a security demand, because the info is harmless. + @cli.IKVM.Attributes.HideFromJavaAttribute.Annotation + public final void GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("enumType", getDeclaringClass()); + info.AddValue("name", name); + info.SetType(ikvm.runtime.Util.getInstanceTypeFromClass(EnumSerializationProxy.class)); + } +} + +@cli.System.SerializableAttribute.Annotation +final class EnumSerializationProxy implements IObjectReference +{ + private Class enumType; + private String name; + + public Object GetRealObject(StreamingContext context) + { + try + { + return Enum.valueOf(enumType, name); + } + catch (IllegalArgumentException x) + { + ikvm.runtime.Util.throwException(new SerializationException("Enum value " + name + " not found in " + enumType, x)); + return null; + } + } } diff --git a/openjdk/map.xml b/openjdk/map.xml index 48b5df8a..e2882c6f 100644 --- a/openjdk/map.xml +++ b/openjdk/map.xml @@ -1364,6 +1364,9 @@ </body> </method> </class> + <class name="java.lang.Enum"> + <implements class="cli.System.Runtime.Serialization.ISerializable" /> + </class> <class name="java.lang.Thread"> <field name="parkLock" sig="Ljava.lang.Object;" modifiers="" /> <field name="parkState" sig="I" modifiers="" /> |