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

COVERAGE SUMMARY FOR SOURCE FILE [OrgHandler.java]

nameclass, %method, %block, %line, %
OrgHandler.java100% (1/1)100% (6/6)91%  (173/190)94%  (36.8/39)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class OrgHandler100% (1/1)100% (6/6)91%  (173/190)94%  (36.8/39)
endElement (String, String, String): void 100% (1/1)71%  (29/41)78%  (7/9)
currentOrNull (): String 100% (1/1)85%  (11/13)92%  (1.8/2)
getResult (): Org 100% (1/1)91%  (31/34)91%  (0.9/1)
OrgHandler (TaskHandler): void 100% (1/1)100% (23/23)100% (8/8)
characters (char [], int, int): void 100% (1/1)100% (8/8)100% (2/2)
startElement (String, String, String, Attributes): void 100% (1/1)100% (71/71)100% (17/17)

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;
22import static org.jclouds.vcloud.util.Utils.putReferenceType;
23 
24import java.util.List;
25import java.util.Map;
26 
27import javax.inject.Inject;
28 
29import org.jclouds.http.functions.ParseSax;
30import org.jclouds.util.SaxUtils;
31import org.jclouds.vcloud.domain.Org;
32import org.jclouds.vcloud.domain.ReferenceType;
33import org.jclouds.vcloud.domain.Task;
34import org.jclouds.vcloud.domain.internal.OrgImpl;
35import org.xml.sax.Attributes;
36import org.xml.sax.SAXException;
37 
38import com.google.common.collect.Lists;
39import com.google.common.collect.Maps;
40 
41/**
42 * @author Adrian Cole
43 */
44public class OrgHandler extends ParseSax.HandlerWithResult<Org> {
45 
46   protected final TaskHandler taskHandler;
47 
48   @Inject
49   public OrgHandler(TaskHandler taskHandler) {
50      this.taskHandler = taskHandler;
51   }
52 
53   private StringBuilder currentText = new StringBuilder();
54 
55   protected ReferenceType org;
56   protected Map<String, ReferenceType> vdcs = Maps.newLinkedHashMap();
57   protected ReferenceType tasksList;
58   protected Map<String, ReferenceType> catalogs = Maps.newLinkedHashMap();
59   protected Map<String, ReferenceType> networks = Maps.newLinkedHashMap();
60   protected List<Task> tasks = Lists.newArrayList();
61 
62   protected String description;
63   protected String fullName;
64 
65   public Org getResult() {
66      return new OrgImpl(org.getName(), org.getType(), org.getHref(), fullName != null ? fullName : org.getName(),
67               description, catalogs, vdcs, networks, tasksList, tasks);
68   }
69 
70   @Override
71   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
72      Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
73      if (qName.endsWith("Org")) {
74         org = newReferenceType(attributes);
75      } else if (qName.endsWith("Link")) {
76         String type = attributes.get("type");
77         if (type != null) {
78            if (type.indexOf("vdc+xml") != -1) {
79               putReferenceType(vdcs, attributes);
80            } else if (type.indexOf("catalog+xml") != -1) {
81               putReferenceType(catalogs, attributes);
82            } else if (type.indexOf("tasksList+xml") != -1) {
83               tasksList = newReferenceType(attributes);
84            } else if (type.indexOf("network+xml") != -1) {
85               putReferenceType(networks, attributes);
86            }
87         }
88      } else {
89         taskHandler.startElement(uri, localName, qName, attrs);
90      }
91 
92   }
93 
94   public void endElement(String uri, String name, String qName) {
95      taskHandler.endElement(uri, name, qName);
96      if (qName.endsWith("Task")) {
97         this.tasks.add(taskHandler.getResult());
98      } else if (qName.endsWith("Description")) {
99         description = currentOrNull();
100      } else if (qName.endsWith("FullName")) {
101         fullName = currentOrNull();
102      }
103      currentText = new StringBuilder();
104   }
105 
106   public void characters(char ch[], int start, int length) {
107      currentText.append(ch, start, length);
108   }
109 
110   protected String currentOrNull() {
111      String returnVal = currentText.toString().trim();
112      return returnVal.equals("") ? null : returnVal;
113   }
114}

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