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

COVERAGE SUMMARY FOR SOURCE FILE [AWSRestClientModule.java]

nameclass, %method, %block, %line, %
AWSRestClientModule.java50%  (1/2)20%  (2/10)13%  (16/125)20%  (4.8/24)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AWSRestClientModule$10%   (0/1)0%   (0/1)0%   (0/6)0%   (0/1)
AWSRestClientModule$1 (AWSRestClientModule): void 0%   (0/1)0%   (0/6)0%   (0/1)
     
class AWSRestClientModule100% (1/1)22%  (2/9)13%  (16/119)20%  (4.8/24)
AWSRestClientModule (Class, Class, Map): void 0%   (0/1)0%   (0/6)0%   (0/2)
bindErrorHandlers (): void 0%   (0/1)0%   (0/25)0%   (0/4)
bindRegionsToProvider (): void 0%   (0/1)0%   (0/4)0%   (0/2)
bindRegionsToProvider (Class): void 0%   (0/1)0%   (0/13)0%   (0/2)
bindRetryHandlers (): void 0%   (0/1)0%   (0/17)0%   (0/3)
configure (): void 0%   (0/1)0%   (0/5)0%   (0/3)
provideRegions (Map): Set 0%   (0/1)0%   (0/3)0%   (0/1)
getDefaultRegion (URI, Map, Logger$LoggerFactory): String 100% (1/1)27%  (11/41)55%  (2.8/5)
AWSRestClientModule (Class, Class): void 100% (1/1)100% (5/5)100% (2/2)

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.aws.config;
20 
21import static com.google.common.collect.Iterables.get;
22 
23import java.net.URI;
24import java.util.Map;
25import java.util.Set;
26 
27import org.jclouds.javax.annotation.Nullable;
28import javax.inject.Singleton;
29 
30import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
31import org.jclouds.aws.handlers.AWSRedirectionRetryHandler;
32import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent;
33import org.jclouds.http.HttpErrorHandler;
34import org.jclouds.http.HttpRetryHandler;
35import org.jclouds.http.RequiresHttp;
36import org.jclouds.http.annotation.ClientError;
37import org.jclouds.http.annotation.Redirection;
38import org.jclouds.http.annotation.ServerError;
39import org.jclouds.location.Provider;
40import org.jclouds.location.Region;
41import org.jclouds.location.config.ProvideRegionToURIViaProperties;
42import org.jclouds.logging.Logger.LoggerFactory;
43import org.jclouds.rest.ConfiguresRestClient;
44import org.jclouds.rest.config.RestClientModule;
45 
46import com.google.common.collect.ImmutableBiMap;
47import com.google.inject.Provides;
48import com.google.inject.Scopes;
49import com.google.inject.TypeLiteral;
50 
51/**
52 * 
53 * @author Adrian Cole
54 */
55@ConfiguresRestClient
56@RequiresHttp
57public class AWSRestClientModule<S, A> extends RestClientModule<S, A> {
58 
59   public AWSRestClientModule(Class<S> syncClientType, Class<A> asyncClientType, Map<Class<?>, Class<?>> delegates) {
60      super(syncClientType, asyncClientType, delegates);
61   }
62 
63   public AWSRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
64      super(syncClientType, asyncClientType);
65   }
66 
67   @Override
68   protected void bindErrorHandlers() {
69      bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseAWSErrorFromXmlContent.class);
70      bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseAWSErrorFromXmlContent.class);
71      bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseAWSErrorFromXmlContent.class);
72   }
73 
74   @Override
75   protected void bindRetryHandlers() {
76      bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(AWSRedirectionRetryHandler.class);
77      bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(AWSClientErrorRetryHandler.class);
78   }
79 
80   @Provides
81   @Singleton
82   @Nullable
83   @Region
84   protected String getDefaultRegion(@Provider URI uri, @Region Map<String, URI> map, LoggerFactory logFactory) {
85      String region = ImmutableBiMap.copyOf(map).inverse().get(uri);
86      if (region == null && map.size() > 0) {
87         logFactory.getLogger(getClass().getName()).warn(
88                  "failed to find region for current endpoint %s in %s; choosing first: %s", uri, map, region);
89         region = get(map.keySet(), 0);
90      }
91      return region;
92   }
93 
94   protected void bindRegionsToProvider() {
95      bindRegionsToProvider(ProvideRegionToURIViaProperties.class);
96   }
97 
98   @Override
99   protected void configure() {
100      super.configure();
101      bindRegionsToProvider();
102   }
103 
104   protected void bindRegionsToProvider(Class<? extends javax.inject.Provider<Map<String, URI>>> providerClass) {
105      bind(new TypeLiteral<Map<String, URI>>() {
106      }).annotatedWith(Region.class).toProvider(providerClass).in(Scopes.SINGLETON);
107   }
108 
109   @Provides
110   @Singleton
111   @Region
112   protected Set<String> provideRegions(@Region Map<String, URI> map) {
113      return map.keySet();
114   }
115 
116}

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