org.jclouds
Class ContextBuilder

java.lang.Object
  extended by org.jclouds.ContextBuilder

public class ContextBuilder
extends Object

Creates RestContext or Injector instances based on the most commonly requested arguments.

Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.

If no Modules are specified, the default logging and http transports will be installed.

Author:
Adrian Cole, Andrew Newdigate
See Also:
RestContext

Field Summary
protected  ApiMetadata apiMetadata
           
protected  String apiVersion
           
protected  String buildVersion
           
protected  String credential
           
protected  com.google.common.base.Optional<String> endpoint
           
protected  com.google.common.base.Optional<String> identity
           
protected  List<com.google.inject.Module> modules
           
protected  com.google.common.base.Optional<Properties> overrides
           
protected  String providerId
           
protected  com.google.common.base.Optional<ProviderMetadata> providerMetadata
           
 
Constructor Summary
  ContextBuilder(ApiMetadata apiMetadata)
           
protected ContextBuilder(ProviderMetadata providerMetadata)
           
protected ContextBuilder(ProviderMetadata providerMetadata, ApiMetadata apiMetadata)
           
 
Method Summary
 ContextBuilder apiVersion(String apiVersion)
           
<C extends Context>
C
build()
          Builds the base context for this api.
<V extends View>
V
build(Class<V> viewType)
           
<C extends Context>
C
build(com.google.common.reflect.TypeToken<C> contextType)
          this will build the context supported by the current ApiMetadata.
 com.google.inject.Injector buildInjector()
           
static com.google.inject.Injector buildInjector(ProviderMetadata providerMetadata, Credentials creds, List<com.google.inject.Module> inputModules)
           
 ContextBuilder buildVersion(String buildVersion)
           
<V extends View>
V
buildView(Class<V> viewType)
           
<V extends View>
V
buildView(com.google.common.reflect.TypeToken<V> viewType)
          this will build any view supported by the ApiMetadata.
 ContextBuilder credentials(String identity, String credential)
           
 ContextBuilder endpoint(String endpoint)
           
 ApiMetadata getApiMetadata()
           
protected  Properties getSystemProperties()
           
 ContextBuilder modules(Iterable<? extends com.google.inject.Module> modules)
           
static ContextBuilder newBuilder(ApiMetadata apiMetadata)
           
static ContextBuilder newBuilder(ProviderMetadata providerMetadata)
           
static ContextBuilder newBuilder(String providerOrApi)
          looks up a provider or api with the given id
 ContextBuilder overrides(Properties overrides)
           
static String searchPropertiesForProviderScopedProperty(Properties mutable, String prov, String key)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

providerMetadata

protected com.google.common.base.Optional<ProviderMetadata> providerMetadata

providerId

protected final String providerId

endpoint

protected com.google.common.base.Optional<String> endpoint

identity

protected com.google.common.base.Optional<String> identity

credential

@Nullable
protected String credential

apiMetadata

protected ApiMetadata apiMetadata

apiVersion

protected String apiVersion

buildVersion

protected String buildVersion

overrides

protected com.google.common.base.Optional<Properties> overrides

modules

protected List<com.google.inject.Module> modules
Constructor Detail

ContextBuilder

protected ContextBuilder(ProviderMetadata providerMetadata)

ContextBuilder

protected ContextBuilder(@Nullable
                         ProviderMetadata providerMetadata,
                         ApiMetadata apiMetadata)

ContextBuilder

public ContextBuilder(ApiMetadata apiMetadata)
Method Detail

newBuilder

public static ContextBuilder newBuilder(String providerOrApi)
                                 throws NoSuchElementException
looks up a provider or api with the given id

Parameters:
providerOrApi - id of the provider or api
Returns:
means to build a context to that provider
Throws:
NoSuchElementException - if the id was not configured.

newBuilder

public static ContextBuilder newBuilder(ApiMetadata apiMetadata)

newBuilder

public static ContextBuilder newBuilder(ProviderMetadata providerMetadata)

toString

public String toString()
Overrides:
toString in class Object

credentials

public ContextBuilder credentials(String identity,
                                  @Nullable
                                  String credential)

endpoint

public ContextBuilder endpoint(String endpoint)

apiVersion

public ContextBuilder apiVersion(String apiVersion)

buildVersion

public ContextBuilder buildVersion(String buildVersion)

modules

public ContextBuilder modules(Iterable<? extends com.google.inject.Module> modules)

overrides

public ContextBuilder overrides(Properties overrides)

searchPropertiesForProviderScopedProperty

public static String searchPropertiesForProviderScopedProperty(Properties mutable,
                                                               String prov,
                                                               String key)
                                                        throws NoSuchElementException
Throws:
NoSuchElementException

buildInjector

public com.google.inject.Injector buildInjector()

getSystemProperties

protected Properties getSystemProperties()

buildInjector

public static com.google.inject.Injector buildInjector(ProviderMetadata providerMetadata,
                                                       Credentials creds,
                                                       List<com.google.inject.Module> inputModules)

build

public <C extends Context> C build()
Builds the base context for this api. Note that this may be of type Closer, if nothing else was configured via ApiMetadata.getContext(). Typically, the type returned is RestContext

See Also:
ApiMetadata.getContext(), build(TypeToken)

build

public <V extends View> V build(Class<V> viewType)
See Also:
buildView(Class)

buildView

public <V extends View> V buildView(Class<V> viewType)
See Also:
buildView(TypeToken)

buildView

public <V extends View> V buildView(com.google.common.reflect.TypeToken<V> viewType)
this will build any view supported by the ApiMetadata. ex. builder.build(BlobStoreContext.class) will work, if TypeToken<BlobStore> is a configured view of this api.


build

public <C extends Context> C build(com.google.common.reflect.TypeToken<C> contextType)
this will build the context supported by the current ApiMetadata.


getApiMetadata

public ApiMetadata getApiMetadata()


Copyright © 2009-2012 jclouds. All Rights Reserved.