EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.s3.functions]

COVERAGE SUMMARY FOR SOURCE FILE [BindRegionToXmlPayload.java]

nameclass, %method, %block, %line, %
BindRegionToXmlPayload.java0%   (0/1)0%   (0/2)0%   (0/100)0%   (0/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BindRegionToXmlPayload0%   (0/1)0%   (0/2)0%   (0/100)0%   (0/22)
BindRegionToXmlPayload (String, String, Set): void 0%   (0/1)0%   (0/18)0%   (0/6)
bindToRequest (HttpRequest, Object): HttpRequest 0%   (0/1)0%   (0/82)0%   (0/16)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  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,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.s3.functions;
20 
21import static com.google.common.base.Preconditions.checkArgument;
22import static com.google.common.base.Preconditions.checkNotNull;
23 
24import java.util.Set;
25 
26import org.jclouds.javax.annotation.Nullable;
27import javax.annotation.Resource;
28import javax.inject.Inject;
29import javax.inject.Singleton;
30import javax.ws.rs.core.MediaType;
31 
32import org.jclouds.http.HttpRequest;
33import org.jclouds.logging.Logger;
34import org.jclouds.rest.binders.BindToStringPayload;
35import org.jclouds.s3.Bucket;
36 
37/**
38 * 
39 * Depending on your latency and legal requirements, you can specify a location
40 * constraint that will affect where your data physically resides.
41 * 
42 * @author Adrian Cole
43 * 
44 */
45@Singleton
46public class BindRegionToXmlPayload extends BindToStringPayload {
47   @Resource
48   protected Logger logger = Logger.NULL;
49 
50   private final String defaultRegionForEndpoint;
51   private final String defaultRegionForService;
52   private final Set<String> regions;
53 
54   @Inject
55   public BindRegionToXmlPayload(@org.jclouds.location.Region @Nullable String defaultRegionForEndpoint,
56         @Nullable @Bucket String defaultRegionForService, @org.jclouds.location.Region Set<String> regions) {
57      this.defaultRegionForEndpoint = defaultRegionForEndpoint;
58      this.defaultRegionForService = defaultRegionForService;
59      this.regions = checkNotNull(regions, "regions");
60   }
61 
62   @Override
63   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
64      if (defaultRegionForEndpoint == null)
65         return request;
66      input = input == null ? defaultRegionForEndpoint : input;
67      checkArgument(input instanceof String, "this binder is only valid for Region!");
68      String constraint = (String) input;
69      String value = null;
70      if ((defaultRegionForService == null && constraint == null)
71            || (defaultRegionForService != null && defaultRegionForService.equals(constraint))) {
72         // nothing to bind as this is default.
73         return request;
74      } else if (regions.contains(constraint)) {
75         value = constraint;
76      } else {
77         logger.warn("region %s not in %s ", constraint, regions);
78         value = constraint;
79      }
80      String payload = String
81            .format(
82                  "<CreateBucketConfiguration><LocationConstraint>%s</LocationConstraint></CreateBucketConfiguration>",
83                  value);
84      request = super.bindToRequest(request, payload);
85      request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_XML);
86      return request;
87   }
88}

[all classes][org.jclouds.s3.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov