EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.aws.ec2.xml]

COVERAGE SUMMARY FOR SOURCE FILE [SpotInstanceHandler.java]

nameclass, %method, %block, %line, %
SpotInstanceHandler.java100% (1/1)100% (6/6)89%  (243/274)94%  (56.4/60)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SpotInstanceHandler100% (1/1)100% (6/6)89%  (243/274)94%  (56.4/60)
getResult (): SpotInstanceRequest 100% (1/1)76%  (25/33)91%  (4.5/5)
currentOrNull (): String 100% (1/1)85%  (11/13)92%  (1.8/2)
endElement (String, String, String): void 100% (1/1)88%  (151/172)92%  (34/37)
SpotInstanceHandler (DateService, String, LaunchSpecificationHandler, SpotIns... 100% (1/1)100% (20/20)100% (7/7)
characters (char [], int, int): void 100% (1/1)100% (18/18)100% (4/4)
startElement (String, String, String, Attributes): void 100% (1/1)100% (18/18)100% (5/5)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.aws.ec2.xml;
20 
21import javax.inject.Inject;
22 
23import org.jclouds.aws.ec2.domain.SpotInstanceRequest;
24import org.jclouds.aws.ec2.domain.SpotInstanceRequest.Builder;
25import org.jclouds.aws.util.AWSUtils;
26import org.jclouds.date.DateService;
27import org.jclouds.http.functions.ParseSax;
28import org.jclouds.location.Region;
29import org.xml.sax.Attributes;
30 
31/**
32 * 
33 * @author Adrian Cole
34 */
35public class SpotInstanceHandler extends ParseSax.HandlerForGeneratedRequestWithResult<SpotInstanceRequest> {
36   private StringBuilder currentText = new StringBuilder();
37 
38   protected final DateService dateService;
39   protected final String defaultRegion;
40   protected final Builder builder;
41   protected boolean inLaunchSpecification;
42   protected final LaunchSpecificationHandler launchSpecificationHandler;
43 
44   @Inject
45   public SpotInstanceHandler(DateService dateService, @Region String defaultRegion,
46         LaunchSpecificationHandler launchSpecificationHandler, SpotInstanceRequest.Builder builder) {
47      this.dateService = dateService;
48      this.defaultRegion = defaultRegion;
49      this.launchSpecificationHandler = launchSpecificationHandler;
50      this.builder = builder;
51   }
52 
53   protected String currentOrNull() {
54      String returnVal = currentText.toString().trim();
55      return returnVal.equals("") ? null : returnVal;
56   }
57 
58   public SpotInstanceRequest getResult() {
59      try {
60         String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null;
61         if (region == null)
62            region = defaultRegion;
63         return builder.region(region).build();
64      } finally {
65         builder.clear();
66      }
67   }
68 
69   public void startElement(String uri, String name, String qName, Attributes attrs) {
70      if (qName.equals("launchSpecification")) {
71         inLaunchSpecification = true;
72      }
73      if (inLaunchSpecification)
74         launchSpecificationHandler.startElement(uri, name, qName, attrs);
75   }
76 
77   public void endElement(String uri, String name, String qName) {
78      if (qName.equals("launchSpecification")) {
79         inLaunchSpecification = false;
80         builder.launchSpecification(launchSpecificationHandler.getResult());
81      }
82      if (inLaunchSpecification) {
83         launchSpecificationHandler.endElement(uri, name, qName);
84      } else if (qName.equals("spotInstanceRequestId")) {
85         builder.id(currentOrNull());
86      } else if (qName.equals("instanceId")) {
87         builder.instanceId(currentOrNull());
88      } else if (qName.equals("availabilityZoneGroup")) {
89         builder.availabilityZoneGroup(currentOrNull());
90      } else if (qName.equals("launchGroup")) {
91         builder.launchGroup(currentOrNull());
92      } else if (qName.equals("code")) {
93         builder.faultCode(currentOrNull());
94      } else if (qName.equals("message")) {
95         builder.faultMessage(currentOrNull());
96      } else if (qName.equals("spotPrice")) {
97         String price = currentOrNull();
98         if (price != null)
99            builder.spotPrice(Float.parseFloat(price));
100      } else if (qName.equals("type")) {
101         String type = currentOrNull();
102         if (type != null)
103            builder.type(SpotInstanceRequest.Type.fromValue(type));
104      } else if (qName.equals("state")) {
105         String state = currentOrNull();
106         if (state != null)
107            builder.state(SpotInstanceRequest.State.fromValue(state));
108      } else if (qName.equals("createTime")) {
109         String createTime = currentOrNull();
110         if (createTime != null)
111            builder.createTime(dateService.iso8601DateParse(createTime));
112      } else if (qName.equals("productDescription")) {
113         builder.productDescription(currentOrNull());
114      }
115      currentText = new StringBuilder();
116   }
117 
118   public void characters(char ch[], int start, int length) {
119      if (inLaunchSpecification)
120         launchSpecificationHandler.characters(ch, start, length);
121      else
122         currentText.append(ch, start, length);
123   }
124}

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