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

COVERAGE SUMMARY FOR SOURCE FILE [TagSetHandler.java]

nameclass, %method, %block, %line, %
TagSetHandler.java100% (1/1)100% (5/5)100% (92/92)100% (25/25)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TagSetHandler100% (1/1)100% (5/5)100% (92/92)100% (25/25)
TagSetHandler (): void 100% (1/1)100% (11/11)100% (4/4)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
endElement (String, String, String): void 100% (1/1)100% (42/42)100% (10/10)
getResult (): Map 100% (1/1)100% (4/4)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (27/27)100% (8/8)

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.aws.ec2.xml;
20 
21import static org.jclouds.util.SaxUtils.*;
22 
23import java.util.Map;
24 
25import org.jclouds.http.functions.ParseSax;
26import org.xml.sax.Attributes;
27import org.xml.sax.SAXException;
28 
29import com.google.common.base.Strings;
30import com.google.common.collect.ImmutableMap;
31 
32/**
33 * @author grkvlt@apache.org
34 */
35public class TagSetHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Map<String, String>> {
36    private StringBuilder currentText = new StringBuilder();
37 
38    private ImmutableMap.Builder<String, String> result;
39    private boolean inItem = false;
40    private String key;
41    private String value;
42 
43    public TagSetHandler() {
44        super();
45    }
46 
47    public Map<String, String> getResult() {
48        return result.build();
49    }
50 
51    @Override
52    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
53        if (equalsOrSuffix(qName, "tagSet")) {
54                result = ImmutableMap.<String, String>builder();
55        } else if (qName.equals("item")) {
56            inItem = true;
57            key = null;
58            value = null;
59        }
60        currentText = new StringBuilder();
61    }
62 
63    @Override
64    public void endElement(String uri, String localName, String qName) throws SAXException {
65        if (qName.equals("item")) {
66            inItem = false;
67            if (key != null) {
68                    result.put(key, Strings.nullToEmpty(value));
69            }
70        }
71        if (inItem) {
72                if (qName.equals("key")) {
73                    key = currentOrNull(currentText);
74                } else if (qName.equals("value")) {
75                    value = currentOrNull(currentText);
76                }
77        }
78    }
79 
80    @Override
81    public void characters(char ch[], int start, int length) {
82        currentText.append(ch, start, length);
83    }
84}

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