From 4d0e6ae699127d34a70a6cef06660535fd761daa Mon Sep 17 00:00:00 2001 From: adriancole Date: Mon, 8 Apr 2013 23:30:30 -0700 Subject: [PATCH] added type token means for buildApi() as it is in fact used --- .../main/java/org/jclouds/ContextBuilder.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/jclouds/ContextBuilder.java b/core/src/main/java/org/jclouds/ContextBuilder.java index 910afbe3e7..ccdf4eb296 100644 --- a/core/src/main/java/org/jclouds/ContextBuilder.java +++ b/core/src/main/java/org/jclouds/ContextBuilder.java @@ -77,7 +77,6 @@ import org.jclouds.providers.internal.UpdateProviderMetadataFromProperties; import org.jclouds.rest.ConfiguresCredentialStore; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestApiMetadata; -import org.jclouds.rest.RestContext; import org.jclouds.rest.config.CredentialStoreModule; import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.config.RestModule; @@ -110,14 +109,14 @@ import com.google.inject.TypeLiteral; * that api. * *
- * ex. to build a {@link RestContext} on a particular endpoint using the typed + * ex. to build a {@code Api} on a particular endpoint using the typed * interface * *
- * context = ContextBuilder.newBuilder(new NovaApiMetadata())
- *                         .endpoint("http://10.10.10.10:5000/v2.0")
- *                         .credentials(user, pass)
- *                         .build(NovaApiMetadata.CONTEXT_TOKEN)
+ * api = ContextBuilder.newBuilder(new NovaApiMetadata())
+ *                     .endpoint("http://10.10.10.10:5000/v2.0")
+ *                     .credentials(user, pass)
+ *                     .buildApi(NovaApi.class);
  * 
* *
@@ -623,7 +622,15 @@ public class ContextBuilder { * */ public A buildApi(Class api) { - return buildInjector().getInstance(api); + return buildApi(typeToken(api)); + } + + /** + * like {@link #buildApi(Class)} but permits a type-token for convenience. + */ + @SuppressWarnings("unchecked") + public A buildApi(TypeToken apiType) { + return (A) buildInjector().getInstance(Key.get(TypeLiteral.get(apiType.getType()))); } public ApiMetadata getApiMetadata() {