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

COVERAGE SUMMARY FOR SOURCE FILE [ListAllMyBucketsHandler.java]

nameclass, %method, %block, %line, %
ListAllMyBucketsHandler.java100% (1/1)100% (4/4)93%  (88/95)95%  (19/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ListAllMyBucketsHandler100% (1/1)100% (4/4)93%  (88/95)95%  (19/20)
endElement (String, String, String): void 100% (1/1)90%  (63/70)92%  (11/12)
ListAllMyBucketsHandler (DateService): void 100% (1/1)100% (14/14)100% (5/5)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
getResult (): Set 100% (1/1)100% (3/3)100% (1/1)

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.Date;
24import java.util.Set;
25 
26import javax.inject.Inject;
27 
28import org.jclouds.s3.domain.BucketMetadata;
29import org.jclouds.s3.domain.CanonicalUser;
30import org.jclouds.date.DateService;
31import org.jclouds.http.functions.ParseSax;
32 
33import com.google.common.collect.Sets;
34 
35/**
36 * Parses the following XML document:
37 * <p/>
38 * SetAllMyBucketsResult xmlns="http://doc.s3.amazonaws.com/2006-03-01"
39 * 
40 * @see <a
41 *      href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTServiceGET.html"
42 *      />
43 * @author Adrian Cole
44 */
45public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult<Set<BucketMetadata>> {
46 
47   private Set<BucketMetadata> buckets = Sets.newLinkedHashSet();
48   private CanonicalUser currentOwner;
49   private StringBuilder currentText = new StringBuilder();
50 
51   private final DateService dateParser;
52   private String currentName;
53   private Date currentCreationDate;
54 
55   @Inject
56   public ListAllMyBucketsHandler(DateService dateParser) {
57      this.dateParser = dateParser;
58   }
59 
60   public Set<BucketMetadata> getResult() {
61      return buckets;
62   }
63 
64   public void endElement(String uri, String name, String qName) {
65      if (qName.equals("ID")) { // owner stuff
66         currentOwner = new CanonicalUser(currentOrNull(currentText));
67      } else if (qName.equals("DisplayName")) {
68         currentOwner.setDisplayName(currentOrNull(currentText));
69      } else if (qName.equals("Bucket")) {
70         buckets.add(new BucketMetadata(currentName, currentCreationDate, currentOwner));
71      } else if (qName.equals("Name")) {
72         currentName = currentOrNull(currentText);
73      } else if (qName.equals("CreationDate")) {
74         currentCreationDate = dateParser.iso8601DateParse(currentOrNull(currentText));
75      }
76      currentText = new StringBuilder();
77   }
78 
79   public void characters(char ch[], int start, int length) {
80      currentText.append(ch, start, length);
81   }
82}

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