EMMA Coverage Report (generated Wed Oct 26 13:47:17 EDT 2011)
[all classes][org.jclouds.location.config]

COVERAGE SUMMARY FOR SOURCE FILE [ProvideZonesViaProperties.java]

nameclass, %method, %block, %line, %
ProvideZonesViaProperties.java0%   (0/1)0%   (0/2)0%   (0/64)0%   (0/11)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ProvideZonesViaProperties0%   (0/1)0%   (0/2)0%   (0/64)0%   (0/11)
ProvideZonesViaProperties (Injector, Set): void 0%   (0/1)0%   (0/9)0%   (0/4)
get (): Map 0%   (0/1)0%   (0/55)0%   (0/7)

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.location.config;
20 
21import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION;
22 
23import java.util.Map;
24import java.util.Set;
25 
26import javax.inject.Inject;
27import javax.inject.Singleton;
28 
29import org.jclouds.location.Region;
30import org.jclouds.location.Zone;
31 
32import com.google.common.base.Splitter;
33import com.google.common.collect.ImmutableMap;
34import com.google.common.collect.ImmutableMap.Builder;
35import com.google.inject.ConfigurationException;
36import com.google.inject.Injector;
37import com.google.inject.Key;
38import com.google.inject.name.Names;
39 
40/**
41 * 
42 * looks for properties bound to the naming convention jclouds.location.region.{@code regionId}.zones
43 * 
44 * @author Adrian Cole
45 */
46@Singleton
47public class ProvideZonesViaProperties implements javax.inject.Provider<Map<String, String>> {
48 
49   private final Injector injector;
50   private final Set<String> regions;
51 
52   @Inject
53   ProvideZonesViaProperties(Injector injector, @Region Set<String> regions) {
54      this.injector = injector;
55      this.regions = regions;
56   }
57 
58   @Singleton
59   @Zone
60   @Override
61   public Map<String, String> get() {
62      try {
63         Builder<String, String> zones = ImmutableMap.<String, String> builder();
64         for (String region : regions) {
65            for (String zone : Splitter.on(',').split(
66                  injector.getInstance(Key.get(String.class, Names.named(PROPERTY_REGION + "." + region + ".zones"))))) {
67               zones.put(zone, region);
68            }
69         }
70         return zones.build();
71      } catch (ConfigurationException e) {
72         // this happens if regions property isn't set
73         // services not run by AWS may not have zones, so this is ok.
74         return ImmutableMap.<String, String> of();
75      }
76   }
77}

[all classes][org.jclouds.location.config]
EMMA 2.0.5312 (C) Vladimir Roubtsov