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

COVERAGE SUMMARY FOR SOURCE FILE [RestContextImpl.java]

nameclass, %method, %block, %line, %
RestContextImpl.java100% (1/1)15%  (3/20)18%  (50/280)25%  (17/69)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RestContextImpl100% (1/1)15%  (3/20)18%  (50/280)25%  (17/69)
credentialStore (): Map 0%   (0/1)0%   (0/3)0%   (0/1)
equals (Object): boolean 0%   (0/1)0%   (0/85)0%   (0/28)
getApiVersion (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getAsyncApi (): Object 0%   (0/1)0%   (0/3)0%   (0/1)
getCredentialStore (): Map 0%   (0/1)0%   (0/3)0%   (0/1)
getDescription (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getEndpoint (): URI 0%   (0/1)0%   (0/3)0%   (0/1)
getId (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getIdentity (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getIso3166Codes (): Set 0%   (0/1)0%   (0/3)0%   (0/1)
getMetadata (): Map 0%   (0/1)0%   (0/11)0%   (0/1)
getParent (): Location 0%   (0/1)0%   (0/2)0%   (0/1)
getScope (): LocationScope 0%   (0/1)0%   (0/2)0%   (0/1)
getUtils (): Utils 0%   (0/1)0%   (0/3)0%   (0/1)
hashCode (): int 0%   (0/1)0%   (0/58)0%   (0/7)
toString (): String 0%   (0/1)0%   (0/32)0%   (0/1)
utils (): Utils 0%   (0/1)0%   (0/3)0%   (0/1)
close (): void 100% (1/1)38%  (5/13)60%  (3/5)
RestContextImpl (Closer, Map, Utils, Injector, TypeLiteral, TypeLiteral, URI,... 100% (1/1)100% (42/42)100% (13/13)
getApi (): Object 100% (1/1)100% (3/3)100% (1/1)

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.rest.internal;
20 
21import java.io.IOException;
22import java.net.URI;
23import java.util.Map;
24import java.util.Set;
25 
26import javax.annotation.Resource;
27import javax.inject.Inject;
28 
29import org.jclouds.domain.Credentials;
30import org.jclouds.domain.Location;
31import org.jclouds.domain.LocationScope;
32import org.jclouds.lifecycle.Closer;
33import org.jclouds.location.Iso3166;
34import org.jclouds.location.Provider;
35import org.jclouds.logging.Logger;
36import org.jclouds.rest.RestContext;
37import org.jclouds.rest.Utils;
38import org.jclouds.rest.annotations.ApiVersion;
39import org.jclouds.rest.annotations.Identity;
40 
41import com.google.common.collect.ImmutableMap;
42import com.google.inject.Injector;
43import com.google.inject.Key;
44import com.google.inject.Singleton;
45import com.google.inject.TypeLiteral;
46 
47/**
48 * @author Adrian Cole
49 */
50@Singleton
51public class RestContextImpl<S, A> implements RestContext<S, A> {
52 
53   @Resource
54   private Logger logger = Logger.NULL;
55   private final A asyncApi;
56   private final S syncApi;
57   private final Closer closer;
58   private final URI endpoint;
59   private final String identity;
60   private final String provider;
61   private final String apiVersion;
62   private final Utils utils;
63   private final Map<String, Credentials> credentialStore;
64   private final Set<String> iso3166Codes;
65 
66   @Inject
67   protected RestContextImpl(Closer closer, Map<String, Credentials> credentialStore, Utils utils, Injector injector,
68            TypeLiteral<S> syncApi, TypeLiteral<A> asyncApi, @Provider URI endpoint, @Provider String provider,
69            @Identity String identity, @ApiVersion String apiVersion, @Iso3166 Set<String> iso3166Codes) {
70      this.credentialStore = credentialStore;
71      this.utils = utils;
72      this.asyncApi = injector.getInstance(Key.get(asyncApi));
73      this.syncApi = injector.getInstance(Key.get(syncApi));
74      this.closer = closer;
75      this.endpoint = endpoint;
76      this.identity = identity;
77      this.provider = provider;
78      this.apiVersion = apiVersion;
79      this.iso3166Codes = iso3166Codes;
80   }
81 
82   /**
83    * {@inheritDoc}
84    * 
85    * @see Closer
86    */
87   @Override
88   public void close() {
89      try {
90         closer.close();
91      } catch (IOException e) {
92         logger.error(e, "error closing content");
93      }
94   }
95 
96   @Override
97   public String getIdentity() {
98      return identity;
99   }
100 
101   @Override
102   public A getAsyncApi() {
103      return asyncApi;
104   }
105 
106   @Override
107   public S getApi() {
108      return syncApi;
109   }
110 
111   @Override
112   public URI getEndpoint() {
113      return endpoint;
114   }
115 
116   @Override
117   public Utils getUtils() {
118      return utils();
119   }
120 
121   @Override
122   public Utils utils() {
123      return utils;
124   }
125 
126   @Override
127   public String getApiVersion() {
128      return apiVersion;
129   }
130 
131   @Override
132   public int hashCode() {
133      final int prime = 31;
134      int result = 1;
135      result = prime * result + ((apiVersion == null) ? 0 : apiVersion.hashCode());
136      result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode());
137      result = prime * result + ((identity == null) ? 0 : identity.hashCode());
138      result = prime * result + ((provider == null) ? 0 : provider.hashCode());
139      return result;
140   }
141 
142   @Override
143   public boolean equals(Object obj) {
144      if (this == obj)
145         return true;
146      if (obj == null)
147         return false;
148      if (getClass() != obj.getClass())
149         return false;
150      RestContextImpl<?, ?> other = (RestContextImpl<?, ?>) obj;
151      if (apiVersion == null) {
152         if (other.apiVersion != null)
153            return false;
154      } else if (!apiVersion.equals(other.apiVersion))
155         return false;
156      if (endpoint == null) {
157         if (other.endpoint != null)
158            return false;
159      } else if (!endpoint.equals(other.endpoint))
160         return false;
161      if (identity == null) {
162         if (other.identity != null)
163            return false;
164      } else if (!identity.equals(other.identity))
165         return false;
166      if (provider == null) {
167         if (other.provider != null)
168            return false;
169      } else if (!provider.equals(other.provider))
170         return false;
171      return true;
172   }
173 
174   @Override
175   public String toString() {
176      return " [id=" + provider + ", endpoint=" + endpoint + ", apiVersion=" + apiVersion + ", identity=" + identity
177               + ", iso3166Codes=" + iso3166Codes + "]";
178   }
179 
180   @Override
181   public Map<String, Credentials> getCredentialStore() {
182      return credentialStore;
183   }
184 
185   @Override
186   public Map<String, Credentials> credentialStore() {
187      return credentialStore;
188   }
189 
190   @Override
191   public String getDescription() {
192      return null;
193   }
194 
195   @Override
196   public String getId() {
197      return provider;
198   }
199 
200   @Override
201   public Set<String> getIso3166Codes() {
202      return iso3166Codes;
203   }
204 
205   @Override
206   public Map<String, Object> getMetadata() {
207      return ImmutableMap.<String, Object> of("endpoint", endpoint, "apiVersion", apiVersion, "identity", identity);
208   }
209 
210   @Override
211   public Location getParent() {
212      return null;
213   }
214 
215   @Override
216   public LocationScope getScope() {
217      return LocationScope.PROVIDER;
218   }
219}

[all classes][org.jclouds.rest.internal]
EMMA 2.0.5312 (C) Vladimir Roubtsov