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

COVERAGE SUMMARY FOR SOURCE FILE [BindAsHostPrefix.java]

nameclass, %method, %block, %line, %
BindAsHostPrefix.java100% (1/1)100% (2/2)100% (53/53)100% (9/9)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BindAsHostPrefix100% (1/1)100% (2/2)100% (53/53)100% (9/9)
BindAsHostPrefix (Provider): void 100% (1/1)100% (6/6)100% (3/3)
bindToRequest (HttpRequest, Object): HttpRequest 100% (1/1)100% (47/47)100% (6/6)

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 static com.google.common.base.Preconditions.checkArgument;
22import static com.google.common.base.Preconditions.checkNotNull;
23import static com.google.common.net.InternetDomainName.fromLenient;
24import static com.google.common.net.InternetDomainName.isValidLenient;
25 
26import javax.inject.Inject;
27import javax.inject.Provider;
28import javax.inject.Singleton;
29import javax.ws.rs.core.UriBuilder;
30 
31import org.jclouds.http.HttpRequest;
32import org.jclouds.rest.Binder;
33 
34import com.google.common.net.InternetDomainName;
35 
36/**
37 * 
38 * @author Adrian Cole
39 */
40@Singleton
41public class BindAsHostPrefix implements Binder {
42 
43   private final Provider<UriBuilder> uriBuilderProvider;
44 
45   @Inject
46   public BindAsHostPrefix(Provider<UriBuilder> uriBuilderProvider) {
47      this.uriBuilderProvider = uriBuilderProvider;
48   }
49 
50   @Override
51   @SuppressWarnings("unchecked")
52   public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
53      checkNotNull(payload, "hostprefix");
54      checkArgument(isValidLenient(request.getEndpoint().getHost()), "this is only valid for hostnames: " + request);
55      UriBuilder builder = uriBuilderProvider.get().uri(request.getEndpoint());
56      InternetDomainName name = fromLenient(request.getEndpoint().getHost()).child(payload.toString());
57      builder.host(name.name());
58      return (R) request.toBuilder().endpoint(builder.build()).build();
59   }
60}

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