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

COVERAGE SUMMARY FOR SOURCE FILE [TaskHandler.java]

nameclass, %method, %block, %line, %
TaskHandler.java100% (1/1)100% (6/6)88%  (146/166)89%  (27.6/31)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TaskHandler100% (1/1)100% (6/6)88%  (146/166)89%  (27.6/31)
parseDate (String): Date 100% (1/1)26%  (5/19)25%  (1/4)
getResult (): Task 100% (1/1)60%  (9/15)80%  (1.6/2)
TaskHandler (DateService): void 100% (1/1)100% (12/12)100% (5/5)
characters (char [], int, int): void 100% (1/1)100% (1/1)100% (1/1)
endElement (String, String, String): void 100% (1/1)100% (1/1)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (118/118)100% (18/18)

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.savvis.vpdc.xml;
20 
21import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes;
22import static org.jclouds.savvis.vpdc.util.Utils.newResource;
23import static org.jclouds.util.SaxUtils.equalsOrSuffix;
24 
25import java.util.Date;
26import java.util.Map;
27 
28import javax.inject.Inject;
29 
30import org.jclouds.date.DateService;
31import org.jclouds.http.functions.ParseSax;
32import org.jclouds.logging.Logger;
33import org.jclouds.savvis.vpdc.domain.Resource;
34import org.jclouds.savvis.vpdc.domain.Task;
35import org.jclouds.savvis.vpdc.domain.TaskError;
36import org.jclouds.savvis.vpdc.util.Utils;
37import org.xml.sax.Attributes;
38import org.xml.sax.SAXException;
39 
40/**
41 * @author Adrian Cole
42 */
43public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
44   @javax.annotation.Resource
45   protected Logger logger = Logger.NULL;
46 
47   protected final DateService dateService;
48 
49   private Task.Builder builder = Task.builder();
50 
51   @Inject
52   public TaskHandler(DateService dateService) {
53      this.dateService = dateService;
54   }
55 
56   public Task getResult() {
57      try {
58         return builder.build();
59      } finally {
60         builder = Task.builder();
61      }
62 
63   }
64 
65   @Override
66   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
67      Map<String, String> attributes = cleanseAttributes(attrs);
68      if (equalsOrSuffix(qName, "Task")) {
69         Resource task = newResource(attributes);
70         builder.id(task.getId());
71         builder.type(task.getType());
72         builder.href(task.getHref());
73         if (attributes.containsKey("startTime"))
74            builder.startTime(parseDate(attributes.get("startTime")));
75         if (attributes.containsKey("endTime"))
76            builder.endTime(parseDate(attributes.get("endTime")));
77         builder.status(Task.Status.fromValue(attributes.get("status")));
78      } else if (equalsOrSuffix(qName, "Owner")) {
79         builder.owner(Utils.newResource(attributes));
80      } else if (equalsOrSuffix(qName, "Result")) {
81         builder.result(Utils.newResource(attributes));
82      } else if (equalsOrSuffix(qName, "Error")) {
83         builder.error(new TaskError(attributes.get("message"), Integer.parseInt(attributes.get("majorErrorCode")),
84               Integer.parseInt(attributes.get("minorErrorCode")), attributes.get("vendorSpecificErrorCode")));
85      }
86 
87   }
88 
89   private Date parseDate(String toParse) {
90      try {
91         return dateService.iso8601DateParse(toParse);
92      } catch (RuntimeException e) {
93         logger.error(e, "error parsing date, %s", toParse);
94      }
95      return null;
96   }
97 
98   @Override
99   public void endElement(String uri, String localName, String qName) {
100   }
101 
102   @Override
103   public void characters(char ch[], int start, int length) {
104   }
105 
106}

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