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

nameclass, %method, %block, %line, %
VDCHandler.java100% (1/1)100% (5/5)100% (139/139)100% (29/29)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VDCHandler100% (1/1)100% (5/5)100% (139/139)100% (29/29)
VDCHandler (): void 100% (1/1)100% (14/14)100% (4/4)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
endElement (String, String, String): void 100% (1/1)100% (15/15)100% (4/4)
getResult (): VDC 100% (1/1)100% (25/25)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (77/77)100% (18/18)

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;
23import static org.jclouds.util.SaxUtils.cleanseAttributes;
24import static org.jclouds.util.SaxUtils.currentOrNull;
25import static org.jclouds.util.SaxUtils.equalsOrSuffix;
26 
27import java.util.Map;
28 
29import org.jclouds.http.functions.ParseSax;
30import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType;
31import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
32import org.jclouds.trmk.vcloud_0_8.domain.VDC;
33import org.jclouds.trmk.vcloud_0_8.domain.internal.VDCImpl;
34import org.jclouds.trmk.vcloud_0_8.util.Utils;
35import org.xml.sax.Attributes;
36import org.xml.sax.SAXException;
37 
38import com.google.common.collect.Maps;
39 
40/**
41 * @author Adrian Cole
42 */
43public class VDCHandler extends ParseSax.HandlerWithResult<VDC> {
44 
45   protected StringBuilder currentText = new StringBuilder();
46 
47   protected ReferenceType vDC;
48   protected String description;
49 
50   protected Map<String, ReferenceType> resourceEntities = Maps.newLinkedHashMap();
51   protected Map<String, ReferenceType> availableNetworks = Maps.newLinkedHashMap();
52 
53   private ReferenceType catalog;
54   private ReferenceType publicIps;
55   private ReferenceType internetServices;
56 
57   public VDC getResult() {
58      return new VDCImpl(vDC.getName(), vDC.getType(), vDC.getHref(), description, catalog, publicIps,
59            internetServices, resourceEntities, availableNetworks);
60   }
61 
62   @Override
63   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
64      Map<String, String> attributes = cleanseAttributes(attrs);
65      super.startElement(uri, localName, qName, attrs);
66      if (qName.endsWith("Vdc")) {
67         vDC = newReferenceType(attributes);
68      } else if (qName.endsWith("Network")) {
69         putReferenceType(availableNetworks, attributes);
70      } else if (qName.endsWith("ResourceEntity")) {
71         putReferenceType(resourceEntities, attributes);
72      } else if (equalsOrSuffix(qName, "Link")) {
73         String name = attributes.get("name");
74         if (name.equals("Internet Services")) {
75            internetServices = Utils.newReferenceType(attributes);
76         } else if (name.equals("Public IPs")) {
77            publicIps = Utils.newReferenceType(attributes);
78         } else {
79            String type = attributes.get("type");
80            if (type.equals(TerremarkVCloudMediaType.CATALOG_XML)) {
81               catalog = Utils.newReferenceType(attributes);
82            }
83         }
84      }
85   }
86 
87   public void endElement(String uri, String name, String qName) {
88      if (equalsOrSuffix(qName, "Description")) {
89         description = currentOrNull(currentText);
90      }
91      currentText = new StringBuilder();
92   }
93 
94   public void characters(char ch[], int start, int length) {
95      currentText.append(ch, start, length);
96   }
97}

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