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

COVERAGE SUMMARY FOR SOURCE FILE [ProvideRegionToURIViaProperties.java]

nameclass, %method, %block, %line, %
ProvideRegionToURIViaProperties.java0%   (0/1)0%   (0/2)0%   (0/97)0%   (0/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ProvideRegionToURIViaProperties0%   (0/1)0%   (0/2)0%   (0/97)0%   (0/15)
ProvideRegionToURIViaProperties (Injector, Multimap): void 0%   (0/1)0%   (0/9)0%   (0/4)
get (): Map 0%   (0/1)0%   (0/88)0%   (0/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.location.config;
20 
21import static org.jclouds.location.reference.LocationConstants.ENDPOINT;
22import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION;
23import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
24 
25import java.net.URI;
26import java.util.Map;
27import java.util.Map.Entry;
28 
29import javax.inject.Inject;
30import javax.inject.Named;
31import javax.inject.Singleton;
32 
33import org.jclouds.location.Region;
34 
35import com.google.common.base.Splitter;
36import com.google.common.collect.ImmutableMap;
37import com.google.common.collect.Multimap;
38import com.google.common.collect.ImmutableMap.Builder;
39import com.google.inject.ConfigurationException;
40import com.google.inject.Injector;
41import com.google.inject.Key;
42import com.google.inject.name.Names;
43 
44/**
45 * 
46 * looks for properties bound to the naming convention jclouds.region.{@code regionId}.endpoint
47 * 
48 * @author Adrian Cole
49 */
50@Singleton
51public class ProvideRegionToURIViaProperties implements javax.inject.Provider<Map<String, URI>> {
52 
53   private final Injector injector;
54   private final Multimap<String, String> constants;
55 
56   @Inject
57   protected ProvideRegionToURIViaProperties(Injector injector, @Named("CONSTANTS") Multimap<String, String> constants) {
58      this.injector = injector;
59      this.constants = constants;
60   }
61 
62   @Singleton
63   @Region
64   @Override
65   public Map<String, URI> get() {
66      try {
67         String regionString = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_REGIONS)));
68         Builder<String, URI> regions = ImmutableMap.<String, URI> builder();
69         for (String region : Splitter.on(',').split(regionString)) {
70            String regionUri = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_REGION + "." + region
71                     + "." + ENDPOINT)));
72            for (Entry<String, String> entry : constants.entries()) {
73               regionUri = regionUri.replace(new StringBuilder().append('{').append(entry.getKey()).append('}').toString(), entry
74                        .getValue());
75            }
76            regions.put(region, URI.create(regionUri));
77         }
78         return regions.build();
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         return ImmutableMap.of();
83      }
84   }
85 
86}

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