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

COVERAGE SUMMARY FOR SOURCE FILE [AccountNameEnumerationResultsHandler.java]

nameclass, %method, %block, %line, %
AccountNameEnumerationResultsHandler.java100% (1/1)100% (5/5)89%  (220/248)91%  (41.1/45)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AccountNameEnumerationResultsHandler100% (1/1)100% (5/5)89%  (220/248)91%  (41.1/45)
startElement (String, String, String, Attributes): void 100% (1/1)86%  (25/29)86%  (6/7)
endElement (String, String, String): void 100% (1/1)86%  (153/177)90%  (26.1/29)
AccountNameEnumerationResultsHandler (DateService): void 100% (1/1)100% (17/17)100% (6/6)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
getResult (): BoundedSet 100% (1/1)100% (17/17)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.azureblob.xml;
20 
21import java.net.URI;
22import java.util.Date;
23import java.util.Map;
24import java.util.SortedSet;
25 
26import javax.inject.Inject;
27 
28import org.jclouds.azureblob.domain.ContainerProperties;
29import org.jclouds.azureblob.domain.internal.ContainerPropertiesImpl;
30import org.jclouds.azure.storage.domain.BoundedSet;
31import org.jclouds.azure.storage.domain.internal.BoundedHashSet;
32import org.jclouds.date.DateService;
33import org.jclouds.http.functions.ParseSax;
34import org.xml.sax.Attributes;
35import org.xml.sax.SAXException;
36 
37import com.google.common.collect.Maps;
38import com.google.common.collect.Sets;
39 
40/**
41 * Parses the following XML document:
42 * <p/>
43 * EnumerationResults AccountName="http://myaccount.blob.core.windows.net"
44 * 
45 * @see <a href="http://msdn.microsoft.com/en-us/library/dd179352.aspx" />
46 * @author Adrian Cole
47 */
48public class AccountNameEnumerationResultsHandler extends
49         ParseSax.HandlerWithResult<BoundedSet<ContainerProperties>> {
50 
51   private SortedSet<ContainerProperties> containerMetadata = Sets.newTreeSet();
52   private String prefix;
53   private String marker;
54   private int maxResults;
55   private String nextMarker;
56   private URI currentUrl;
57   private Date currentLastModified;
58   private String currentETag;
59   private boolean inMetadata;
60 
61   private Map<String, String> currentMetadata = Maps.newHashMap();
62 
63   private StringBuilder currentText = new StringBuilder();
64 
65   private final DateService dateParser;
66   private URI accountUrl;
67 
68   @Inject
69   public AccountNameEnumerationResultsHandler(DateService dateParser) {
70      this.dateParser = dateParser;
71   }
72 
73   @Override
74   public void startElement(String uri, String localName, String qName, Attributes attributes)
75            throws SAXException {
76      if (qName.equals("Container")) {
77         inMetadata = false;
78      } else if (qName.equals("Metadata")) {
79         inMetadata = true;
80      } else if (qName.equals("EnumerationResults")) {
81         accountUrl = URI.create(attributes.getValue("AccountName").toString().trim());
82      }
83   }
84 
85   public BoundedSet<ContainerProperties> getResult() {
86      return new BoundedHashSet<ContainerProperties>(containerMetadata, accountUrl, prefix, marker,
87               maxResults, nextMarker);
88   }
89 
90   public void endElement(String uri, String name, String qName) {
91      if (inMetadata && !qName.equals("Metadata")) {
92         currentMetadata.put(qName, currentText.toString().trim());
93      } else if (qName.equals("Metadata")) {
94         inMetadata = false;
95      } else if (qName.equals("MaxResults")) {
96         maxResults = Integer.parseInt(currentText.toString().trim());
97      } else if (qName.equals("Marker")) {
98         marker = currentText.toString().trim();
99         marker = (marker.equals("")) ? null : marker;
100      } else if (qName.equals("Prefix")) {
101         prefix = currentText.toString().trim();
102         prefix = (prefix.equals("")) ? null : prefix;
103      } else if (qName.equals("NextMarker")) {
104         nextMarker = currentText.toString().trim();
105         nextMarker = (nextMarker.equals("")) ? null : nextMarker;
106      } else if (qName.equals("Container")) {
107         containerMetadata.add(new ContainerPropertiesImpl(currentUrl, currentLastModified,
108                  currentETag, currentMetadata));
109         currentUrl = null;
110         currentLastModified = null;
111         currentETag = null;
112         currentMetadata = Maps.newHashMap();
113      } else if (qName.equals("Url")) {
114         currentUrl = URI.create(currentText.toString().trim());
115      } else if (qName.equals("Last-Modified")) {
116         currentLastModified = dateParser.rfc822DateParse(currentText.toString().trim());
117      } else if (qName.equals("Etag")) {
118         currentETag = currentText.toString().trim();
119      }
120      currentText = new StringBuilder();
121   }
122 
123   public void characters(char ch[], int start, int length) {
124      currentText.append(ch, start, length);
125   }
126}

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