Renamed Locator to Provider.
git-svn-id: https://google-guice.googlecode.com/svn/trunk@214 d779f126-a31b-0410-b53b-1d3aecad763e
diff --git a/src/com/google/inject/BinderImpl.java b/src/com/google/inject/BinderImpl.java
index 6abf829..d4b01de 100644
--- a/src/com/google/inject/BinderImpl.java
+++ b/src/com/google/inject/BinderImpl.java
@@ -81,7 +81,7 @@
}
public String toString() {
- return "Locator<Container>";
+ return "Provider<Container>";
}
};
@@ -96,7 +96,7 @@
}
public String toString() {
- return "Locator<Logger>";
+ return "Provider<Logger>";
}
};
@@ -403,9 +403,9 @@
Map<Key<?>, Binding<?>> bindings = container.internalBindings();
Binding<?> original = bindings.get(key);
- // Binding to Locator<?> is not allowed.
- if (key.getRawType().equals(Locator.class)) {
- addError(binding.getSource(), ErrorMessages.CANNOT_BIND_TO_LOCATOR);
+ // Binding to Provider<?> is not allowed.
+ if (key.getRawType().equals(Provider.class)) {
+ addError(binding.getSource(), ErrorMessages.CANNOT_BIND_TO_PROVIDER);
return;
}
diff --git a/src/com/google/inject/Binding.java b/src/com/google/inject/Binding.java
index 4836b6b..623fcdc 100644
--- a/src/com/google/inject/Binding.java
+++ b/src/com/google/inject/Binding.java
@@ -19,7 +19,7 @@
import com.google.inject.util.ToStringBuilder;
/**
- * A binding from a {@link Key} (type and name) to an instance locator.
+ * A binding from a {@link Key} (type and name) to a provider.
*
* @author crazybob@google.com (Bob Lee)
*/
@@ -53,16 +53,16 @@
return source;
}
- volatile Locator<T> locator;
+ volatile Provider<T> provider;
/**
- * Gets the locator which returns instances of {@code T}.
+ * Gets the provider which returns instances of {@code T}.
*/
- public Locator<T> getLocator() {
- if (locator == null) {
- locator = container.getLocator(key);
+ public Provider<T> getProvider() {
+ if (provider == null) {
+ provider = container.getProvider(key);
}
- return locator;
+ return provider;
}
InternalFactory<? extends T> getInternalFactory() {
@@ -85,7 +85,7 @@
return new ToStringBuilder(Binding.class)
.add("key", key)
.add("source", source)
- .add("locator", internalFactory)
+ .add("provider", internalFactory)
.toString();
}
}
\ No newline at end of file
diff --git a/src/com/google/inject/BindingBuilderImpl.java b/src/com/google/inject/BindingBuilderImpl.java
index 95097e2..89310ff 100644
--- a/src/com/google/inject/BindingBuilderImpl.java
+++ b/src/com/google/inject/BindingBuilderImpl.java
@@ -278,7 +278,7 @@
}
public String toString() {
- return new ToStringBuilder(Locator.class)
+ return new ToStringBuilder(Provider.class)
.add("implementation", implementation)
.toString();
}
diff --git a/src/com/google/inject/Container.java b/src/com/google/inject/Container.java
index ca86d7b..9ad642d 100644
--- a/src/com/google/inject/Container.java
+++ b/src/com/google/inject/Container.java
@@ -16,7 +16,6 @@
package com.google.inject;
-import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Map;
@@ -34,7 +33,7 @@
*
* <ul>
* <li>This {@link Container}
- * <li>A {@code Locator<T>} for each binding of type {@code T}
+ * <li>A {@code Provider<T>} for each binding of type {@code T}
* <li>The {@link java.util.logging.Logger} for the class being injected
* <li>The {@link Stage} specified when this container was created
* </ul>
@@ -65,77 +64,13 @@
*/
<T> List<Binding<T>> findBindingsByType(TypeLiteral<T> type);
-// /**
-// * Gets an instance from the locator bound to the given type.
-// */
-// <T> T getInstance(TypeLiteral<T> type);
-//
-// /**
-// * Gets an instance from the locator bound to the given type.
-// */
-// <T> T getInstance(Class<T> type);
-//
-// /**
-// * Gets an instance from the locator bound to the given key.
-// */
-// <T> T getInstance(Key<T> key);
-//
-// /**
-// * Gets an instance from the locator bound to the given type and annotation.
-// */
-// <T> T getInstance(TypeLiteral<T> type, Annotation annotation);
-//
-// /**
-// * Gets an instance from the locator bound to the given type and annotation.
-// */
-// <T> T getInstance(Class<T> type, Annotation annotation);
-//
-// /**
-// * Gets an instance from the locator bound to the given type and annotation.
-// */
-// <T> T getInstance(TypeLiteral<T> type,
-// Class<? extends Annotation> annotationType);
-//
-// /**
-// * Gets an instance from the locator bound to the given type and annotation.
-// */
-// <T> T getInstance(Class<T> type,
-// Class<? extends Annotation> annotationType);
+ /**
+ * Gets the provider bound to the given key.
+ */
+ <T> Provider<T> getProvider(Key<T> key);
/**
- * Gets the locator bound to the given key.
+ * Gets the provider bound to the given type.
*/
- <T> Locator<T> getLocator(Key<T> key);
-
- /**
- * Gets the locator bound to the given type.
- */
- <T> Locator<T> getLocator(Class<T> type);
-
-// /**
-// * Gets the locator bound to the given type.
-// */
-// <T> Locator<T> getLocator(TypeLiteral<T> type);
-//
-// /**
-// * Gets the locator bound to the given type and annotation.
-// */
-// <T> Locator<T> getLocator(Class<T> type, Annotation annotation);
-//
-// /**
-// * Gets the locator bound to the given type and annotation.
-// */
-// <T> Locator<T> getLocator(TypeLiteral<T> type, Annotation annotation);
-//
-// /**
-// * Gets the locator bound to the given type and annotation.
-// */
-// <T> Locator<T> getLocator(Class<T> type,
-// Class<? extends Annotation> annotationType);
-//
-// /**
-// * Gets the locator bound to the given type and annotation.
-// */
-// <T> Locator<T> getLocator(TypeLiteral<T> type,
-// Class<? extends Annotation> annotationType);
+ <T> Provider<T> getProvider(Class<T> type);
}
diff --git a/src/com/google/inject/ContainerImpl.java b/src/com/google/inject/ContainerImpl.java
index 3bd020b..a219f1f 100644
--- a/src/com/google/inject/ContainerImpl.java
+++ b/src/com/google/inject/ContainerImpl.java
@@ -160,20 +160,20 @@
Class<? super T> rawType = key.getType().getRawType();
// Handle cases where T is a Factory<?>.
- if (rawType.equals(Locator.class)) {
- Type locatorType = key.getType().getType();
- if (!(locatorType instanceof ParameterizedType)) {
+ if (rawType.equals(Provider.class)) {
+ Type provderType = key.getType().getType();
+ if (!(provderType instanceof ParameterizedType)) {
return null; // is this right? not test-covered
}
Type entryType
- = ((ParameterizedType) locatorType).getActualTypeArguments()[0];
+ = ((ParameterizedType) provderType).getActualTypeArguments()[0];
try {
- final Locator<?> locator = getLocator(key.ofType(entryType));
+ final Provider<?> provider = getProvider(key.ofType(entryType));
return new InternalFactory<T>() {
@SuppressWarnings("unchecked")
public T get(InternalContext context) {
- return (T) locator;
+ return (T) provider;
}
};
}
@@ -646,69 +646,11 @@
});
}
- // Next 4 methods not test-covered and have no usages
-
- public <T> T getInstance(TypeLiteral<T> type,
- Annotation annotation) {
- return getLocator(Key.get(type, annotation)).get();
+ public <T> Provider<T> getProvider(Class<T> type) {
+ return getProvider(Key.get(type));
}
- public <T> T getInstance(Class<T> type,
- Annotation annotation) {
- return getLocator(Key.get(type, annotation)).get();
- }
-
- public <T> Locator<T> getLocator(Class<T> type,
- Annotation annotation) {
- return getLocator(Key.get(type, annotation));
- }
-
- public <T> Locator<T> getLocator(TypeLiteral<T> type,
- Annotation annotation) {
- return getLocator(Key.get(type, annotation));
- }
-
- public <T> T getInstance(TypeLiteral<T> type,
- Class<? extends Annotation> annotationType) {
- return getLocator(Key.get(type, annotationType)).get();
- }
-
- public <T> T getInstance(Class<T> type,
- Class<? extends Annotation> annotationType) {
- return getLocator(Key.get(type, annotationType)).get();
- }
-
- public <T> Locator<T> getLocator(Class<T> type,
- Class<? extends Annotation> annotationType) {
- return getLocator(Key.get(type, annotationType));
- }
-
- public <T> Locator<T> getLocator(TypeLiteral<T> type,
- Class<? extends Annotation> annotationType) {
- return getLocator(Key.get(type, annotationType));
- }
-
- public <T> T getInstance(TypeLiteral<T> type) {
- return getLocator(Key.get(type)).get();
- }
-
- public <T> T getInstance(Class<T> type) {
- return getLocator(Key.get(type)).get();
- }
-
- public <T> T getInstance(Key<T> key) {
- return getLocator(key).get();
- }
-
- public <T> Locator<T> getLocator(Class<T> type) {
- return getLocator(Key.get(type));
- }
-
- public <T> Locator<T> getLocator(TypeLiteral<T> type) {
- return getLocator(Key.get(type));
- }
-
- public <T> Locator<T> getLocator(final Key<T> key) {
+ public <T> Provider<T> getProvider(final Key<T> key) {
final InternalFactory<? extends T> factory = getInternalFactory(null, key);
if (factory == null) {
@@ -716,7 +658,7 @@
"Missing binding to " + ErrorMessages.convert(key) + ".");
}
- return new Locator<T>() {
+ return new Provider<T>() {
public T get() {
return callInContext(new ContextualCallable<T>() {
public T call(InternalContext context) {
diff --git a/src/com/google/inject/Context.java b/src/com/google/inject/Context.java
index c4a83e2..da7178a 100644
--- a/src/com/google/inject/Context.java
+++ b/src/com/google/inject/Context.java
@@ -33,7 +33,7 @@
/**
* Gets the field, method or constructor which is being injected. Returns
* {@code null} if the object isn't being injected into anywhere (i.e. it's
- * preloaded, returned from {@link Locator#get()}, etc.).
+ * preloaded, returned from {@link Provider#get()}, etc.).
*/
Member getMember();
diff --git a/src/com/google/inject/ErrorMessages.java b/src/com/google/inject/ErrorMessages.java
index d43c2b3..44b9c6a 100644
--- a/src/com/google/inject/ErrorMessages.java
+++ b/src/com/google/inject/ErrorMessages.java
@@ -64,7 +64,7 @@
static final String CONSTANT_CONVERSION_ERROR = "Error converting String"
+ " constant bound at %s to %s: %s";
- static final String CANNOT_BIND_TO_LOCATOR = "Binding to Locator<?> is not"
+ static final String CANNOT_BIND_TO_PROVIDER = "Binding to Provider<?> is not"
+ " allowed.";
static final String SCOPE_NOT_FOUND = "No scope is bound to %s.";
diff --git a/src/com/google/inject/InternalFactoryToLocatorAdapter.java b/src/com/google/inject/InternalFactoryToProviderAdapter.java
similarity index 72%
rename from src/com/google/inject/InternalFactoryToLocatorAdapter.java
rename to src/com/google/inject/InternalFactoryToProviderAdapter.java
index a4707d6..2ffabea 100644
--- a/src/com/google/inject/InternalFactoryToLocatorAdapter.java
+++ b/src/com/google/inject/InternalFactoryToProviderAdapter.java
@@ -19,19 +19,19 @@
/**
* @author crazybob@google.com (Bob Lee)
*/
-class InternalFactoryToLocatorAdapter<T> implements InternalFactory<T> {
+class InternalFactoryToProviderAdapter<T> implements InternalFactory<T> {
- private final Locator<? extends T> locator;
+ private final Provider<? extends T> provider;
- public InternalFactoryToLocatorAdapter(Locator<? extends T> locator) {
- this.locator = locator;
+ public InternalFactoryToProviderAdapter(Provider<? extends T> provider) {
+ this.provider = provider;
}
public T get(InternalContext context) {
- return locator.get();
+ return provider.get();
}
public String toString() {
- return locator.toString();
+ return provider.toString();
}
}
diff --git a/src/com/google/inject/Locator.java b/src/com/google/inject/Provider.java
similarity index 86%
rename from src/com/google/inject/Locator.java
rename to src/com/google/inject/Provider.java
index 2db9605..5fc2a41 100644
--- a/src/com/google/inject/Locator.java
+++ b/src/com/google/inject/Provider.java
@@ -17,14 +17,14 @@
package com.google.inject;
/**
- * Locates bound instances of {@code T}.
+ * Provides instances of {@code T}.
*
* @author crazybob@google.com (Bob Lee)
*/
-public interface Locator<T> {
+public interface Provider<T> {
/**
- * Locates an instance of {@code T}.
+ * Provides an instance of {@code T}.
*/
T get();
}
diff --git a/src/com/google/inject/LocatorToInternalFactoryAdapter.java b/src/com/google/inject/ProviderToInternalFactoryAdapter.java
similarity index 89%
rename from src/com/google/inject/LocatorToInternalFactoryAdapter.java
rename to src/com/google/inject/ProviderToInternalFactoryAdapter.java
index 2eb5078..cd3ab1e 100644
--- a/src/com/google/inject/LocatorToInternalFactoryAdapter.java
+++ b/src/com/google/inject/ProviderToInternalFactoryAdapter.java
@@ -19,13 +19,13 @@
/**
* @author crazybob@google.com (Bob Lee)
*/
-class LocatorToInternalFactoryAdapter<T> implements Locator<T> {
+class ProviderToInternalFactoryAdapter<T> implements Provider<T> {
private final ContainerImpl container;
private final InternalFactory<? extends T> internalFactory;
- public LocatorToInternalFactoryAdapter(ContainerImpl container,
+ public ProviderToInternalFactoryAdapter(ContainerImpl container,
InternalFactory<? extends T> internalFactory) {
this.container = container;
this.internalFactory = internalFactory;
diff --git a/src/com/google/inject/ProxyFactory.java b/src/com/google/inject/ProxyFactory.java
index ab1140c..00fc923 100644
--- a/src/com/google/inject/ProxyFactory.java
+++ b/src/com/google/inject/ProxyFactory.java
@@ -62,10 +62,10 @@
* exceptions in {@link RuntimeException} including
* {@link InvocationTargetException}.
*/
- public <T> Locator<T> getFactory(Class<T> type) throws NoSuchMethodException {
+ public <T> Provider<T> getFactory(Class<T> type) throws NoSuchMethodException {
final ConstructionProxy<T> constructionProxy
= createConstructionProxy(type.getDeclaredConstructor());
- return new Locator<T>() {
+ return new Provider<T>() {
public T get() {
try {
return constructionProxy.newInstance();
diff --git a/src/com/google/inject/Scope.java b/src/com/google/inject/Scope.java
index 37a7130..8ef6e07 100644
--- a/src/com/google/inject/Scope.java
+++ b/src/com/google/inject/Scope.java
@@ -17,10 +17,10 @@
package com.google.inject;
/**
- * A scope which bound objects can reside in. Scopes a given {@link Locator}.
+ * A scope which bound objects can reside in. Scopes a given {@link Provider}.
*
* <p>Scope implementations should override {@code toString()} in the returned
- * locator and include the unscoped locator's {@code toString()} output. Doing
+ * provider and include the unscoped provider's {@code toString()} output. Doing
* so aids debugging. They should also override their own {@code toString()}
* method.
*
@@ -29,16 +29,16 @@
public interface Scope {
/**
- * Scopes a locator. The returned locator returns objects from this scope. If
- * an object does not exist in this scope, the locator can use the given
- * unscoped locator to retrieve one.
+ * Scopes a provider. The returned locator returns objects from this scope. If
+ * an object does not exist in this scope, the provider can use the given
+ * unscoped provider to retrieve one.
*
* @param key binding key
* @param unscoped locates an instance when one doesn't already exist in this
* scope.
- * @return a new locator which only delegates to the given unscoped locator
+ * @return a new provider which only delegates to the given unscoped provider
* when an instance of the requested object doesn't already exist in this
* scope
*/
- public <T> Locator<T> scope(Key<T> key, Locator<T> unscoped);
+ public <T> Provider<T> scope(Key<T> key, Provider<T> unscoped);
}
diff --git a/src/com/google/inject/Scopes.java b/src/com/google/inject/Scopes.java
index a59066a..c1f7558 100644
--- a/src/com/google/inject/Scopes.java
+++ b/src/com/google/inject/Scopes.java
@@ -17,8 +17,6 @@
package com.google.inject;
import java.lang.annotation.Annotation;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
import java.util.Map;
import com.google.inject.util.StackTraceElements;
@@ -35,8 +33,8 @@
* One instance per container. Also see {@code @}{@link ContainerScoped}.
*/
public static final Scope CONTAINER = new Scope() {
- public <T> Locator<T> scope(Key<T> key, final Locator<T> creator) {
- return new Locator<T>() {
+ public <T> Provider<T> scope(Key<T> key, final Provider<T> creator) {
+ return new Provider<T>() {
private volatile T instance;
@@ -118,8 +116,8 @@
if (scope == null) {
return creator;
}
- Locator<T> scoped = scope.scope(key,
- new LocatorToInternalFactoryAdapter<T>(container, creator));
- return new InternalFactoryToLocatorAdapter<T>(scoped);
+ Provider<T> scoped = scope.scope(key,
+ new ProviderToInternalFactoryAdapter<T>(container, creator));
+ return new InternalFactoryToProviderAdapter<T>(scoped);
}
}
diff --git a/src/com/google/inject/servlet/ServletScopes.java b/src/com/google/inject/servlet/ServletScopes.java
index aa07da8..f7cb059 100644
--- a/src/com/google/inject/servlet/ServletScopes.java
+++ b/src/com/google/inject/servlet/ServletScopes.java
@@ -17,7 +17,7 @@
package com.google.inject.servlet;
import com.google.inject.Scope;
-import com.google.inject.Locator;
+import com.google.inject.Provider;
import com.google.inject.Key;
import javax.servlet.http.HttpServletRequest;
@@ -36,9 +36,9 @@
* HTTP servlet request scope.
*/
public static final Scope REQUEST = new Scope() {
- public <T> Locator<T> scope(Key<T> key, final Locator<T> creator) {
+ public <T> Provider<T> scope(Key<T> key, final Provider<T> creator) {
final String name = key.toString();
- return new Locator<T>() {
+ return new Provider<T>() {
public T get() {
HttpServletRequest request = GuiceFilter.getRequest();
synchronized (request) {
@@ -63,9 +63,9 @@
* HTTP session scope.
*/
public static final Scope SESSION = new Scope() {
- public <T> Locator<T> scope(Key<T> key, final Locator<T> creator) {
+ public <T> Provider<T> scope(Key<T> key, final Provider<T> creator) {
final String name = key.toString();
- return new Locator<T>() {
+ return new Provider<T>() {
public T get() {
HttpSession session = GuiceFilter.getRequest().getSession();
synchronized (session) {
diff --git a/src/com/google/inject/tools/jmx/ManagedBinding.java b/src/com/google/inject/tools/jmx/ManagedBinding.java
index ffa0896..798b8f9 100644
--- a/src/com/google/inject/tools/jmx/ManagedBinding.java
+++ b/src/com/google/inject/tools/jmx/ManagedBinding.java
@@ -34,7 +34,7 @@
return binding.getKey().toString();
}
- public String getLocator() {
- return binding.getLocator().toString();
+ public String getProvider() {
+ return binding.getProvider().toString();
}
}
diff --git a/src/com/google/inject/tools/jmx/ManagedBindingMBean.java b/src/com/google/inject/tools/jmx/ManagedBindingMBean.java
index 4b187d7..6f9469a 100644
--- a/src/com/google/inject/tools/jmx/ManagedBindingMBean.java
+++ b/src/com/google/inject/tools/jmx/ManagedBindingMBean.java
@@ -29,9 +29,9 @@
String getSource();
/**
- * Gets the locator to which this binding is bound.
+ * Gets the provider to which this binding is bound.
*/
- String getLocator();
+ String getProvider();
/**
* Gets the binding key.