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

COVERAGE SUMMARY FOR SOURCE FILE [AttachmentHandler.java]

nameclass, %method, %block, %line, %
AttachmentHandler.java100% (1/1)100% (4/4)94%  (117/124)96%  (25/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AttachmentHandler100% (1/1)100% (4/4)94%  (117/124)96%  (25/26)
endElement (String, String, String): void 100% (1/1)91%  (68/75)93%  (13/14)
AttachmentHandler (DateService, String): 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 (): Attachment 100% (1/1)100% (24/24)100% (4/4)

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.annotation.Resource;
24import javax.inject.Inject;
25 
26import org.jclouds.ec2.domain.Attachment;
27import org.jclouds.aws.util.AWSUtils;
28import org.jclouds.date.DateService;
29import org.jclouds.http.functions.ParseSax;
30import org.jclouds.location.Region;
31import org.jclouds.logging.Logger;
32 
33/**
34 * 
35 * @author Adrian Cole
36 */
37public class AttachmentHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Attachment> {
38 
39   @Resource
40   protected Logger logger = Logger.NULL;
41 
42   protected final DateService dateService;
43   protected final String defaultRegion;
44 
45   @Inject
46   AttachmentHandler(DateService dateService, @Region String defaultRegion) {
47      this.dateService = dateService;
48      this.defaultRegion = defaultRegion;
49   }
50 
51   private StringBuilder currentText = new StringBuilder();
52   private String volumeId;
53   private String instanceId;
54   private String device;
55   private Attachment.Status attachmentStatus;
56   private Date attachTime;
57 
58   public Attachment getResult() {
59      String region = AWSUtils.findRegionInArgsOrNull(getRequest());
60      if (region == null)
61         region = defaultRegion;
62      return new Attachment(region, volumeId, instanceId, device, attachmentStatus, attachTime);
63   }
64 
65   public void endElement(String uri, String name, String qName) {
66      if (qName.equals("volumeId")) {
67         volumeId = currentText.toString().trim();
68      } else if (qName.equals("volumeId")) {
69         volumeId = currentText.toString().trim();
70      } else if (qName.equals("status")) {
71         attachmentStatus = Attachment.Status.fromValue(currentText.toString().trim());
72      } else if (qName.equals("instanceId")) {
73         instanceId = currentText.toString().trim();
74      } else if (qName.equals("device")) {
75         device = currentText.toString().trim();
76      } else if (qName.equals("attachTime")) {
77         attachTime = dateService.iso8601DateParse(currentText.toString().trim());
78      }
79      currentText = new StringBuilder();
80   }
81 
82   public void characters(char ch[], int start, int length) {
83      currentText.append(ch, start, length);
84   }
85}

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