From 6d9893ddf3653f58eaae0f556f30a7830207a8fa Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Sat, 23 Oct 2010 15:45:33 +0000 Subject: [PATCH] Added a transient map in Metadata since metadata is often of two kinds: transient and persistent. persistent part is serialized/deserialized to JSON. Fixed imports in RepositoryInMemory. --- .../webservice/definition/rest/MetaData.java | 25 ++++++++++++++++--- .../wsf/server/rest/RepositoryInMemory.java | 5 +--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/wsdef/src/main/java/com/google/gson/webservice/definition/rest/MetaData.java b/wsdef/src/main/java/com/google/gson/webservice/definition/rest/MetaData.java index cb39e9ee..bfea6392 100644 --- a/wsdef/src/main/java/com/google/gson/webservice/definition/rest/MetaData.java +++ b/wsdef/src/main/java/com/google/gson/webservice/definition/rest/MetaData.java @@ -28,7 +28,11 @@ import com.google.gson.JsonSerializer; import com.google.gson.reflect.TypeToken; /** - * Metadata associated with a repository for a rest resource + * Metadata associated with a repository for a rest resource. Metadata is of two types: persistent + * and transient. All metadata is persistent by default, and must be a name-value pair of strings. + * Transient metadata can be an arbitrary key-value pair of objects and is available through + * {@link #getFromTransient(Object)}, {@link #putInTransient(Object, Object)}, + * and {@link #removeFromTransient(Object)} methods. * * @author inder * @@ -37,6 +41,7 @@ import com.google.gson.reflect.TypeToken; public final class MetaData> { private final Map map; + private final transient Map mapTransient; public static > MetaData create() { return new MetaData(); @@ -53,6 +58,7 @@ public final class MetaData> { private MetaData(Map values) { this.map = values; + this.mapTransient = new HashMap(); } public String getString(String key) { @@ -76,10 +82,23 @@ public final class MetaData> { map.remove(key); } + public Object getFromTransient(Object key) { + return (String) mapTransient.get(key); + } + + public void putInTransient(Object key, Object value) { + mapTransient.put(key, value); + } + + public void removeFromTransient(Object key) { + mapTransient.remove(key); + } + @Override public String toString() { - return String.format("%s", map); + return String.format("map:%s, mapTransient:%s", map, mapTransient); } + /** * Gson Type adapter for {@link MetaData}. The serialized representation on wire is just a * Map @@ -102,4 +121,4 @@ public final class MetaData> { return context.serialize(src.map, MAP_TYPE); } } -} \ No newline at end of file +} diff --git a/wsf/src/main/java/com/google/gson/wsf/server/rest/RepositoryInMemory.java b/wsf/src/main/java/com/google/gson/wsf/server/rest/RepositoryInMemory.java index 76914a97..b271efff 100644 --- a/wsf/src/main/java/com/google/gson/wsf/server/rest/RepositoryInMemory.java +++ b/wsf/src/main/java/com/google/gson/wsf/server/rest/RepositoryInMemory.java @@ -15,13 +15,10 @@ */ package com.google.gson.wsf.server.rest; -import java.util.Map; - +import com.google.common.base.Preconditions; import com.google.gson.webservice.definition.rest.Id; import com.google.gson.webservice.definition.rest.MetaData; import com.google.gson.webservice.definition.rest.RestResource; -import com.google.inject.internal.Maps; -import com.google.inject.internal.Preconditions; /** * An in-memory map of rest resources