EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.rest.binders]

COVERAGE SUMMARY FOR SOURCE FILE [BindMapToStringPayload.java]

nameclass, %method, %block, %line, %
BindMapToStringPayload.java100% (1/1)67%  (2/3)91%  (51/56)92%  (12/13)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BindMapToStringPayload100% (1/1)67%  (2/3)91%  (51/56)92%  (12/13)
bindToRequest (HttpRequest, Object): HttpRequest 0%   (0/1)0%   (0/5)0%   (0/1)
BindMapToStringPayload (Provider): void 100% (1/1)100% (6/6)100% (3/3)
bindToRequest (HttpRequest, Map): HttpRequest 100% (1/1)100% (45/45)100% (9/9)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.rest.binders;
20 
21import java.net.URI;
22import java.util.Map;
23 
24import javax.inject.Inject;
25import javax.inject.Provider;
26import javax.inject.Singleton;
27import javax.ws.rs.core.UriBuilder;
28 
29import org.jclouds.http.HttpRequest;
30import org.jclouds.io.Payloads;
31import org.jclouds.rest.MapBinder;
32import org.jclouds.rest.annotations.Payload;
33import org.jclouds.rest.internal.GeneratedHttpRequest;
34 
35/**
36 * 
37 * @author Adrian Cole
38 */
39@Singleton
40public class BindMapToStringPayload implements MapBinder {
41   protected final Provider<UriBuilder> uriBuilders;
42 
43   @Inject
44   public BindMapToStringPayload(Provider<UriBuilder> uriBuilders) {
45      this.uriBuilders = uriBuilders;
46   }
47 
48   @SuppressWarnings("unchecked")
49   @Override
50   public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
51      GeneratedHttpRequest<?> r = GeneratedHttpRequest.class.cast(request);
52      String payload = r.getJavaMethod().getAnnotation(Payload.class).value();
53      if (postParams.size() > 0) {
54         UriBuilder builder = uriBuilders.get();
55         builder.uri(URI.create("http://test/"));
56         builder.path(payload);
57         URI fake = builder.buildFromMap(postParams);
58         payload = fake.getPath().substring(1);
59      }
60      return (R) request.toBuilder().payload(Payloads.newStringPayload(payload)).build();
61   }
62 
63   @Override
64   public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
65      throw new IllegalArgumentException("this is a map binder");
66   }
67 
68}

[all classes][org.jclouds.rest.binders]
EMMA 2.0.5312 (C) Vladimir Roubtsov