EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.trmk.vcloud_0_8.xml]

COVERAGE SUMMARY FOR SOURCE FILE [CatalogHandler.java]

nameclass, %method, %block, %line, %
CatalogHandler.java100% (1/1)83%  (5/6)80%  (68/85)83%  (15/18)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CatalogHandler100% (1/1)83%  (5/6)80%  (68/85)83%  (15/18)
currentOrNull (): String 0%   (0/1)0%   (0/13)0%   (0/2)
endElement (String, String, String): void 100% (1/1)71%  (10/14)75%  (3/4)
CatalogHandler (): void 100% (1/1)100% (11/11)100% (3/3)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
getResult (): Catalog 100% (1/1)100% (17/17)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (22/22)100% (6/6)

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.trmk.vcloud_0_8.xml;
20 
21import static org.jclouds.trmk.vcloud_0_8.util.Utils.newReferenceType;
22import static org.jclouds.trmk.vcloud_0_8.util.Utils.putReferenceType;
23 
24import java.util.Map;
25 
26import org.jclouds.http.functions.ParseSax;
27import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType;
28import org.jclouds.trmk.vcloud_0_8.domain.Catalog;
29import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
30import org.jclouds.trmk.vcloud_0_8.domain.internal.CatalogImpl;
31import org.jclouds.util.SaxUtils;
32import org.xml.sax.Attributes;
33import org.xml.sax.SAXException;
34 
35import com.google.common.collect.Maps;
36 
37/**
38 * @author Adrian Cole
39 */
40public class CatalogHandler extends ParseSax.HandlerWithResult<Catalog> {
41 
42   private StringBuilder currentText = new StringBuilder();
43 
44   private ReferenceType catalog;
45   private Map<String, ReferenceType> contents = Maps.newLinkedHashMap();
46   private String description;
47 
48   public Catalog getResult() {
49      return new CatalogImpl(catalog.getName(), catalog.getType(), catalog.getHref(), description, contents);
50   }
51 
52   @Override
53   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
54      Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
55      if (qName.equals("Catalog")) {
56         catalog = newReferenceType(attributes, TerremarkVCloudMediaType.CATALOG_XML);
57      } else if (qName.equals("CatalogItem")) {
58         putReferenceType(contents, attributes);
59      }
60   }
61 
62   public void endElement(String uri, String name, String qName) {
63      if (qName.equals("Description")) {
64         description = currentOrNull();
65      }
66      currentText = new StringBuilder();
67   }
68 
69   public void characters(char ch[], int start, int length) {
70      currentText.append(ch, start, length);
71   }
72 
73   protected String currentOrNull() {
74      String returnVal = currentText.toString().trim();
75      return returnVal.equals("") ? null : returnVal;
76   }
77}

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