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;
|
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
|
* @author inder
|
||||||
*
|
*
|
||||||
|
@ -37,6 +41,7 @@ import com.google.gson.reflect.TypeToken;
|
||||||
public final class MetaData<R extends RestResource<R>> {
|
public final class MetaData<R extends RestResource<R>> {
|
||||||
|
|
||||||
private final Map<String, String> map;
|
private final Map<String, String> map;
|
||||||
|
private final transient Map<Object, Object> mapTransient;
|
||||||
|
|
||||||
public static <RS extends RestResource<RS>> MetaData<RS> create() {
|
public static <RS extends RestResource<RS>> MetaData<RS> create() {
|
||||||
return new MetaData<RS>();
|
return new MetaData<RS>();
|
||||||
|
@ -53,6 +58,7 @@ public final class MetaData<R extends RestResource<R>> {
|
||||||
|
|
||||||
private MetaData(Map<String, String> values) {
|
private MetaData(Map<String, String> values) {
|
||||||
this.map = values;
|
this.map = values;
|
||||||
|
this.mapTransient = new HashMap<Object, Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getString(String key) {
|
public String getString(String key) {
|
||||||
|
@ -76,10 +82,23 @@ public final class MetaData<R extends RestResource<R>> {
|
||||||
map.remove(key);
|
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
|
@Override
|
||||||
public String toString() {
|
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
|
* Gson Type adapter for {@link MetaData}. The serialized representation on wire is just a
|
||||||
* Map<String, String>
|
* Map<String, String>
|
||||||
|
|
|
@ -15,13 +15,10 @@
|
||||||
*/
|
*/
|
||||||
package com.google.gson.wsf.server.rest;
|
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.Id;
|
||||||
import com.google.gson.webservice.definition.rest.MetaData;
|
import com.google.gson.webservice.definition.rest.MetaData;
|
||||||
import com.google.gson.webservice.definition.rest.RestResource;
|
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
|
* An in-memory map of rest resources
|
||||||
|
|
Loading…
Reference in New Issue
Block a user