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

COVERAGE SUMMARY FOR SOURCE FILE [NetworkConnectionSectionHandler.java]

nameclass, %method, %block, %line, %
NetworkConnectionSectionHandler.java100% (1/1)100% (6/6)99%  (156/158)100% (32.8/33)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class NetworkConnectionSectionHandler100% (1/1)100% (6/6)99%  (156/158)100% (32.8/33)
currentOrNull (): String 100% (1/1)85%  (11/13)92%  (1.8/2)
NetworkConnectionSectionHandler (NetworkConnectionHandler): void 100% (1/1)100% (14/14)100% (5/5)
characters (char [], int, int): void 100% (1/1)100% (18/18)100% (4/4)
endElement (String, String, String): void 100% (1/1)100% (50/50)100% (11/11)
getResult (): NetworkConnectionSection 100% (1/1)100% (18/18)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (45/45)100% (10/10)

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.vcloud.xml;
20 
21import static org.jclouds.vcloud.util.Utils.newReferenceType;
22 
23import java.util.Map;
24import java.util.Set;
25 
26import javax.inject.Inject;
27 
28import org.jclouds.http.functions.ParseSax;
29import org.jclouds.util.SaxUtils;
30import org.jclouds.vcloud.domain.NetworkConnection;
31import org.jclouds.vcloud.domain.NetworkConnectionSection;
32import org.jclouds.vcloud.domain.ReferenceType;
33import org.xml.sax.Attributes;
34 
35import com.google.common.collect.Sets;
36 
37/**
38 * @author Adrian Cole
39 */
40public class NetworkConnectionSectionHandler extends ParseSax.HandlerWithResult<NetworkConnectionSection> {
41   protected StringBuilder currentText = new StringBuilder();
42 
43   private final NetworkConnectionHandler networkConnectionHandler;
44 
45   @Inject
46   public NetworkConnectionSectionHandler(NetworkConnectionHandler networkConnectionHandler) {
47      this.networkConnectionHandler = networkConnectionHandler;
48   }
49 
50   protected String info;
51   protected Set<NetworkConnection> connections = Sets.newLinkedHashSet();
52   protected ReferenceType section;
53   protected ReferenceType edit;
54   protected Integer primaryNetworkConnectionIndex;
55   protected boolean inConnections;
56 
57   public NetworkConnectionSection getResult() {
58      return new NetworkConnectionSection(section.getType(), section.getHref(), info, primaryNetworkConnectionIndex,
59               connections, edit);
60   }
61 
62   @Override
63   public void startElement(String uri, String localName, String qName, Attributes attrs) {
64      Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
65      if (qName.endsWith("NetworkConnection")) {
66         inConnections = true;
67      }
68      if (inConnections) {
69         networkConnectionHandler.startElement(uri, localName, qName, attrs);
70      } else if (qName.endsWith("NetworkConnectionSection")) {
71         section = newReferenceType(attributes);
72      } else if (qName.endsWith("Link") && "edit".equals(attributes.get("rel"))) {
73         edit = newReferenceType(attributes);
74      }
75   }
76 
77   @Override
78   public void endElement(String uri, String localName, String qName) {
79      if (qName.endsWith("NetworkConnection")) {
80         inConnections = false;
81         connections.add(networkConnectionHandler.getResult());
82      }
83      if (inConnections) {
84         networkConnectionHandler.endElement(uri, localName, qName);
85      } else if (qName.endsWith("Info")) {
86         this.info = currentOrNull();
87      } else if (qName.endsWith("PrimaryNetworkConnectionIndex")) {
88         this.primaryNetworkConnectionIndex = new Integer(currentOrNull());
89      }
90      currentText = new StringBuilder();
91   }
92 
93   @Override
94   public void characters(char ch[], int start, int length) {
95      if (inConnections)
96         networkConnectionHandler.characters(ch, start, length);
97      else
98         currentText.append(ch, start, length);
99   }
100 
101   protected String currentOrNull() {
102      String returnVal = currentText.toString().trim();
103      return returnVal.equals("") ? null : returnVal;
104   }
105}

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