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.
This commit is contained in:
parent
1d2648231f
commit
6d9893ddf3
@ -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<R extends RestResource<R>> {
|
||||
|
||||
private final Map<String, String> map;
|
||||
private final transient Map<Object, Object> mapTransient;
|
||||
|
||||
public static <RS extends RestResource<RS>> MetaData<RS> create() {
|
||||
return new MetaData<RS>();
|
||||
@ -53,6 +58,7 @@ public final class MetaData<R extends RestResource<R>> {
|
||||
|
||||
private MetaData(Map<String, String> values) {
|
||||
this.map = values;
|
||||
this.mapTransient = new HashMap<Object, Object>();
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
@ -76,10 +82,23 @@ public final class MetaData<R extends RestResource<R>> {
|
||||
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<String, String>
|
||||
@ -102,4 +121,4 @@ public final class MetaData<R extends RestResource<R>> {
|
||||
return context.serialize(src.map, MAP_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user