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

COVERAGE SUMMARY FOR SOURCE FILE [InstanceStatesHandler.java]

nameclass, %method, %block, %line, %
InstanceStatesHandler.java100% (1/1)100% (5/5)82%  (90/110)90%  (18/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class InstanceStatesHandler100% (1/1)100% (5/5)82%  (90/110)90%  (18/20)
instanceActionWarningOnUnrecognized (String): Instance$Action 100% (1/1)44%  (8/18)75%  (3/4)
instanceStateWarningOnUnrecognized (String): Instance$State 100% (1/1)44%  (8/18)75%  (3/4)
InstanceStatesHandler (): void 100% (1/1)100% (9/9)100% (3/3)
getResult (): Multimap 100% (1/1)100% (3/3)100% (1/1)
startElement (String, String, String, Attributes): void 100% (1/1)100% (62/62)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.deltacloud.xml;
20 
21import java.util.Map;
22 
23import javax.annotation.Resource;
24 
25import org.jclouds.deltacloud.domain.Transition;
26import org.jclouds.deltacloud.domain.TransitionAutomatically;
27import org.jclouds.deltacloud.domain.TransitionOnAction;
28import org.jclouds.deltacloud.domain.Instance.Action;
29import org.jclouds.deltacloud.domain.Instance.State;
30import org.jclouds.http.functions.ParseSax;
31import org.jclouds.logging.Logger;
32import org.jclouds.util.SaxUtils;
33import org.xml.sax.Attributes;
34import org.xml.sax.SAXException;
35 
36import com.google.common.collect.LinkedHashMultimap;
37import com.google.common.collect.Multimap;
38 
39/**
40 * @author Adrian Cole
41 */
42public class InstanceStatesHandler extends ParseSax.HandlerWithResult<Multimap<State, ? extends Transition>> {
43 
44   @Resource
45   protected Logger logger = Logger.NULL;
46 
47   private Multimap<State, Transition> states = LinkedHashMultimap.create();
48   private State state;
49 
50   public Multimap<State, ? extends Transition> getResult() {
51      return states;
52   }
53 
54   @Override
55   public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
56      Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
57      if (qName.equals("state")) {
58         state = instanceStateWarningOnUnrecognized(attributes.get("name"));
59      } else if (qName.equals("transition")) {
60         if (attributes.containsKey("auto"))
61            states.put(state, new TransitionAutomatically(instanceStateWarningOnUnrecognized(attributes.get("to"))));
62         else
63            states.put(state, new TransitionOnAction(instanceActionWarningOnUnrecognized(attributes.get("action")),
64                     instanceStateWarningOnUnrecognized(attributes.get("to"))));
65      }
66   }
67 
68   State instanceStateWarningOnUnrecognized(String input) {
69      State state = State.fromValue(input);
70      if (state == State.UNRECOGNIZED)
71         logger.warn("unrecognized state: %s", input);
72      return state;
73   }
74 
75   Action instanceActionWarningOnUnrecognized(String input) {
76      Action action = Action.fromValue(input);
77      if (action == Action.UNRECOGNIZED)
78         logger.warn("unrecognized action: %s", input);
79      return action;
80   }
81 
82}

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