From 1925fb966cb54913709ff4c88dfdb0a849d2d9bd Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Mon, 15 Feb 2010 14:46:42 +0000 Subject: [PATCH] Introduced the notion of TypedKey for a parameter map or spec --- .../gson/webservice/definition/HeaderMap.java | 4 ++++ .../gson/webservice/definition/ParamMap.java | 4 ++++ .../gson/webservice/definition/TypedKey.java | 19 +++++++++++++++++++ .../definition/WebServiceCallSpec.java | 19 +++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 wsdef/src/main/java/com/google/gson/webservice/definition/TypedKey.java diff --git a/wsdef/src/main/java/com/google/gson/webservice/definition/HeaderMap.java b/wsdef/src/main/java/com/google/gson/webservice/definition/HeaderMap.java index f8294492..f8b983a5 100644 --- a/wsdef/src/main/java/com/google/gson/webservice/definition/HeaderMap.java +++ b/wsdef/src/main/java/com/google/gson/webservice/definition/HeaderMap.java @@ -30,6 +30,10 @@ public final class HeaderMap extends ParamMap { public Builder(HeaderMapSpec spec) { super(spec); } + + public Builder put(TypedKey paramKey, T content) { + return put(paramKey.getName(), content); + } @Override public Builder put(String paramName, Object content) { diff --git a/wsdef/src/main/java/com/google/gson/webservice/definition/ParamMap.java b/wsdef/src/main/java/com/google/gson/webservice/definition/ParamMap.java index d4b0c2fe..459d302f 100644 --- a/wsdef/src/main/java/com/google/gson/webservice/definition/ParamMap.java +++ b/wsdef/src/main/java/com/google/gson/webservice/definition/ParamMap.java @@ -63,6 +63,10 @@ class ParamMap { return contents.get(paramName); } + public T get(TypedKey key) { + return get(key.getName(), key.getClassOfT()); + } + @SuppressWarnings("unchecked") public T get(String key, Type typeOfValue) { Preconditions.checkArgument(spec.checkIfCompatible(key, typeOfValue)); diff --git a/wsdef/src/main/java/com/google/gson/webservice/definition/TypedKey.java b/wsdef/src/main/java/com/google/gson/webservice/definition/TypedKey.java new file mode 100644 index 00000000..1f61acc5 --- /dev/null +++ b/wsdef/src/main/java/com/google/gson/webservice/definition/TypedKey.java @@ -0,0 +1,19 @@ +package com.google.gson.webservice.definition; + +public class TypedKey { + private final String name; + private final Class classOfT; + + public TypedKey(String name, Class classOfT) { + this.name = name; + this.classOfT = classOfT; + } + + public String getName() { + return name; + } + + public Class getClassOfT() { + return classOfT; + } +} diff --git a/wsdef/src/main/java/com/google/gson/webservice/definition/WebServiceCallSpec.java b/wsdef/src/main/java/com/google/gson/webservice/definition/WebServiceCallSpec.java index bbfd5b31..2e886c21 100644 --- a/wsdef/src/main/java/com/google/gson/webservice/definition/WebServiceCallSpec.java +++ b/wsdef/src/main/java/com/google/gson/webservice/definition/WebServiceCallSpec.java @@ -55,18 +55,37 @@ public final class WebServiceCallSpec { return this; } + public Builder addRequestParam(TypedKey paramKey, Class typeOfParam) { + return addRequestParam(paramKey.getName(), typeOfParam); + } + public Builder addRequestParam(String paramName, Type type) { reqParamsSpecBuilder.put(paramName, type); return this; } + + public Builder addRequestBodyParam(TypedKey paramKey, Class typeOfParam) { + return addRequestBodyParam(paramKey.getName(), typeOfParam); + } + public Builder addRequestBodyParam(String paramName, Type type) { reqBodySpecBuilder.add(paramName, type); return this; } + + public Builder addResponseParam(TypedKey paramKey, Class typeOfParam) { + return addResponseParam(paramKey.getName(), typeOfParam); + } + public Builder addResponseParam(String paramName, Type type) { resParamsSpecBuilder.put(paramName, type); return this; } + + public Builder addResponseBodyParam(TypedKey paramKey, Class typeOfParam) { + return addResponseBodyParam(paramKey.getName(), typeOfParam); + } + public Builder addResponseBodyParam(String paramName, Type type) { resBodySpecBuilder.add(paramName, type); return this;