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

COVERAGE SUMMARY FOR SOURCE FILE [VDCHandler.java]

nameclass, %method, %block, %line, %
VDCHandler.java100% (1/1)100% (5/5)87%  (113/130)94%  (22.6/24)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VDCHandler100% (1/1)100% (5/5)87%  (113/130)94%  (22.6/24)
getResult (): VDC 100% (1/1)60%  (9/15)80%  (1.6/2)
startElement (String, String, String, Attributes): void 100% (1/1)83%  (55/66)91%  (10/11)
VDCHandler (): void 100% (1/1)100% (11/11)100% (3/3)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
endElement (String, String, String): void 100% (1/1)100% (30/30)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.savvis.vpdc.xml;
20 
21import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes;
22import static org.jclouds.savvis.vpdc.util.Utils.currentOrNull;
23import static org.jclouds.savvis.vpdc.util.Utils.newResource;
24import static org.jclouds.util.SaxUtils.equalsOrSuffix;
25 
26import java.util.Map;
27 
28import org.jclouds.http.functions.ParseSax;
29import org.jclouds.savvis.vpdc.domain.Resource;
30import org.jclouds.savvis.vpdc.domain.VDC;
31import org.jclouds.savvis.vpdc.domain.VDC.Status;
32import org.xml.sax.Attributes;
33import org.xml.sax.SAXException;
34 
35import com.google.common.collect.ImmutableMap;
36 
37/**
38 * @author Adrian Cole
39 */
40public class VDCHandler extends ParseSax.HandlerWithResult<VDC> {
41 
42   protected StringBuilder currentText = new StringBuilder();
43 
44   protected VDC.Builder builder = VDC.builder();
45 
46   public VDC getResult() {
47      try {
48         return builder.build();
49      } finally {
50         builder = VDC.builder();
51      }
52   }
53 
54   @Override
55   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
56      Map<String, String> attributes = cleanseAttributes(attrs);
57      if (equalsOrSuffix(qName, "Vdc")) {
58         // savvis doesn't add href in the header for some reason
59         if (!attributes.containsKey("href") && getRequest() != null)
60            attributes = ImmutableMap.<String, String> builder().putAll(attributes)
61                  .put("href", getRequest().getEndpoint().toASCIIString()).build();
62         Resource vDC = newResource(attributes);
63         builder.name(vDC.getName()).type(vDC.getType()).id(vDC.getId()).href(vDC.getHref());
64      } else if (equalsOrSuffix(qName, "Network")) {
65         builder.availableNetwork(newResource(attributes));
66      } else if (equalsOrSuffix(qName, "ResourceEntity")) {
67         builder.resourceEntity(newResource(attributes));
68      }
69   }
70 
71   public void endElement(String uri, String name, String qName) {
72      if (equalsOrSuffix(qName, "Description")) {
73         builder.description(currentOrNull(currentText));
74      } else if (equalsOrSuffix(qName, "OfferingTag")) {
75         builder.status(Status.fromValue(currentOrNull(currentText)));
76      }
77      currentText = new StringBuilder();
78   }
79 
80   public void characters(char ch[], int start, int length) {
81      currentText.append(ch, start, length);
82   }
83}

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