mirror of https://github.com/apache/jclouds.git
exposed methods to create Injectors
git-svn-id: http://jclouds.googlecode.com/svn/trunk@113 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
8e8740ba7f
commit
6839d6c40f
|
@ -40,7 +40,8 @@ import com.google.inject.name.Names;
|
||||||
import static org.jclouds.aws.s3.S3Constants.*;
|
import static org.jclouds.aws.s3.S3Constants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: Adrian: Document return getConnection!
|
* Creates {@link S3Context} or {@link Injector} instances based on the most
|
||||||
|
* commonly requested arguments.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@ -63,16 +64,22 @@ public class S3ContextFactory {
|
||||||
DEFAULT_PROPERTIES.setProperty(PROPERTY_POOL_MAX_CONNECTIONS, "12");
|
DEFAULT_PROPERTIES.setProperty(PROPERTY_POOL_MAX_CONNECTIONS, "12");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static S3Context createS3Context(String awsAccessKeyId,
|
public static Injector createInjector(String awsAccessKeyId,
|
||||||
String awsSecretAccessKey, Module... modules) {
|
String awsSecretAccessKey, Module... modules) {
|
||||||
Properties properties = new Properties(DEFAULT_PROPERTIES);
|
Properties properties = new Properties(DEFAULT_PROPERTIES);
|
||||||
properties.setProperty(PROPERTY_AWS_ACCESSKEYID, awsAccessKeyId);
|
properties.setProperty(PROPERTY_AWS_ACCESSKEYID, awsAccessKeyId);
|
||||||
properties
|
properties
|
||||||
.setProperty(PROPERTY_AWS_SECRETACCESSKEY, awsSecretAccessKey);
|
.setProperty(PROPERTY_AWS_SECRETACCESSKEY, awsSecretAccessKey);
|
||||||
return createS3Context(properties, modules);
|
return createInjector(properties, modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static S3Context createS3Context(String awsAccessKeyId,
|
public static S3Context createS3Context(String awsAccessKeyId,
|
||||||
|
String awsSecretAccessKey, Module... modules) {
|
||||||
|
return createInjector(awsAccessKeyId, awsSecretAccessKey, modules)
|
||||||
|
.getInstance(S3Context.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Injector createInjector(String awsAccessKeyId,
|
||||||
String awsSecretAccessKey, boolean isSecure, Module... modules) {
|
String awsSecretAccessKey, boolean isSecure, Module... modules) {
|
||||||
Properties properties = new Properties(DEFAULT_PROPERTIES);
|
Properties properties = new Properties(DEFAULT_PROPERTIES);
|
||||||
properties.setProperty(PROPERTY_AWS_ACCESSKEYID, awsAccessKeyId);
|
properties.setProperty(PROPERTY_AWS_ACCESSKEYID, awsAccessKeyId);
|
||||||
|
@ -82,10 +89,16 @@ public class S3ContextFactory {
|
||||||
.setProperty(PROPERTY_HTTP_SECURE, Boolean.toString(isSecure));
|
.setProperty(PROPERTY_HTTP_SECURE, Boolean.toString(isSecure));
|
||||||
if (!isSecure)
|
if (!isSecure)
|
||||||
properties.setProperty(PROPERTY_HTTP_PORT, "80");
|
properties.setProperty(PROPERTY_HTTP_PORT, "80");
|
||||||
return createS3Context(properties, modules);
|
return createInjector(properties, modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static S3Context createS3Context(String awsAccessKeyId,
|
public static S3Context createS3Context(String awsAccessKeyId,
|
||||||
|
String awsSecretAccessKey, boolean isSecure, Module... modules) {
|
||||||
|
return createInjector(awsAccessKeyId, awsSecretAccessKey, isSecure,
|
||||||
|
modules).getInstance(S3Context.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Injector createInjector(String awsAccessKeyId,
|
||||||
String awsSecretAccessKey, boolean isSecure, String server,
|
String awsSecretAccessKey, boolean isSecure, String server,
|
||||||
Module... modules) {
|
Module... modules) {
|
||||||
Properties properties = new Properties(DEFAULT_PROPERTIES);
|
Properties properties = new Properties(DEFAULT_PROPERTIES);
|
||||||
|
@ -97,10 +110,24 @@ public class S3ContextFactory {
|
||||||
properties.setProperty(PROPERTY_HTTP_ADDRESS, server);
|
properties.setProperty(PROPERTY_HTTP_ADDRESS, server);
|
||||||
if (!isSecure)
|
if (!isSecure)
|
||||||
properties.setProperty(PROPERTY_HTTP_PORT, "80");
|
properties.setProperty(PROPERTY_HTTP_PORT, "80");
|
||||||
return createS3Context(properties, modules);
|
return createInjector(properties, modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static S3Context createS3Context(String awsAccessKeyId,
|
public static S3Context createS3Context(String awsAccessKeyId,
|
||||||
|
String awsSecretAccessKey, boolean isSecure, String server,
|
||||||
|
Module... modules) {
|
||||||
|
return createInjector(awsAccessKeyId, awsSecretAccessKey, isSecure,
|
||||||
|
server, modules).getInstance(S3Context.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static S3Context createS3Context(String awsAccessKeyId,
|
||||||
|
String awsSecretAccessKey, boolean isSecure, String server,
|
||||||
|
int port, Module... modules) {
|
||||||
|
return createInjector(awsAccessKeyId, awsSecretAccessKey, isSecure,
|
||||||
|
server, port, modules).getInstance(S3Context.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Injector createInjector(String awsAccessKeyId,
|
||||||
String awsSecretAccessKey, boolean isSecure, String server,
|
String awsSecretAccessKey, boolean isSecure, String server,
|
||||||
int port, Module... modules) {
|
int port, Module... modules) {
|
||||||
Properties properties = new Properties(DEFAULT_PROPERTIES);
|
Properties properties = new Properties(DEFAULT_PROPERTIES);
|
||||||
|
@ -111,12 +138,12 @@ public class S3ContextFactory {
|
||||||
.setProperty(PROPERTY_HTTP_SECURE, Boolean.toString(isSecure));
|
.setProperty(PROPERTY_HTTP_SECURE, Boolean.toString(isSecure));
|
||||||
properties.setProperty(PROPERTY_HTTP_ADDRESS, server);
|
properties.setProperty(PROPERTY_HTTP_ADDRESS, server);
|
||||||
properties.setProperty(PROPERTY_HTTP_PORT, port + "");
|
properties.setProperty(PROPERTY_HTTP_PORT, port + "");
|
||||||
return createS3Context(properties, modules);
|
return createInjector(properties, modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static S3Context createS3Context(Properties properties,
|
public static S3Context createS3Context(Properties properties,
|
||||||
Module... modules) {
|
Module... modules) {
|
||||||
return getInjector(properties, modules).getInstance(S3Context.class);
|
return createInjector(properties, modules).getInstance(S3Context.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,7 +158,7 @@ public class S3ContextFactory {
|
||||||
* - modules that must bind {@link HttpFutureCommandClient} if
|
* - modules that must bind {@link HttpFutureCommandClient} if
|
||||||
* specified
|
* specified
|
||||||
* */
|
* */
|
||||||
public static Injector getInjector(final Properties properties,
|
public static Injector createInjector(final Properties properties,
|
||||||
Module... httpModules) {
|
Module... httpModules) {
|
||||||
final List<? extends Module> modules = httpModules.length != 0 ? Arrays
|
final List<? extends Module> modules = httpModules.length != 0 ? Arrays
|
||||||
.asList(httpModules) : Collections
|
.asList(httpModules) : Collections
|
||||||
|
|
Loading…
Reference in New Issue