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

COVERAGE SUMMARY FOR SOURCE FILE [HardwareProfileHandler.java]

nameclass, %method, %block, %line, %
HardwareProfileHandler.java100% (1/1)100% (5/5)100% (138/138)100% (34/34)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class HardwareProfileHandler100% (1/1)100% (5/5)100% (138/138)100% (34/34)
HardwareProfileHandler (HardwarePropertyHandler): void 100% (1/1)100% (14/14)100% (5/5)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
endElement (String, String, String): void 100% (1/1)100% (70/70)100% (15/15)
getResult (): HardwareProfile 100% (1/1)100% (3/3)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (43/43)100% (11/11)

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.deltacloud.xml;
20 
21import java.net.URI;
22import java.util.Map;
23import java.util.Set;
24 
25import javax.inject.Inject;
26 
27import org.jclouds.deltacloud.domain.HardwareProfile;
28import org.jclouds.deltacloud.domain.HardwareProperty;
29import org.jclouds.http.functions.ParseSax;
30import org.jclouds.util.SaxUtils;
31import org.xml.sax.Attributes;
32import org.xml.sax.SAXException;
33 
34import com.google.common.collect.Sets;
35 
36/**
37 * @author Adrian Cole
38 */
39public class HardwareProfileHandler extends ParseSax.HandlerWithResult<HardwareProfile> {
40   private StringBuilder currentText = new StringBuilder();
41   private final HardwarePropertyHandler propertyHandler;
42 
43   @Inject
44   HardwareProfileHandler(HardwarePropertyHandler propertyHandler) {
45      this.propertyHandler = propertyHandler;
46   }
47 
48   private URI href;
49   private String id;
50   private String name;
51   private Set<HardwareProperty> properties = Sets.newLinkedHashSet();
52   private boolean inProperty;
53 
54   private HardwareProfile profile;
55 
56   public HardwareProfile getResult() {
57      return profile;
58   }
59 
60   @Override
61   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
62      Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
63      if (qName.equals("property")) {
64         inProperty = true;
65      }
66 
67      if (inProperty) {
68         propertyHandler.startElement(uri, localName, qName, attrs);
69      } else if (qName.equals("hardware_profile")) {
70         String href = attributes.get("href");
71         if (href != null) {
72            this.href = URI.create(href);
73         }
74         this.id = attributes.get("id");
75      }
76   }
77 
78   @Override
79   public void endElement(String uri, String localName, String qName) throws SAXException {
80 
81      if (inProperty)
82         propertyHandler.endElement(uri, localName, qName);
83 
84      if (qName.endsWith("property")) {
85         inProperty = false;
86         this.properties.add(propertyHandler.getResult());
87      } else if (qName.equalsIgnoreCase("name")) {
88         this.name = currentText.toString().trim();
89      } else if (qName.equalsIgnoreCase("hardware_profile")) {
90         this.profile = new HardwareProfile(href, id, name, properties);
91         this.href = null;
92         this.id = null;
93         this.name = null;
94         this.properties = Sets.newLinkedHashSet();
95      }
96      currentText = new StringBuilder();
97   }
98 
99   public void characters(char ch[], int start, int length) {
100      currentText.append(ch, start, length);
101   }
102}

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