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

COVERAGE SUMMARY FOR SOURCE FILE [CatalogHandler.java]

nameclass, %method, %block, %line, %
CatalogHandler.java100% (1/1)100% (6/6)91%  (155/170)93%  (30.8/33)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CatalogHandler100% (1/1)100% (6/6)91%  (155/170)93%  (30.8/33)
endElement (String, String, String): void 100% (1/1)69%  (29/42)78%  (7/9)
currentOrNull (): String 100% (1/1)85%  (11/13)92%  (1.8/2)
CatalogHandler (TaskHandler): void 100% (1/1)100% (23/23)100% (8/8)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
getResult (): Catalog 100% (1/1)100% (25/25)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (59/59)100% (11/11)

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.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 CatalogHandler extends ParseSax.HandlerWithResult<Catalog> {
46 
47   protected final TaskHandler taskHandler;
48 
49   @Inject
50   public CatalogHandler(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   private boolean readOnly = true;
64 
65   public Catalog getResult() {
66      return new CatalogImpl(catalog.getName(), catalog.getType(), catalog.getHref(), org, description, contents,
67               tasks, published, readOnly);
68   }
69 
70   @Override
71   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
72      Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
73      if (qName.equals("Catalog")) {
74         catalog = newReferenceType(attributes, VCloudMediaType.CATALOG_XML);
75      } else if (qName.equals("CatalogItem")) {
76         putReferenceType(contents, attributes);
77      } else if (qName.equals("Link") && "up".equals(attributes.get("rel"))) {
78         org = newReferenceType(attributes);
79      } else if (qName.equals("Link") && "add".equals(attributes.get("rel"))) {
80         readOnly = false;
81      } else {
82         taskHandler.startElement(uri, localName, qName, attrs);
83      }
84   }
85 
86   public void endElement(String uri, String name, String qName) {
87      taskHandler.endElement(uri, name, qName);
88      if (qName.equals("Task")) {
89         this.tasks.add(taskHandler.getResult());
90      } else if (qName.equals("Description")) {
91         description = currentOrNull();
92      } else if (qName.equals("IsPublished")) {
93         published = Boolean.parseBoolean(currentOrNull());
94      }
95      currentText = new StringBuilder();
96   }
97 
98   public void characters(char ch[], int start, int length) {
99      currentText.append(ch, start, length);
100   }
101 
102   protected String currentOrNull() {
103      String returnVal = currentText.toString().trim();
104      return returnVal.equals("") ? null : returnVal;
105   }
106}

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