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

COVERAGE SUMMARY FOR SOURCE FILE [LocationConstraintHandler.java]

nameclass, %method, %block, %line, %
LocationConstraintHandler.java0%   (0/1)0%   (0/7)0%   (0/68)0%   (0/18)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class LocationConstraintHandler0%   (0/1)0%   (0/7)0%   (0/68)0%   (0/18)
LocationConstraintHandler (Map): void 0%   (0/1)0%   (0/11)0%   (0/4)
characters (char [], int, int): void 0%   (0/1)0%   (0/8)0%   (0/2)
endElement (String, String, String): void 0%   (0/1)0%   (0/15)0%   (0/3)
fromValue (String): String 0%   (0/1)0%   (0/10)0%   (0/3)
getResult (): String 0%   (0/1)0%   (0/3)0%   (0/1)
setBucket (String): void 0%   (0/1)0%   (0/4)0%   (0/2)
setContext (HttpRequest): LocationConstraintHandler 0%   (0/1)0%   (0/17)0%   (0/3)

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.xml;
20 
21import static org.jclouds.util.SaxUtils.currentOrNull;
22 
23import java.util.Map;
24 
25import javax.inject.Inject;
26 
27import org.jclouds.aws.domain.Region;
28import org.jclouds.http.HttpRequest;
29import org.jclouds.http.functions.ParseSax;
30import org.jclouds.rest.internal.GeneratedHttpRequest;
31import org.jclouds.s3.Bucket;
32 
33/**
34 * Parses the response from Amazon S3 GET Bucket Location
35 * <p/>
36 * Region is the document we expect to parse.
37 * 
38 * @see <a href=
39 *      "http://docs.amazonwebservices.com/AmazonS3/latest/RESTBucketLocationGET.html"
40 *      />
41 * @author Adrian Cole
42 */
43public class LocationConstraintHandler extends ParseSax.HandlerWithResult<String> {
44   private final Map<String, String> bucketToRegion;
45   private StringBuilder currentText = new StringBuilder();
46   private String region;
47   private String bucket;
48 
49   @Inject
50   public LocationConstraintHandler(@Bucket Map<String, String> bucketToRegion) {
51      this.bucketToRegion = bucketToRegion;
52   }
53 
54   public String getResult() {
55      return region;
56   }
57 
58   public void endElement(String uri, String name, String qName) {
59      region = fromValue(currentOrNull(currentText));
60      bucketToRegion.put(bucket, region);
61   }
62 
63   @Override
64   public LocationConstraintHandler setContext(HttpRequest request) {
65      super.setContext(request);
66      setBucket(GeneratedHttpRequest.class.cast(getRequest()).getArgs().get(0).toString());
67      return this;
68   }
69 
70   void setBucket(String bucket) {
71      this.bucket = bucket;
72   }
73 
74   /**
75    * parses the value expected in xml documents from the S3 service.=
76    * <p/>
77    * {@code US_STANDARD} is returned as "" xml documents.
78    */
79   public static String fromValue(String v) {
80      if (v == null || "".equals(v))
81         return Region.US_STANDARD;
82      return v;
83   }
84 
85   public void characters(char ch[], int start, int length) {
86      currentText.append(ch, start, length);
87   }
88}

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