下面列出了com.google.inject.multibindings.MapBinder#newMapBinder ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initCorrectionPlugins() {
MapBinder<String, ICorrectionProvider> parserCorrectionPlugins
= MapBinder.newMapBinder(binder(), String.class, ICorrectionProvider.class);
parserCorrectionPlugins
.addBinding(DamerauLevenshteinCorrectionProvider.ID)
.to(DamerauLevenshteinCorrectionProvider.class);
parserCorrectionPlugins
.addBinding(StemmingCorrectionProvider.ID)
.to(StemmingCorrectionProvider.class);
parserCorrectionPlugins
.addBinding(PhoneticCorrectionProvider.ID)
.to(PhoneticCorrectionProvider.class);
parserCorrectionPlugins
.addBinding(MergedTermsCorrectionProvider.ID)
.to(MergedTermsCorrectionProvider.class);
}
@Override protected void configure() {
super.configure();
parserBinder = MapBinder.newMapBinder(binder(), new TypeLiteral<String>() {},
new TypeLiteral<IParser<ISpoofaxInputUnit, ISpoofaxParseUnit>>() {});
spoofaxParserBinder = MapBinder.newMapBinder(binder(), String.class, ISpoofaxParser.class);
analyzerBinder = MapBinder.newMapBinder(binder(), new TypeLiteral<String>() {},
new TypeLiteral<IAnalyzer<ISpoofaxParseUnit, ISpoofaxAnalyzeUnit, ISpoofaxAnalyzeUnitUpdate>>() {});
spoofaxAnalyzerBinder = MapBinder.newMapBinder(binder(), String.class, ISpoofaxAnalyzer.class);
Multibinder.newSetBinder(binder(), ClassLoader.class).permitDuplicates();
bindUnit();
bindSyntax();
bindParsers(parserBinder, spoofaxParserBinder);
bindAnalyzers(analyzerBinder, spoofaxAnalyzerBinder);
bindCompletion();
bindAction();
bindTransformer();
bindCategorizer();
bindStyler();
bindTracing();
bindOutline();
bindMenu();
bindDialog();
}
@Override
protected void configure()
{
bind(WatchStore.class).to(WatchStoreImpl.class);
MapBinder<String, EventSerializer> eventSerializerBinder =
MapBinder.newMapBinder(binder(), String.class, EventSerializer.class);
MapBinder<String, EventSerializerDescriptor> eventSerializerDescriptorBinder =
MapBinder.newMapBinder(binder(), String.class, EventSerializerDescriptor.class);
for (Class<? extends EventSerializer> eventSerializer : eventSerializers)
{
EventSerializerDescriptor descriptor = new EventSerializerDescriptor(eventSerializer);
eventSerializerBinder.addBinding(descriptor.getEventName()).to(eventSerializer);
eventSerializerDescriptorBinder.addBinding(descriptor.getEventName()).toInstance(descriptor);
}
MapBinder<String, EventHandler> eventHandlerBinder =
MapBinder.newMapBinder(binder(), String.class, EventHandler.class);
for (Class<? extends EventHandler> eventHandler : eventHandlers)
{
eventHandlerBinder.addBinding(eventHandler.getAnnotation(ProtobufEventHandler.class).eventName())
.to(eventHandler);
}
}
@Override
protected void configure() {
final Multibinder<Plugin> pluginMultibinder = Multibinder.newSetBinder(binder(), Plugin.class);
pluginMultibinder.addBinding().to(MyPlugin.class);
pluginMultibinder.addBinding().toInstance(new MyPlugin2());
final MapBinder<String, KeyedPlugin> keyedPluginMapBinder =
MapBinder.newMapBinder(binder(), String.class, KeyedPlugin.class);
keyedPluginMapBinder.addBinding("foo").to(MyKeyedPlugin.class);
keyedPluginMapBinder.addBinding("bar").toInstance(new MyKeyedPlugin2());
OptionalBinder.newOptionalBinder(binder(), OptService.class).setDefault().to(DefImpl.class);
install(new OverideModule());
}
private void bindCommonToolbarOptions() {
MapBinder<String, ToolbarOption> toolbarOptions =
MapBinder.newMapBinder(binder(), String.class, ToolbarOption.class);
Arrays.stream(CommonToolbarOptions.values()).forEach(
option -> toolbarOptions.addBinding(option.getTitle())
.toInstance(new CommonToolbarOption(option.getTitle())));
}
@Override
protected void configure() {
bind(JoynrRuntime.class).to(ClusterControllerRuntime.class).in(Singleton.class);
bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_DISCOVERY_GLOBAL_ADD_AND_REMOVE_TTL_MS))
.toInstance(jeeGlobalAddAndRemoveTtlMs);
bind(ScheduledExecutorService.class).annotatedWith(Names.named(MessageRouter.SCHEDULEDTHREADPOOL))
.toInstance(scheduledExecutorService);
bind(ScheduledExecutorService.class).annotatedWith(Names.named(JoynrInjectionConstants.JOYNR_SCHEDULER_CLEANUP))
.toInstance(scheduledExecutorService);
bind(ScheduledExecutorService.class).annotatedWith(Names.named(LocalCapabilitiesDirectory.JOYNR_SCHEDULER_CAPABILITIES_FRESHNESS))
.toInstance(scheduledExecutorService);
bind(ExecutorService.class).toInstance(scheduledExecutorService);
MapBinder<Class<? extends Address>, IMessagingSkeletonFactory> messagingSkeletonFactory;
messagingSkeletonFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
}, new TypeLiteral<IMessagingSkeletonFactory>() {
}, Names.named(MessagingSkeletonFactory.MIDDLEWARE_MESSAGING_SKELETON_FACTORIES));
MapBinder<Class<? extends Address>, AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>> messagingStubFactory;
messagingStubFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
}, new TypeLiteral<AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>>() {
}, Names.named(MessagingStubFactory.MIDDLEWARE_MESSAGING_STUB_FACTORIES));
Multibinder.newSetBinder(binder(), JoynrMessageProcessor.class);
install(new JeeHttpMessagingModule(messagingSkeletonFactory, messagingStubFactory));
install(new HttpBridgeEndpointRegistryClientModule());
install(new JeeMqttMessageSendingModule(messagingSkeletonFactory, messagingStubFactory));
}
@Override
protected void configure() {
LOG.debug("Configuring Bobcat module: {}", getClass().getSimpleName());
bind(SiteToolbar.class).to(SiteToolbarImpl.class);
bind(TemplateList.class).to(TemplateListImpl.class);
bind(CreatePageWizard.class).to(CreatePageWizardImpl.class);
bind(CreatePageProperties.class).to(CreatePagePropertiesImpl.class);
MapBinder<String, ActionWithData> siteAdminActions =
MapBinder.newMapBinder(binder(), String.class, ActionWithData.class);
siteAdminActions.addBinding(AemActions.CREATE_PAGE_VIA_SITEADMIN).to(CreatePageAction.class);
}
private void configureKernelStatesDependencies() {
// A map for KernelState instances to be provided at runtime.
MapBinder<Kernel.State, KernelState> stateMapBinder
= MapBinder.newMapBinder(binder(), Kernel.State.class, KernelState.class);
stateMapBinder.addBinding(Kernel.State.SHUTDOWN).to(KernelStateShutdown.class);
stateMapBinder.addBinding(Kernel.State.MODELLING).to(KernelStateModelling.class);
stateMapBinder.addBinding(Kernel.State.OPERATING).to(KernelStateOperating.class);
bind(OrderPoolConfiguration.class)
.toInstance(getConfigBindingProvider().get(OrderPoolConfiguration.PREFIX,
OrderPoolConfiguration.class));
transportOrderCleanupApprovalBinder();
orderSequenceCleanupApprovalBinder();
}
@Override
protected void configure() {
MapBinder<String, ProactiveReportHandler> handlers = MapBinder.newMapBinder(binder(), KEY_LITERAL, VALUE_LITERAL);
handlers.addBinding(VoiceService.StartPlaceRequest.ASSISTANT_ALEXA).to(AlexaProactiveReportHandler.class);
Multibinder<VoiceProvider> providerMultibinder = bindSetOf(VoiceProvider.class);
providerMultibinder.addBinding().to(AlexaService.class);
}
@Override
protected void configure() {
bind(AemAuthCookieFactory.class).to(AemAuthCookieFactoryImpl.class);
MapBinder<String, Action> siteAdminActions =
MapBinder.newMapBinder(binder(), String.class, Action.class);
siteAdminActions.addBinding(AemActions.LOG_IN).to(LogIn.class);
siteAdminActions.addBinding(AemActions.LOG_OUT).to(LogOut.class);
}
@Override
protected void configure() {
bind(SiteToolbar.class).to(SiteToolbarImpl.class);
bind(TemplateList.class).to(TemplateListImpl.class);
bind(CreatePageWizard.class).to(CreatePageWizardImpl.class);
bind(CreatePageProperties.class).to(CreatePagePropertiesImpl.class);
MapBinder<String, ActionWithData> siteAdminActions =
MapBinder.newMapBinder(binder(), String.class, ActionWithData.class);
siteAdminActions.addBinding(AemActions.CREATE_PAGE_VIA_SITEADMIN).to(CreatePageAction.class);
}
@Override
protected void configure() {
bind(IOutputGeneration.class).to(OutputGeneration.class);
MapBinder<String, ILifecycleTask> lifecycleTaskPlugins
= MapBinder.newMapBinder(binder(), String.class, ILifecycleTask.class);
lifecycleTaskPlugins.addBinding("ai.labs.output").to(OutputGenerationTask.class);
}
@Override
public void configure() {
bindConstant()
.annotatedWith(ResourceDexdumpName.class)
.to("/com/google/android/apps/common/testing/broker/dexdump_annotations");
bindConstant()
.annotatedWith(TestServicesApkResourceName.class)
.to(
"/services/test_services.apk");
bindConstant()
.annotatedWith(OdoApkResourceName.class)
.to(
"/runner/android_test_orchestrator/stubapp/stubapp.apk");
bind(AdbController.AdbControllerFactory.class).to(AdbController.FullControlAdbControllerFactory.class);
bind(String.class)
.annotatedWith(ExecutorLocation.class)
.toProvider(
new ResourceProvider(
Providers.of("/com/google/android/apps/common/testing/broker/executor.sh")))
.in(Scopes.SINGLETON);
bind(String.class).annotatedWith(OdoApkLocation.class).toProvider(
new ResourceProvider(getProvider(Key.get(String.class, OdoApkResourceName.class))))
.in(Scopes.SINGLETON);
bind(String.class)
.annotatedWith(TestServicesApkLocation.class)
.toProvider(
new ResourceProvider(
getProvider(Key.get(String.class, TestServicesApkResourceName.class))))
.in(Scopes.SINGLETON);
bind(String.class).annotatedWith(ResourceDexdumpPath.class).toProvider(
new ResourceProvider(getProvider(Key.get(String.class, ResourceDexdumpName.class))))
.in(Scopes.SINGLETON);
Multibinder.newSetBinder(binder(), DeviceBrokerDecorator.class);
MapBinder.newMapBinder(binder(), DeviceBrokerType.class, DeviceBroker.class);
MapBinder<String, String> adbEnv =
MapBinder.newMapBinder(binder(), String.class, String.class, AdbEnvironment.class);
adbEnv.addBinding(ENVIRONMENT_KEY_ANDROID_ADB).to(Key.get(String.class, AdbPath.class));
}
@Override
protected void configure() {
bind(Dispatcher.class).to(NotificationDispatcher.class);
bind(NotificationAuditor.class).to(CassandraAuditor.class);
bind(RetryManager.class).to(BackoffRetryManager.class);
bind(RetryProcessor.class).to(ScheduledRetryProcessor.class);
bind(NotificationMessageRenderer.class).to(TemplateMessageRenderer.class);
bind(NotificationProviderRegistry.class).to(MapNotificationProviderRegistry.class);
switch (apnsSender) {
default:
logger.warn("unknown apns sender implementation {}: using default instead");
// fall through
case "default":
case "pushy":
logger.info("using pushy apns sender");
bind(ApnsSender.class).to(PushyApnsSender.class);
break;
case "noop":
logger.warn("using noop apns sender");
bind(ApnsSender.class).to(NoopApnsSender.class);
break;
}
switch (gcmSender) {
default:
logger.warn("unknown gcm sender implementation {}: using default instead");
// fall through
case "default":
case "smack":
logger.info("using smack gcm sender");
bind(GcmSender.class).to(SmackGcmSender.class);
break;
case "noop":
logger.warn("using noop gcm sender");
bind(GcmSender.class).to(NoopGcmSender.class);
break;
}
bind(UpstreamNotificationResponder.class).to(IrisUpstreamNotificationResponder.class);
bind(NotificationService.class).asEagerSingleton();
MapBinder<String, NotificationProvider> registryBinder = MapBinder.newMapBinder(binder(), String.class, NotificationProvider.class);
registryBinder.addBinding("LOG").to(LogProvider.class);
registryBinder.addBinding("GCM").to(GCMProvider.class);
registryBinder.addBinding("APNS").to(ApnsProvider.class);
registryBinder.addBinding("EMAIL").to(EmailProvider.class);
registryBinder.addBinding("IVR").to(IVRProvider.class);
registryBinder.addBinding("WEBHOOK").to(WebhookProvider.class);
}
@Override
protected void configure() {
MapBinder<String, Source> sourceBindings = MapBinder.newMapBinder(binder(), String.class, Source.class);
sourceBindings.addBinding("simple").to(SimpleSource.class);
}
public static MapBinder<String, ScoringEventObserver<DocLevelEventArg, DocLevelEventArg>> docLevelEventArgObserverBindingSite(final Binder binder) {
return MapBinder.newMapBinder(binder, TypeLiteral.get(String.class),
new TypeLiteral<ScoringEventObserver<DocLevelEventArg, DocLevelEventArg>>() {
});
}
protected <K, V> MapBinder<K, V> bindMapOf(TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
return MapBinder.newMapBinder(binder(), keyType, valueType);
}
@Override
protected void configure() {
MapBinder<String, Exports> exportsBindings = MapBinder.newMapBinder(binder(), String.class, Exports.class);
exportsBindings.addBinding("mydummymodule").to(MyDummyExport.class);
}
@Override
protected void configure() {
MapBinder<DeviceBrokerType, DeviceBroker> mapbinder =
MapBinder.newMapBinder(binder(), DeviceBrokerType.class, DeviceBroker.class);
mapbinder.addBinding(DeviceBrokerType.WRAPPED_EMULATOR).to(WrappedEmulatedDeviceBroker.class);
}
/**
* Contribute a message handler for some extended message type.
* <p>See BEP-10 for details on protocol extensions.
* <p>Binding key is a unique message type ID, that will be communicated to a peer
* during the extended handshake procedure in the 'm' dictionary of an extended handshake message.
*
* @since 1.0
* @deprecated since 1.5 in favor of {@link ProtocolModuleExtender#addExtendedMessageHandler(String, Class)}
* and its' overloaded versions
*/
@Deprecated
public static MapBinder<String, MessageHandler<? extends ExtendedMessage>> contributeExtendedMessageHandler(Binder binder) {
return MapBinder.newMapBinder(
binder,
new TypeLiteral<String>(){},
new TypeLiteral<MessageHandler<? extends ExtendedMessage>>(){},
ExtendedMessageHandlers.class);
}