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

COVERAGE SUMMARY FOR SOURCE FILE [FirewallServiceHandler.java]

nameclass, %method, %block, %line, %
FirewallServiceHandler.java100% (1/1)100% (5/5)83%  (102/123)85%  (25.6/30)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FirewallServiceHandler100% (1/1)100% (5/5)83%  (102/123)85%  (25.6/30)
getResult (): FirewallService 100% (1/1)60%  (9/15)80%  (1.6/2)
endElement (String, String, String): void 100% (1/1)74%  (42/57)71%  (10/14)
FirewallServiceHandler (FirewallRuleHandler): void 100% (1/1)100% (14/14)100% (5/5)
characters (char [], int, int): void 100% (1/1)100% (14/14)100% (3/3)
startElement (String, String, String, Attributes): void 100% (1/1)100% (23/23)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.util.SaxUtils.currentOrNull;
22import static org.jclouds.util.SaxUtils.equalsOrSuffix;
23 
24import javax.inject.Inject;
25 
26import org.jclouds.http.functions.ParseSax;
27import org.jclouds.savvis.vpdc.domain.FirewallService;
28import org.xml.sax.Attributes;
29import org.xml.sax.SAXException;
30 
31/**
32 * @author Kedar Dave
33 */
34public class FirewallServiceHandler extends ParseSax.HandlerWithResult<FirewallService> {
35   protected StringBuilder currentText = new StringBuilder();
36   private FirewallRuleHandler firewallRuleHandler;
37   private FirewallService.Builder builder = FirewallService.builder();
38   boolean inFirewallService;
39   boolean inFirewallRule;
40 
41   @Inject
42   public FirewallServiceHandler(FirewallRuleHandler firewallRuleHandler) {
43      this.firewallRuleHandler = firewallRuleHandler;
44   }
45 
46   public FirewallService getResult() {
47      try {
48         return builder.build();
49      } finally {
50         builder = FirewallService.builder();
51      }
52   }
53 
54   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
55      if (equalsOrSuffix(qName, "FirewallService")) {
56         inFirewallService = true;
57      } else if (equalsOrSuffix(qName, "FirewallRule")) {
58         inFirewallRule = true;
59         firewallRuleHandler.startElement(uri, localName, qName, attrs);
60      }
61   }
62 
63   @Override
64   public void endElement(String uri, String localName, String qName) throws SAXException {
65      if (equalsOrSuffix(qName, "FirewallService")) {
66         inFirewallService = false;
67      } else if (equalsOrSuffix(qName, "FirewallRule")) {
68         builder.firewallRule(firewallRuleHandler.getResult());
69         inFirewallRule = false;
70      } else if (equalsOrSuffix(qName, "isEnabled")) {
71         if (inFirewallService) {
72            String current = currentOrNull(currentText);
73            if (current != null) {
74               builder.isEnabled(Boolean.parseBoolean(current));
75            }
76         }
77      }
78 
79      if (inFirewallRule) {
80         firewallRuleHandler.endElement(uri, localName, qName);
81      }
82      currentText = new StringBuilder();
83   }
84 
85   @Override
86   public void characters(char ch[], int start, int length) {
87      currentText.append(ch, start, length);
88      firewallRuleHandler.characters(ch, start, length);
89   }
90 
91}

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