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

COVERAGE SUMMARY FOR SOURCE FILE [ProvideIso3166CodesByLocationIdViaProperties.java]

nameclass, %method, %block, %line, %
ProvideIso3166CodesByLocationIdViaProperties.java0%   (0/1)0%   (0/2)0%   (0/90)0%   (0/13)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ProvideIso3166CodesByLocationIdViaProperties0%   (0/1)0%   (0/2)0%   (0/90)0%   (0/13)
ProvideIso3166CodesByLocationIdViaProperties (Injector): void 0%   (0/1)0%   (0/9)0%   (0/3)
get (): Map 0%   (0/1)0%   (0/81)0%   (0/10)

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

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