public abstract class DynamicMap<T> extends java.lang.Object implements java.lang.Iterable<Extension<T>>
Maps index their members by plugin name and export name.
DynamicMaps are always mapped as singletons in Guice. Maps store Providers internally, and resolve the provider to an instance on demand. This enables registrations to decide between singleton and non-singleton members.
Modifier and Type | Method and Description |
---|---|
java.util.SortedMap<java.lang.String,com.google.inject.Provider<T>> |
byPlugin(java.lang.String pluginName)
Get the items exported by a single plugin.
|
static <T> DynamicMap<T> |
emptyMap()
Returns an empty DynamicMap instance *
|
T |
get(java.lang.String pluginName,
java.lang.String exportName)
Lookup an implementation by name.
|
java.util.Iterator<Extension<T>> |
iterator()
Iterate through all entries in an undefined order.
|
static <T> void |
mapOf(com.google.inject.Binder binder,
java.lang.Class<T> member)
Declare a singleton
DynamicMap<T> with a binder. |
static <T> void |
mapOf(com.google.inject.Binder binder,
com.google.inject.TypeLiteral<T> member)
Declare a singleton
DynamicMap<T> with a binder. |
java.util.SortedSet<java.lang.String> |
plugins()
Get the names of all running plugins supplying this type.
|
public static <T> void mapOf(com.google.inject.Binder binder, java.lang.Class<T> member)
DynamicMap<T>
with a binder.
Maps must be defined in a Guice module before they can be bound:
DynamicMap.mapOf(binder(), Interface.class); bind(Interface.class) .annotatedWith(Exports.named("foo")) .to(Impl.class);
binder
- a new binder created in the module.member
- type of value in the map.public static <T> void mapOf(com.google.inject.Binder binder, com.google.inject.TypeLiteral<T> member)
DynamicMap<T>
with a binder.
Maps must be defined in a Guice module before they can be bound:
DynamicMap.mapOf(binder(), new TypeLiteral<Thing<Bar>>(){}); bind(new TypeLiteral<Thing<Bar>>() {}) .annotatedWith(Exports.named("foo")) .to(Impl.class);
binder
- a new binder created in the module.member
- type of value in the map.public static <T> DynamicMap<T> emptyMap()
public T get(java.lang.String pluginName, java.lang.String exportName) throws com.google.inject.ProvisionException
pluginName
- local name of the plugin providing the item.exportName
- name the plugin exports the item as.com.google.inject.ProvisionException
- if the registered provider is unable to obtain an instance of the
requested implementation.public java.util.SortedSet<java.lang.String> plugins()
public java.util.SortedMap<java.lang.String,com.google.inject.Provider<T>> byPlugin(java.lang.String pluginName)
pluginName
- name of the plugin.