diff options
Diffstat (limited to 'guava-gwt/src/com/google/common/collect/ImmutableAsList_CustomFieldSerializer.java')
-rw-r--r-- | guava-gwt/src/com/google/common/collect/ImmutableAsList_CustomFieldSerializer.java | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/guava-gwt/src/com/google/common/collect/ImmutableAsList_CustomFieldSerializer.java b/guava-gwt/src/com/google/common/collect/ImmutableAsList_CustomFieldSerializer.java index 7466c22..4cb55ee 100644 --- a/guava-gwt/src/com/google/common/collect/ImmutableAsList_CustomFieldSerializer.java +++ b/guava-gwt/src/com/google/common/collect/ImmutableAsList_CustomFieldSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 The Guava Authors + * Copyright (C) 2010 The Guava Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,40 @@ package com.google.common.collect; +import com.google.common.annotations.GwtCompatible; +import com.google.gwt.user.client.rpc.SerializationException; +import com.google.gwt.user.client.rpc.SerializationStreamReader; +import com.google.gwt.user.client.rpc.SerializationStreamWriter; +import com.google.gwt.user.client.rpc.core.java.util.Collection_CustomFieldSerializerBase; + +import java.util.ArrayList; +import java.util.List; + /** - * Even though {@link ImmutableAsList} cannot be instantiated, we still need - * a custom field serializer. TODO(cpovirk): why? + * This class implements the server-side GWT serialization of + * {@link ImmutableAsList}. * * @author Hayward Chan */ -public final class ImmutableAsList_CustomFieldSerializer {} +@GwtCompatible(emulated = true) +public class ImmutableAsList_CustomFieldSerializer { + + public static void deserialize(SerializationStreamReader reader, + ImmutableAsList<?> instance) { + } + + public static ImmutableAsList<Object> instantiate( + SerializationStreamReader reader) throws SerializationException { + List<Object> elements = new ArrayList<Object>(); + Collection_CustomFieldSerializerBase.deserialize(reader, elements); + ImmutableList<Object> asImmutableList = ImmutableList.copyOf(elements); + return new ImmutableAsList<Object>( + asImmutableList.toArray(new Object[asImmutableList.size()]), + asImmutableList); + } + + public static void serialize(SerializationStreamWriter writer, + ImmutableAsList<?> instance) throws SerializationException { + Collection_CustomFieldSerializerBase.serialize(writer, instance); + } +} |