EMMA Coverage Report (generated Fri Jun 17 06:47:19 EDT 2011)
[all classes][org.jclouds.vcloud.xml]

COVERAGE SUMMARY FOR SOURCE FILE [VCloudExpressCatalogHandler.java]

nameclass, %method, %block, %line, %
VCloudExpressCatalogHandler.java100% (1/1)17%  (1/6)13%  (20/152)23%  (7/30)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VCloudExpressCatalogHandler100% (1/1)17%  (1/6)13%  (20/152)23%  (7/30)
characters (char [], int, int): void 0%   (0/1)0%   (0/8)0%   (0/2)
currentOrNull (): String 0%   (0/1)0%   (0/13)0%   (0/2)
endElement (String, String, String): void 0%   (0/1)0%   (0/42)0%   (0/9)
getResult (): Catalog 0%   (0/1)0%   (0/24)0%   (0/1)
startElement (String, String, String, Attributes): void 0%   (0/1)0%   (0/45)0%   (0/9)
VCloudExpressCatalogHandler (TaskHandler): void 100% (1/1)100% (20/20)100% (7/7)

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.vcloud.xml;
20 
21import static org.jclouds.vcloud.util.Utils.newReferenceType;
22import static org.jclouds.vcloud.util.Utils.putReferenceType;
23 
24import java.util.List;
25import java.util.Map;
26 
27import javax.inject.Inject;
28 
29import org.jclouds.http.functions.ParseSax;
30import org.jclouds.util.SaxUtils;
31import org.jclouds.vcloud.VCloudMediaType;
32import org.jclouds.vcloud.domain.Catalog;
33import org.jclouds.vcloud.domain.ReferenceType;
34import org.jclouds.vcloud.domain.Task;
35import org.jclouds.vcloud.domain.internal.CatalogImpl;
36import org.xml.sax.Attributes;
37import org.xml.sax.SAXException;
38 
39import com.google.common.collect.Lists;
40import com.google.common.collect.Maps;
41 
42/**
43 * @author Adrian Cole
44 */
45public class VCloudExpressCatalogHandler extends ParseSax.HandlerWithResult<Catalog> {
46 
47   protected final TaskHandler taskHandler;
48 
49   @Inject
50   public VCloudExpressCatalogHandler(TaskHandler taskHandler) {
51      this.taskHandler = taskHandler;
52   }
53 
54   private StringBuilder currentText = new StringBuilder();
55 
56   private ReferenceType catalog;
57   private Map<String, ReferenceType> contents = Maps.newLinkedHashMap();
58   protected List<Task> tasks = Lists.newArrayList();
59   private String description;
60   private ReferenceType org;
61 
62   private boolean published = true;
63 
64   public Catalog getResult() {
65      return new CatalogImpl(catalog.getName(), catalog.getType(), catalog.getHref(), org, description, contents,
66               tasks, published, false);
67   }
68 
69   @Override
70   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
71      Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
72      if (qName.equals("Catalog")) {
73         catalog = newReferenceType(attributes, VCloudMediaType.CATALOG_XML);
74      } else if (qName.equals("CatalogItem")) {
75         putReferenceType(contents, attributes);
76      } else if (qName.equals("Link") && "up".equals(attributes.get("rel"))) {
77         org = newReferenceType(attributes);
78      } else {
79         taskHandler.startElement(uri, localName, qName, attrs);
80      }
81   }
82 
83   public void endElement(String uri, String name, String qName) {
84      taskHandler.endElement(uri, name, qName);
85      if (qName.equals("Task")) {
86         this.tasks.add(taskHandler.getResult());
87      } else if (qName.equals("Description")) {
88         description = currentOrNull();
89      } else if (qName.equals("IsPublished")) {
90         published = Boolean.parseBoolean(currentOrNull());
91      }
92      currentText = new StringBuilder();
93   }
94 
95   public void characters(char ch[], int start, int length) {
96      currentText.append(ch, start, length);
97   }
98 
99   protected String currentOrNull() {
100      String returnVal = currentText.toString().trim();
101      return returnVal.equals("") ? null : returnVal;
102   }
103}

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