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 [OrgHandler.java]

nameclass, %method, %block, %line, %
OrgHandler.java100% (1/1)83%  (5/6)88%  (122/139)90%  (26/29)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class OrgHandler100% (1/1)83%  (5/6)88%  (122/139)90%  (26/29)
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)
OrgHandler (): void 100% (1/1)100% (17/17)100% (5/5)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
getResult (): Org 100% (1/1)100% (23/23)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (64/64)100% (15/15)

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;
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.domain.Org;
28import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
29import org.jclouds.trmk.vcloud_0_8.domain.internal.OrgImpl;
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 OrgHandler extends ParseSax.HandlerWithResult<Org> {
40 
41   private StringBuilder currentText = new StringBuilder();
42 
43   protected ReferenceType org;
44   protected Map<String, ReferenceType> vdcs = Maps.newLinkedHashMap();
45   protected Map<String, ReferenceType> catalogs = Maps.newLinkedHashMap();
46   protected Map<String, ReferenceType> tasksLists = Maps.newLinkedHashMap();
47   protected ReferenceType keys;
48 
49   protected String description;
50 
51   public Org getResult() {
52      return new OrgImpl(org.getName(), org.getType(), org.getHref(),
53               description, catalogs, vdcs, tasksLists, keys);
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.endsWith("Org")) {
60         org = newReferenceType(attributes);
61      } else if (qName.endsWith("Link")) {
62         String type = attributes.get("type");
63         if (type != null) {
64            if (type.indexOf("vdc+xml") != -1) {
65               putReferenceType(vdcs, attributes);
66            } else if (type.indexOf("catalog+xml") != -1) {
67               putReferenceType(catalogs, attributes);
68            } else if (type.indexOf("tasksList+xml") != -1) {
69               putReferenceType(tasksLists, attributes);
70            } else if (type != null && type.endsWith("keysList+xml")) {
71               keys = newReferenceType(attributes);
72            }
73         }
74      }
75   }
76 
77   public void endElement(String uri, String name, String qName) {
78      if (qName.endsWith("Description")) {
79         description = currentOrNull();
80      }
81      currentText = new StringBuilder();
82   }
83 
84   public void characters(char ch[], int start, int length) {
85      currentText.append(ch, start, length);
86   }
87 
88   protected String currentOrNull() {
89      String returnVal = currentText.toString().trim();
90      return returnVal.equals("") ? null : returnVal;
91   }
92}

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