Removed dependence on Guice and Collections from wsclient.
Renamed Builder.create() methods to Builder.build()
This commit is contained in:
parent
2bcc832ade
commit
51efca8457
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Google Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.google.gson.webservice.client;
|
||||||
|
|
||||||
|
final class Preconditions {
|
||||||
|
|
||||||
|
public static void checkArgument(boolean condition) {
|
||||||
|
if (!condition) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkNotNull(Object obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,7 +23,6 @@ import java.lang.reflect.Type;
|
|||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.webservice.definition.HeaderMap;
|
import com.google.gson.webservice.definition.HeaderMap;
|
||||||
import com.google.gson.webservice.definition.HeaderMapSpec;
|
import com.google.gson.webservice.definition.HeaderMapSpec;
|
||||||
@ -70,13 +69,13 @@ public final class ResponseReceiver {
|
|||||||
paramsBuilder.put(paramName, value, typeOfT);
|
paramsBuilder.put(paramName, value, typeOfT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return paramsBuilder.create();
|
return paramsBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseBody readResponseBody(HttpURLConnection conn, ResponseBodySpec bodySpec)
|
private ResponseBody readResponseBody(HttpURLConnection conn, ResponseBodySpec bodySpec)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (bodySpec.size() == 0) {
|
if (bodySpec.size() == 0) {
|
||||||
return new ResponseBody.Builder(bodySpec).create();
|
return new ResponseBody.Builder(bodySpec).build();
|
||||||
}
|
}
|
||||||
String connContentType = conn.getContentType();
|
String connContentType = conn.getContentType();
|
||||||
Preconditions.checkArgument(connContentType.contains(bodySpec.getContentType()));
|
Preconditions.checkArgument(connContentType.contains(bodySpec.getContentType()));
|
||||||
|
@ -39,7 +39,7 @@ public final class CallPathMap<T> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CallPathMap<T> create() {
|
public CallPathMap<T> build() {
|
||||||
return new CallPathMap<T>(contents, nullValue);
|
return new CallPathMap<T>(contents, nullValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public final class HeaderMap extends ParamMap {
|
|||||||
return (Builder) super.put(paramName, content, typeOfContent);
|
return (Builder) super.put(paramName, content, typeOfContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HeaderMap create() {
|
public HeaderMap build() {
|
||||||
return new HeaderMap(spec, contents);
|
return new HeaderMap(spec, contents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ public final class HeaderMapSpec implements ParamMapSpec {
|
|||||||
map.put(headerName, headerType);
|
map.put(headerName, headerType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HeaderMapSpec create() {
|
public HeaderMapSpec build() {
|
||||||
return new HeaderMapSpec(map);
|
return new HeaderMapSpec(map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ public final class RequestBody extends ContentBody {
|
|||||||
return (Builder) super.put(paramName, content, typeOfContent);
|
return (Builder) super.put(paramName, content, typeOfContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestBody create() {
|
public RequestBody build() {
|
||||||
return new RequestBody(spec, contents);
|
return new RequestBody(spec, contents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public final class RequestBodySpec extends ContentBodySpec {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestBodySpec create() {
|
public RequestBodySpec build() {
|
||||||
RequestBodySpec spec = new RequestBodySpec(paramsSpec);
|
RequestBodySpec spec = new RequestBodySpec(paramsSpec);
|
||||||
return spec;
|
return spec;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public final class ResponseBody extends ContentBody {
|
|||||||
return (Builder) super.put(paramName, content, typeOfContent);
|
return (Builder) super.put(paramName, content, typeOfContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResponseBody create() {
|
public ResponseBody build() {
|
||||||
return new ResponseBody(spec, contents);
|
return new ResponseBody(spec, contents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public final class ResponseBodySpec extends ContentBodySpec {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResponseBodySpec create() {
|
public ResponseBodySpec build() {
|
||||||
ResponseBodySpec spec = new ResponseBodySpec(paramsSpec);
|
ResponseBodySpec spec = new ResponseBodySpec(paramsSpec);
|
||||||
return spec;
|
return spec;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public final class WebServiceCallSpec {
|
public final class WebServiceCallSpec {
|
||||||
|
|
||||||
public static final WebServiceCallSpec NULL_SPEC = new Builder(new CallPath("")).create();
|
public static final WebServiceCallSpec NULL_SPEC = new Builder(new CallPath("")).build();
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private final CallPath callPath;
|
private final CallPath callPath;
|
||||||
@ -71,14 +71,14 @@ public final class WebServiceCallSpec {
|
|||||||
resBodySpecBuilder.add(paramName, type);
|
resBodySpecBuilder.add(paramName, type);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public WebServiceCallSpec create() {
|
public WebServiceCallSpec build() {
|
||||||
if (supportedHttpMethods.isEmpty()) {
|
if (supportedHttpMethods.isEmpty()) {
|
||||||
supportedHttpMethods.addAll(Arrays.asList(HttpMethod.values()));
|
supportedHttpMethods.addAll(Arrays.asList(HttpMethod.values()));
|
||||||
}
|
}
|
||||||
RequestSpec requestSpec =
|
RequestSpec requestSpec =
|
||||||
new RequestSpec(reqParamsSpecBuilder.create(), reqBodySpecBuilder.create());
|
new RequestSpec(reqParamsSpecBuilder.build(), reqBodySpecBuilder.build());
|
||||||
ResponseSpec responseSpec =
|
ResponseSpec responseSpec =
|
||||||
new ResponseSpec(resParamsSpecBuilder.create(), resBodySpecBuilder.create());
|
new ResponseSpec(resParamsSpecBuilder.build(), resBodySpecBuilder.build());
|
||||||
WebServiceCallSpec callSpec = new WebServiceCallSpec(supportedHttpMethods, callPath,
|
WebServiceCallSpec callSpec = new WebServiceCallSpec(supportedHttpMethods, callPath,
|
||||||
requestSpec, responseSpec);
|
requestSpec, responseSpec);
|
||||||
return callSpec;
|
return callSpec;
|
||||||
|
@ -60,8 +60,8 @@ public final class WebServiceResponse {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebServiceResponse create() {
|
public WebServiceResponse build() {
|
||||||
return new WebServiceResponse(spec, headers.create(), body.create());
|
return new WebServiceResponse(spec, headers.build(), body.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,11 +66,11 @@ public class RequestBodyGsonConverter implements JsonSerializer<RequestBody>,
|
|||||||
Object value = context.deserialize(entry.getValue(), entryType);
|
Object value = context.deserialize(entry.getValue(), entryType);
|
||||||
builder.put(key, value);
|
builder.put(key, value);
|
||||||
}
|
}
|
||||||
return builder.create();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RequestBody createInstance(Type type) {
|
public RequestBody createInstance(Type type) {
|
||||||
return new RequestBody.Builder(spec).create();
|
return new RequestBody.Builder(spec).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,11 +66,11 @@ public final class ResponseBodyGsonConverter implements JsonSerializer<ResponseB
|
|||||||
Object value = context.deserialize(entry.getValue(), entryType);
|
Object value = context.deserialize(entry.getValue(), entryType);
|
||||||
responseBodyBuilder.put(key, value, entryType);
|
responseBodyBuilder.put(key, value, entryType);
|
||||||
}
|
}
|
||||||
return responseBodyBuilder.create();
|
return responseBodyBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseBody createInstance(Type type) {
|
public ResponseBody createInstance(Type type) {
|
||||||
return new ResponseBody.Builder(spec).create();
|
return new ResponseBody.Builder(spec).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -81,7 +81,7 @@ public final class RequestReceiver {
|
|||||||
paramsBuilder.put(name, value);
|
paramsBuilder.put(name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return paramsBuilder.create();
|
return paramsBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private RequestBody buildRequestBody(HttpServletRequest request) throws IOException {
|
private RequestBody buildRequestBody(HttpServletRequest request) throws IOException {
|
||||||
@ -95,6 +95,6 @@ public final class RequestReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private RequestBody createEmptyRequestBody(RequestBodySpec bodySpec) {
|
private RequestBody createEmptyRequestBody(RequestBodySpec bodySpec) {
|
||||||
return new RequestBody.Builder(bodySpec).create();
|
return new RequestBody.Builder(bodySpec).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user