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

COVERAGE SUMMARY FOR SOURCE FILE [NetworkHandler.java]

nameclass, %method, %block, %line, %
NetworkHandler.java100% (1/1)100% (5/5)86%  (107/124)94%  (20.6/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class NetworkHandler100% (1/1)100% (5/5)86%  (107/124)94%  (20.6/22)
getResult (): Network 100% (1/1)60%  (9/15)80%  (1.6/2)
startElement (String, String, String, Attributes): void 100% (1/1)82%  (50/61)89%  (8/9)
NetworkHandler (): 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% (29/29)100% (6/6)

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.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.Network;
30import org.jclouds.savvis.vpdc.domain.Resource;
31import org.xml.sax.Attributes;
32import org.xml.sax.SAXException;
33 
34import com.google.common.collect.ImmutableMap;
35 
36/**
37 * @author Adrian Cole
38 */
39public class NetworkHandler extends ParseSax.HandlerWithResult<Network> {
40 
41   protected StringBuilder currentText = new StringBuilder();
42 
43   protected Network.Builder builder = Network.builder();
44 
45   public Network getResult() {
46      try {
47         return builder.build();
48      } finally {
49         builder = Network.builder();
50      }
51   }
52 
53   @Override
54   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
55      Map<String, String> attributes = cleanseAttributes(attrs);
56      if (equalsOrSuffix(qName, "Network")) {
57         // savvis doesn't add href in the header for some reason
58         if (!attributes.containsKey("href") && getRequest() != null)
59            attributes = ImmutableMap.<String, String> builder().putAll(attributes)
60                  .put("href", getRequest().getEndpoint().toASCIIString()).build();
61         Resource org = newResource(attributes);
62         builder.name(org.getName()).type(org.getType()).id(org.getId()).href(org.getHref());
63      } else if (equalsOrSuffix(qName, "NatRule")) {
64         builder.internalToExternalNATRule(attributes.get("internalIP"), attributes.get("externalIP"));
65      }
66   }
67 
68   public void endElement(String uri, String name, String qName) {
69      if (equalsOrSuffix(qName, "Gateway")) {
70         builder.gateway(currentOrNull(currentText));
71      } else if (equalsOrSuffix(qName, "Netmask")) {
72         builder.netmask(currentOrNull(currentText));
73      }
74      currentText = new StringBuilder();
75   }
76 
77   public void characters(char ch[], int start, int length) {
78      currentText.append(ch, start, length);
79   }
80}

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