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

COVERAGE SUMMARY FOR SOURCE FILE [SnapshotHandler.java]

nameclass, %method, %block, %line, %
SnapshotHandler.java100% (1/1)100% (4/4)97%  (201/207)98%  (43/44)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SnapshotHandler100% (1/1)100% (4/4)97%  (201/207)98%  (43/44)
endElement (String, String, String): void 100% (1/1)95%  (118/124)96%  (22/23)
SnapshotHandler (DateService, String): 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 (): Snapshot 100% (1/1)100% (61/61)100% (14/14)

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.ec2.xml;
20 
21import java.util.Date;
22 
23import javax.inject.Inject;
24 
25import org.jclouds.ec2.domain.Snapshot;
26import org.jclouds.ec2.domain.Snapshot.Status;
27import org.jclouds.aws.util.AWSUtils;
28import org.jclouds.date.DateService;
29import org.jclouds.http.functions.ParseSax;
30import org.jclouds.location.Region;
31 
32/**
33 * 
34 * @author Adrian Cole
35 */
36public class SnapshotHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Snapshot> {
37   private StringBuilder currentText = new StringBuilder();
38 
39   protected final DateService dateService;
40   protected final String defaultRegion;
41 
42   private String id;
43   private String volumeId;
44   private int volumeSize;
45   private Status status;
46   private Date startTime;
47   private int progress;
48   private String ownerId;
49   private String description;
50   private String ownerAlias;
51 
52   @Inject
53   public SnapshotHandler(DateService dateService, @Region String defaultRegion) {
54      this.dateService = dateService;
55      this.defaultRegion = defaultRegion;
56   }
57 
58   public Snapshot getResult() {
59      String region = AWSUtils.findRegionInArgsOrNull(getRequest());
60      if (region == null)
61         region = defaultRegion;
62      Snapshot snapshot = new Snapshot(region, id, volumeId, volumeSize, status, startTime,
63               progress, ownerId, description, ownerAlias);
64      this.id = null;
65      this.volumeId = null;
66      this.volumeSize = 0;
67      this.status = null;
68      this.startTime = null;
69      this.progress = 0;
70      this.ownerId = null;
71      this.description = null;
72      this.ownerAlias = null;
73      return snapshot;
74   }
75 
76   public void endElement(String uri, String name, String qName) {
77      if (qName.equals("snapshotId")) {
78         id = currentText.toString().trim();
79      } else if (qName.equals("volumeId")) {
80         volumeId = currentText.toString().trim();
81      } else if (qName.equals("volumeSize")) {
82         volumeSize = Integer.parseInt(currentText.toString().trim());
83      } else if (qName.equals("status")) {
84         status = Snapshot.Status.fromValue(currentText.toString().trim());
85      } else if (qName.equals("startTime")) {
86         startTime = dateService.iso8601DateParse(currentText.toString().trim());
87      } else if (qName.equals("progress")) {
88         String progressString = currentText.toString().trim();
89         if (!progressString.equals("")) {
90            progressString = progressString.substring(0, progressString.length() - 1);
91            progress = Integer.parseInt(progressString);
92         }
93      } else if (qName.equals("ownerId")) {
94         ownerId = currentText.toString().trim();
95      } else if (qName.equals("description")) {
96         description = currentText.toString().trim();
97      } else if (qName.equals("ownerAlias")) {
98         ownerAlias = currentText.toString().trim();
99      }
100      currentText = new StringBuilder();
101   }
102 
103   public void characters(char ch[], int start, int length) {
104      currentText.append(ch, start, length);
105   }
106}

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