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

COVERAGE SUMMARY FOR SOURCE FILE [CatalogItemHandler.java]

nameclass, %method, %block, %line, %
CatalogItemHandler.java100% (1/1)100% (6/6)95%  (139/146)96%  (27.8/29)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CatalogItemHandler100% (1/1)100% (6/6)95%  (139/146)96%  (27.8/29)
endElement (String, String, String): void 100% (1/1)83%  (25/30)86%  (6/7)
currentOrNull (): String 100% (1/1)85%  (11/13)92%  (1.8/2)
CatalogItemHandler (): 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 (): CatalogItem 100% (1/1)100% (20/20)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (64/64)100% (14/14)

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.trmk.vcloud_0_8.xml;
20 
21import static org.jclouds.trmk.vcloud_0_8.util.Utils.newReferenceType;
22 
23import java.util.Map;
24import java.util.SortedMap;
25 
26import org.jclouds.http.functions.ParseSax;
27import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem;
28import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
29import org.jclouds.trmk.vcloud_0_8.domain.internal.CatalogItemImpl;
30import org.jclouds.util.SaxUtils;
31import org.xml.sax.Attributes;
32import org.xml.sax.SAXException;
33 
34import com.google.common.collect.Maps;
35 
36/**
37 * @author Adrian Cole
38 */
39public class CatalogItemHandler extends ParseSax.HandlerWithResult<CatalogItem> {
40   private StringBuilder currentText = new StringBuilder();
41 
42   protected ReferenceType catalogItem;
43   protected ReferenceType entity;
44 
45   protected String description;
46   protected String key;
47   protected SortedMap<String, String> properties = Maps.newTreeMap();
48   private ReferenceType customizationOptions;
49   private ReferenceType computeOptions;
50 
51   public CatalogItem getResult() {
52      return new CatalogItemImpl(catalogItem.getName(), catalogItem.getHref(), description, computeOptions,
53            customizationOptions, entity, properties);
54   }
55 
56   @Override
57   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
58      Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
59      if (qName.equals("CatalogItem")) {
60         catalogItem = newReferenceType(attributes);
61      } else if (qName.equals("Entity")) {
62         entity = newReferenceType(attributes);
63      } else if (qName.equals("Property")) {
64         key = attributes.get("key");
65      } else if (qName.equals("Link")) {
66         if (attributes.containsKey("name")) {
67            if (attributes.get("name").equals("Customization Options")) {
68               customizationOptions = newReferenceType(attributes);
69            } else if (attributes.get("name").equals("Compute Options")) {
70               computeOptions = newReferenceType(attributes);
71            }
72         }
73      }
74   }
75 
76   public void endElement(String uri, String name, String qName) {
77      if (qName.equals("Description")) {
78         description = currentOrNull();
79      } else if (qName.equals("Property")) {
80         properties.put(key, currentOrNull());
81         key = null;
82      }
83      currentText = new StringBuilder();
84   }
85 
86   public void characters(char ch[], int start, int length) {
87      currentText.append(ch, start, length);
88   }
89 
90   protected String currentOrNull() {
91      String returnVal = currentText.toString().trim();
92      return returnVal.equals("") ? null : returnVal;
93   }
94}

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