Removed dependence on Guice and Collections from wsclient.

Renamed Builder.create() methods to Builder.build()
This commit is contained in:
Inderjeet Singh 2010-01-19 12:58:52 +00:00
parent 2bcc832ade
commit 51efca8457
14 changed files with 52 additions and 22 deletions

View File

@ -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();
}
}
}

View File

@ -23,7 +23,6 @@ import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.util.Map;
import com.google.common.base.Preconditions;
import com.google.gson.Gson;
import com.google.gson.webservice.definition.HeaderMap;
import com.google.gson.webservice.definition.HeaderMapSpec;
@ -70,13 +69,13 @@ public final class ResponseReceiver {
paramsBuilder.put(paramName, value, typeOfT);
}
}
return paramsBuilder.create();
return paramsBuilder.build();
}
private ResponseBody readResponseBody(HttpURLConnection conn, ResponseBodySpec bodySpec)
throws IOException {
if (bodySpec.size() == 0) {
return new ResponseBody.Builder(bodySpec).create();
return new ResponseBody.Builder(bodySpec).build();
}
String connContentType = conn.getContentType();
Preconditions.checkArgument(connContentType.contains(bodySpec.getContentType()));

View File

@ -39,7 +39,7 @@ public final class CallPathMap<T> {
return this;
}
public CallPathMap<T> create() {
public CallPathMap<T> build() {
return new CallPathMap<T>(contents, nullValue);
}
}

View File

@ -41,7 +41,7 @@ public final class HeaderMap extends ParamMap {
return (Builder) super.put(paramName, content, typeOfContent);
}
public HeaderMap create() {
public HeaderMap build() {
return new HeaderMap(spec, contents);
}
}

View File

@ -34,7 +34,7 @@ public final class HeaderMapSpec implements ParamMapSpec {
map.put(headerName, headerType);
}
public HeaderMapSpec create() {
public HeaderMapSpec build() {
return new HeaderMapSpec(map);
}
}

View File

@ -44,7 +44,7 @@ public final class RequestBody extends ContentBody {
return (Builder) super.put(paramName, content, typeOfContent);
}
public RequestBody create() {
public RequestBody build() {
return new RequestBody(spec, contents);
}
}

View File

@ -33,7 +33,7 @@ public final class RequestBodySpec extends ContentBodySpec {
return this;
}
public RequestBodySpec create() {
public RequestBodySpec build() {
RequestBodySpec spec = new RequestBodySpec(paramsSpec);
return spec;
}

View File

@ -41,7 +41,7 @@ public final class ResponseBody extends ContentBody {
return (Builder) super.put(paramName, content, typeOfContent);
}
public ResponseBody create() {
public ResponseBody build() {
return new ResponseBody(spec, contents);
}
}

View File

@ -33,7 +33,7 @@ public final class ResponseBodySpec extends ContentBodySpec {
return this;
}
public ResponseBodySpec create() {
public ResponseBodySpec build() {
ResponseBodySpec spec = new ResponseBodySpec(paramsSpec);
return spec;
}

View File

@ -29,7 +29,7 @@ import java.util.Set;
*/
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 {
private final CallPath callPath;
@ -71,14 +71,14 @@ public final class WebServiceCallSpec {
resBodySpecBuilder.add(paramName, type);
return this;
}
public WebServiceCallSpec create() {
public WebServiceCallSpec build() {
if (supportedHttpMethods.isEmpty()) {
supportedHttpMethods.addAll(Arrays.asList(HttpMethod.values()));
}
RequestSpec requestSpec =
new RequestSpec(reqParamsSpecBuilder.create(), reqBodySpecBuilder.create());
new RequestSpec(reqParamsSpecBuilder.build(), reqBodySpecBuilder.build());
ResponseSpec responseSpec =
new ResponseSpec(resParamsSpecBuilder.create(), resBodySpecBuilder.create());
new ResponseSpec(resParamsSpecBuilder.build(), resBodySpecBuilder.build());
WebServiceCallSpec callSpec = new WebServiceCallSpec(supportedHttpMethods, callPath,
requestSpec, responseSpec);
return callSpec;

View File

@ -60,8 +60,8 @@ public final class WebServiceResponse {
return this;
}
public WebServiceResponse create() {
return new WebServiceResponse(spec, headers.create(), body.create());
public WebServiceResponse build() {
return new WebServiceResponse(spec, headers.build(), body.build());
}
}

View File

@ -66,11 +66,11 @@ public class RequestBodyGsonConverter implements JsonSerializer<RequestBody>,
Object value = context.deserialize(entry.getValue(), entryType);
builder.put(key, value);
}
return builder.create();
return builder.build();
}
@Override
public RequestBody createInstance(Type type) {
return new RequestBody.Builder(spec).create();
return new RequestBody.Builder(spec).build();
}
}

View File

@ -66,11 +66,11 @@ public final class ResponseBodyGsonConverter implements JsonSerializer<ResponseB
Object value = context.deserialize(entry.getValue(), entryType);
responseBodyBuilder.put(key, value, entryType);
}
return responseBodyBuilder.create();
return responseBodyBuilder.build();
}
@Override
public ResponseBody createInstance(Type type) {
return new ResponseBody.Builder(spec).create();
return new ResponseBody.Builder(spec).build();
}
}

View File

@ -81,7 +81,7 @@ public final class RequestReceiver {
paramsBuilder.put(name, value);
}
}
return paramsBuilder.create();
return paramsBuilder.build();
}
private RequestBody buildRequestBody(HttpServletRequest request) throws IOException {
@ -95,6 +95,6 @@ public final class RequestReceiver {
}
private RequestBody createEmptyRequestBody(RequestBodySpec bodySpec) {
return new RequestBody.Builder(bodySpec).create();
return new RequestBody.Builder(bodySpec).build();
}
}