EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.vcloud.xml]

COVERAGE SUMMARY FOR SOURCE FILE [VCloudExpressNetworkHandler.java]

nameclass, %method, %block, %line, %
VCloudExpressNetworkHandler.java100% (1/1)100% (5/5)59%  (173/293)65%  (36.6/56)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VCloudExpressNetworkHandler100% (1/1)100% (5/5)59%  (173/293)65%  (36.6/56)
endElement (String, String, String): void 100% (1/1)46%  (101/221)54%  (22.6/42)
VCloudExpressNetworkHandler (): void 100% (1/1)100% (23/23)100% (7/7)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
getResult (): VCloudExpressNetwork 100% (1/1)100% (29/29)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (12/12)100% (4/4)

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.vcloud.xml;
20 
21import static org.jclouds.util.SaxUtils.cleanseAttributes;
22import static org.jclouds.util.SaxUtils.currentOrNull;
23import static org.jclouds.vcloud.util.Utils.newReferenceType;
24 
25import java.util.Map;
26import java.util.Set;
27 
28import javax.annotation.Resource;
29 
30import org.jclouds.http.functions.ParseSax;
31import org.jclouds.logging.Logger;
32import org.jclouds.vcloud.domain.ReferenceType;
33import org.jclouds.vcloud.domain.network.FenceMode;
34import org.jclouds.vcloud.domain.network.VCloudExpressNetwork;
35import org.jclouds.vcloud.domain.network.firewall.FirewallPolicy;
36import org.jclouds.vcloud.domain.network.firewall.FirewallRule;
37import org.jclouds.vcloud.domain.network.internal.VCloudExpressNetworkImpl;
38import org.jclouds.vcloud.domain.network.nat.NatProtocol;
39import org.jclouds.vcloud.domain.network.nat.rules.PortForwardingRule;
40import org.xml.sax.Attributes;
41import org.xml.sax.SAXException;
42 
43import com.google.common.collect.Sets;
44 
45/**
46 * @author Adrian Cole
47 */
48public class VCloudExpressNetworkHandler extends ParseSax.HandlerWithResult<VCloudExpressNetwork> {
49 
50   @Resource
51   protected Logger logger = Logger.NULL;
52 
53   protected StringBuilder currentText = new StringBuilder();
54 
55   protected ReferenceType network;
56 
57   protected String description;
58 
59   protected Set<String> dnsServers = Sets.newLinkedHashSet();
60   protected String gateway;
61   protected String netmask;
62   protected Set<FenceMode> fenceModes = Sets.newLinkedHashSet();
63   protected Boolean dhcp;
64   protected Set<PortForwardingRule> natRules = Sets.newLinkedHashSet();
65   protected Set<FirewallRule> firewallRules = Sets.newLinkedHashSet();
66 
67   protected String externalIP;
68   protected Integer externalPort;
69   protected String internalIP;
70   protected Integer internalPort;
71 
72   protected FirewallPolicy policy;
73   protected String sourceIP;
74   protected int sourcePort;
75 
76   public VCloudExpressNetwork getResult() {
77      return new VCloudExpressNetworkImpl(network.getName(), network.getType(), network.getHref(), description,
78               dnsServers, gateway, netmask, fenceModes, dhcp, natRules, firewallRules);
79   }
80 
81   @Override
82   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
83      Map<String, String> attributes = cleanseAttributes(attrs);
84      if (qName.equals("Network")) {
85         network = newReferenceType(attributes);
86      }
87   }
88 
89   public void endElement(String uri, String name, String qName) {
90      if (qName.equals("Description")) {
91         description = currentOrNull(currentText);
92      } else if (qName.equals("Dns")) {
93         dnsServers.add(currentOrNull(currentText));
94      } else if (qName.equals("Gateway")) {
95         gateway = currentOrNull(currentText);
96      } else if (qName.equals("Netmask")) {
97         netmask = currentOrNull(currentText);
98      } else if (qName.equals("FenceMode")) {
99         try {
100            fenceModes.add(FenceMode.fromValue(currentOrNull(currentText)));
101         } catch (IllegalArgumentException e) {
102            fenceModes.add(FenceMode.BRIDGED);
103         }
104      } else if (qName.equals("Dhcp")) {
105         dhcp = new Boolean(currentOrNull(currentText));
106      } else if (qName.equals("NatRule")) {
107         natRules.add(new PortForwardingRule(externalIP, externalPort, internalIP, internalPort, NatProtocol.TCP_UDP));
108         externalIP = null;
109         externalPort = null;
110         internalIP = null;
111         internalPort = null;
112      } else if (qName.equals("ExternalIP")) {
113         externalIP = currentOrNull(currentText);
114      } else if (qName.equals("ExternalPort")) {
115         externalPort = Integer.parseInt(currentOrNull(currentText));
116      } else if (qName.equals("InternalIP")) {
117         internalIP = currentOrNull(currentText);
118      } else if (qName.equals("InternalPort")) {
119         internalPort = Integer.parseInt(currentOrNull(currentText));
120      } else if (qName.equals("FirewallRule")) {
121         firewallRules.add(new FirewallRule(true, null, policy, null, sourcePort, sourceIP));
122         policy = null;
123         sourceIP = null;
124         sourcePort = -1;
125      } else if (qName.equals("Policy")) {
126         policy = FirewallPolicy.fromValue(currentOrNull(currentText));
127      } else if (qName.equals("SourceIp")) {
128         sourceIP = currentOrNull(currentText);
129      } else if (qName.equals("SourcePort")) {
130         sourcePort = Integer.parseInt(currentOrNull(currentText));
131      }
132 
133      currentText = new StringBuilder();
134   }
135 
136   public void characters(char ch[], int start, int length) {
137      currentText.append(ch, start, length);
138   }
139 
140}

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