Java Code Examples for com.google.inject.Binder

The following are top voted examples for showing how to use com.google.inject.Binder. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: jboot   File: JbootInjectManager.java   Source Code and License 6 votes vote down vote up
/**
 * auto bind interface impl
 *
 * @param binder
 */
private void beanBind(Binder binder) {

    List<Class> classes = ClassScanner.scanClassByAnnotation(Bean.class, true);
    for (Class impl : classes) {
        Class<?>[] interfaceClasses = impl.getInterfaces();
        Bean bean = (Bean) impl.getAnnotation(Bean.class);
        String name = bean.name();
        for (Class interfaceClass : interfaceClasses) {
            if (interfaceClass == Serializable.class) {
                continue;
            }
            try {
                if (StringUtils.isBlank(name)) {
                    binder.bind(interfaceClass).to(impl);
                } else {
                    binder.bind(interfaceClass).annotatedWith(Names.named(name)).to(impl);
                }
            } catch (Throwable ex) {
                System.err.println(String.format("can not bind [%s] to [%s]", interfaceClass, impl));
            }
        }
    }
}
 
Example 2
Project: vars-annotation   File: MBARIInjectorModule.java   Source Code and License 6 votes vote down vote up
private void configurePanoptes(Binder binder) {
    String endpoint = config.getString("panoptes.service.url");
    String clientSecret = config.getString("panoptes.service.client.secret");
    Duration timeout = config.getDuration("panoptes.service.timeout");
    PanoptesWebServiceFactory factory = new PanoptesWebServiceFactory(endpoint, timeout);
    RetrofitServiceFactory authFactory = new BasicJWTAuthServiceFactorySC(endpoint, timeout);
    AuthService authService = new BasicJWTAuthService(authFactory,
            new Authorization("APIKEY", clientSecret));
    binder.bind(String.class)
            .annotatedWith(Names.named("PANOPTES_ENDPOINT"))
            .toInstance(endpoint);
    binder.bind(AuthService.class)
            .annotatedWith(Names.named("PANOPTES_AUTH"))
            .toInstance(authService);
    PanoptesService service = new PanoptesService(factory, authService);
    binder.bind(Long.class)
            .annotatedWith(Names.named("PANOPTES_TIMEOUT"))
            .toInstance(timeout.toMillis());
    binder.bind(PanoptesWebServiceFactory.class).toInstance(factory);
    binder.bind(ImageArchiveService.class).toInstance(service);

}
 
Example 3
Project: hadoop   File: TestNodesPage.java   Source Code and License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  final RMContext mockRMContext =
      TestRMWebApp.mockRMContext(3, numberOfRacks, numberOfNodesPerRack,
        8 * TestRMWebApp.GiB);
  injector =
      WebAppTests.createMockInjector(RMContext.class, mockRMContext,
        new Module() {
          @Override
          public void configure(Binder binder) {
            try {
              binder.bind(ResourceManager.class).toInstance(
                TestRMWebApp.mockRm(mockRMContext));
            } catch (IOException e) {
              throw new IllegalStateException(e);
            }
          }
        });
}
 
Example 4
Project: presto-manager   File: DynamicAnnouncementBinder.java   Source Code and License 5 votes vote down vote up
protected DynamicAnnouncementBinder(Binder binder)
{
    keyBinder = newSetBinder(binder,
            SERVICE_PROPERTY_TYPE,
            ForDynamicAnnouncements.class);
    getterBinder = newMapBinder(binder,
            SERVICE_PROPERTY_TYPE,
            new TypeLiteral<Function<Object, String>>() {},
            ForDynamicAnnouncements.class);
    objectBinder = newMapBinder(binder,
            SERVICE_PROPERTY_TYPE,
            new TypeLiteral<Object>() {},
            ForDynamicAnnouncements.class);
}
 
Example 5
Project: drift   File: ThriftCodecModule.java   Source Code and License 5 votes vote down vote up
@Override
public void configure(Binder binder)
{
    binder.bind(ThriftCodecFactory.class).to(CompilerThriftCodecFactory.class).in(Scopes.SINGLETON);
    binder.bind(ThriftCatalog.class).in(Scopes.SINGLETON);
    binder.bind(ThriftCodecManager.class).in(Scopes.SINGLETON);
    newSetBinder(binder, new TypeLiteral<ThriftCodec<?>>() {}, InternalThriftCodec.class).permitDuplicates();

    binder.bind(ClassLoader.class)
            .annotatedWith(ForCompiler.class)
            .toInstance(parent);
}
 
Example 6
Project: Wechat-Group   File: ApiTestModule.java   Source Code and License 5 votes vote down vote up
@Override
public void configure(Binder binder) {
  try (InputStream is1 = ClassLoader
      .getSystemResourceAsStream("test-config.xml")) {
    WxXmlCpInMemoryConfigStorage config = fromXml(
        WxXmlCpInMemoryConfigStorage.class, is1);
    WxCpServiceImpl wxService = new WxCpServiceImpl();
    wxService.setWxCpConfigStorage(config);

    binder.bind(WxCpServiceImpl.class).toInstance(wxService);
    binder.bind(WxCpConfigStorage.class).toInstance(config);
  } catch (IOException e) {
    e.printStackTrace();
  }
}
 
Example 7
Project: violet   File: DuplexBinder.java   Source Code and License 5 votes vote down vote up
/**
 * Creates a new duplex binder.
 *
 * @param binder the enclosing (public) binder
 * @return a new duplex binder
 */
@NonNull
static DuplexBinder create(@NonNull final Binder binder) {
  if(binder instanceof DuplexBinder) {
    return (DuplexBinder) binder;
  }
  return new DuplexBinderImpl(binder, binder.newPrivateBinder());
}
 
Example 8
Project: presto-manager   File: DynamicAnnouncementModule.java   Source Code and License 5 votes vote down vote up
@Override
public void configure(Binder binder)
{
    httpClientBinder(binder).addGlobalFilterBinding()
            .to(DynamicAnnouncementFilter.class)
            .asEagerSingleton();

    jsonCodecBinder(binder).bindJsonCodec(JsonAnnouncement.class);

    // Initialize various multibinders
    DynamicAnnouncementBinder.dynamicAnnouncementBinder(binder);
}
 
Example 9
Project: solidity-ide   File: SolidityCompilerModule.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void configure(Binder binder) {
	try {
		// try to instantiate platform specific implementation
		// will fail currently on Mac, thus the binding does not happen there
		Class<? extends ISolidityCompiler> solidityCompilerClass = (Class<? extends ISolidityCompiler>) Class
				.forName("com.yakindu.solidity.compiler.builder.SolidityCompiler");
		binder.bind(ISolidityCompiler.class).to(solidityCompilerClass);
	} catch (ClassNotFoundException e) {
		System.err.println("SolidityCompilerModule: " + e.getMessage());
	}
	binder.bind(IPreferenceStore.class)
			.toInstance((IPreferenceStore) SolidityActivator.getInstance().getPreferenceStore());
}
 
Example 10
Project: EasyController   File: ActionModule.java   Source Code and License 5 votes vote down vote up
@Override
public void configure(Binder binder) {
    binder.bind(ActionMapping.class).toInstance(new ActionMapping());
    binder.bind(ActionHandler.class).toInstance(new ActionHandler());

    binder.bind(ViewFactory.class).to(DefaultViewFactory.class).in(Singleton.class);
    binder.bind(ViewResolver.class).to(DefaultViewResolver.class).in(Singleton.class);

    configureCaptcha(binder);
}
 
Example 11
Project: Equella   File: ListProvider.java   Source Code and License 5 votes vote down vote up
public ListProvider(Binder binder, List<Class<? extends T>> clazzes)
{
	this.binder = binder;
	this.clazzes.addAll(clazzes);
	for( Class<? extends T> clazz : clazzes )
	{
		binder.bind(clazz);
	}
}
 
Example 12
Project: n4js   File: N4JSUiModule.java   Source Code and License 5 votes vote down vote up
/**
 * Binds a specific label provider for the content assist use case.
 */
@Override
public void configureContentProposalLabelProvider(com.google.inject.Binder binder) {
	binder.bind(org.eclipse.jface.viewers.ILabelProvider.class)
			.annotatedWith(org.eclipse.xtext.ui.editor.contentassist.ContentProposalLabelProvider.class)
			.to(N4JSContentAssistLabelProvider.class);
}
 
Example 13
Project: ProjectAres   File: SetBinder.java   Source Code and License 5 votes vote down vote up
protected SetBinder(Binder binder, @Nullable Key<T> key) {
    if(key == null) {
        key = Key.get(new ResolvableType<T>(){}.in(getClass()));
    }

    this.binder = binder.skipSources(SetBinder.class);
    this.elementType = key.getTypeLiteral();
    this.collectionType = new ResolvableType<Set<T>>(){}.with(new TypeArgument<T>(this.elementType){});
    this.multibinder = Multibinder.newSetBinder(binder, key);
}
 
Example 14
Project: presto-ethereum   File: EthereumConnectorModule.java   Source Code and License 5 votes vote down vote up
@Override
public void configure(Binder binder) {
    binder.bind(EthereumConnector.class).in(Scopes.SINGLETON);
    binder.bind(EthereumMetadata.class).in(Scopes.SINGLETON);
    binder.bind(EthereumWeb3jProvider.class).in(Scopes.SINGLETON);

    binder.bind(EthereumSplitManager.class).in(Scopes.SINGLETON);
    binder.bind(EthereumRecordSetProvider.class).in(Scopes.SINGLETON);

    configBinder(binder).bindConfig(EthereumConnectorConfig.class);
    jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
}
 
Example 15
Project: vars-annotation   File: MBARIInjectorModule.java   Source Code and License 5 votes vote down vote up
private void configureConceptService(Binder binder) {
    String endpoint = config.getString("concept.service.url");
    Duration timeout = config.getDuration("concept.service.timeout");
    KBWebServiceFactory factory = new KBWebServiceFactory(endpoint, timeout, defaultExecutor);
    KBConceptService service = new KBConceptService(factory);
    // --- Using a local cache
    CachedConceptService cachedService = new CachedConceptService(service);
    List<String> cachedConceptTemplates = config.getStringList("app.annotation.details.cache");
    cachedService.prefetch(cachedConceptTemplates);
    binder.bind(String.class)
            .annotatedWith(Names.named("CONCEPT_ENDPOINT"))
            .toInstance(endpoint);
    binder.bind(KBWebServiceFactory.class).toInstance(factory);
    binder.bind(ConceptService.class).toInstance(cachedService);
}
 
Example 16
Project: n4js   File: N4JSRuntimeModule.java   Source Code and License 5 votes vote down vote up
/**
 * Sets the scope provider to use as delegate for the local scope provider. This delegate is used to handle imported
 * elements. The customization makes elements that name is equal to the resource name both referenceable by e.g
 * my/pack/A/A as well as my/pack/A if the resource name is A. In this delegate later the import of the built in
 * types should be made.
 */
public void configureIScopeProviderDelegate(Binder binder) {
	binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class)
			.annotatedWith(
					com.google.inject.name.Names
							.named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE))
			.to(N4JSImportedNamespaceAwareLocalScopeProvider.class);
}
 
Example 17
Project: n4js   File: N4JSRuntimeModule.java   Source Code and License 5 votes vote down vote up
/** Configures the formatter preference value provider */
@Override
public void configureFormatterPreferences(Binder binder) {
	binder
			.bind(IPreferenceValuesProvider.class)
			.annotatedWith(FormatterPreferences.class)
			.to(N4JSSimpleFormattingPreferenceProvider.class);
}
 
Example 18
Project: incubator-netbeans   File: ExtensionModule.java   Source Code and License 5 votes vote down vote up
@Override
    public void configure(Binder binder) {
        binder.bind(PluginDependenciesResolver.class).to(NbPluginDependenciesResolver.class);
        binder.bind(Roles.componentKey(RepositoryConnectorFactory.class, "offline")).to(OfflineConnector.class);
        //#212214 the EnhancedLocalRepositoryManager will claim artifact is not locally present even if file is there but some metadata is missing
        //we just replace it with the simple variant that relies on file's presence only. 
        //I'm a bit afraid to remove the binding altogether, that's why we map simple to enhanced.
        binder.bind(Roles.componentKey(LocalRepositoryManagerFactory.class, "enhanced")).to(SimpleLocalRepositoryManagerFactory.class);
        
        //exxperimental only.
//        binder.bind(InheritanceAssembler.class).to(NbInheritanceAssembler.class);
        binder.bind(ModelBuilder.class).to(NBModelBuilder.class);
    }
 
Example 19
Project: hadoop   File: TestRMWebAppFairScheduler.java   Source Code and License 5 votes vote down vote up
@Test
public void testFairSchedulerWebAppPage() {
  List<RMAppState> appStates = Arrays.asList(RMAppState.NEW,
      RMAppState.NEW_SAVING, RMAppState.SUBMITTED);
  final RMContext rmContext = mockRMContext(appStates);
  Injector injector = WebAppTests.createMockInjector(RMContext.class,
      rmContext,
      new Module() {
        @Override
        public void configure(Binder binder) {
          try {
            ResourceManager mockRmWithFairScheduler =
                mockRm(rmContext);
            binder.bind(ResourceManager.class).toInstance
                (mockRmWithFairScheduler);
            binder.bind(ApplicationBaseProtocol.class).toInstance(
              mockRmWithFairScheduler.getClientRMService());
          } catch (IOException e) {
            throw new IllegalStateException(e);
          }
        }
      });
  FairSchedulerPage fsViewInstance = injector.getInstance(FairSchedulerPage
      .class);
  fsViewInstance.render();
  WebAppTests.flushOutput(injector);
}
 
Example 20
Project: org.xtext.dsl.restaurante   File: AbstractRestauranteUiModule.java   Source Code and License 4 votes vote down vote up
public void configureBuilderPreferenceStoreInitializer(Binder binder) {
	binder.bind(IPreferenceStoreInitializer.class)
		.annotatedWith(Names.named("builderPreferenceInitializer"))
		.to(BuilderPreferenceAccess.Initializer.class);
}
 
Example 21
Project: empiria.player   File: ItemDataProviderJUnitTest.java   Source Code and License 4 votes vote down vote up
@Override
public void configure(Binder binder) {
    binder.bind(DataSourceManager.class).toInstance(dataSourceManager);
    binder.bind(PageScopeFactory.class).toInstance(pageScopeFactory);
}
 
Example 22
Project: SurveyDSL   File: AbstractQueryITRuntimeModule.java   Source Code and License 4 votes vote down vote up
public void configureIgnoreCaseLinking(com.google.inject.Binder binder) {
	binder.bindConstant().annotatedWith(org.eclipse.xtext.scoping.IgnoreCaseLinking.class).to(false);
}
 
Example 23
Project: SurveyDSL   File: AbstractQueryITRuntimeModule.java   Source Code and License 4 votes vote down vote up
public void configureIScopeProviderDelegate(com.google.inject.Binder binder) {
	binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class).annotatedWith(com.google.inject.name.Names.named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(org.eclipse.xtext.scoping.impl.SimpleLocalScopeProvider.class);
}
 
Example 24
Project: pokemon-tcgo-deck-generator   File: AbstractPkmntcgoRuntimeModule.java   Source Code and License 4 votes vote down vote up
public void configureIResourceDescriptions(Binder binder) {
	binder.bind(IResourceDescriptions.class).to(ResourceSetBasedResourceDescriptions.class);
}
 
Example 25
Project: OCCI-Studio   File: AbstractOCCIUiModule.java   Source Code and License 4 votes vote down vote up
public void configureResourceUIServiceLabelProvider(Binder binder) {
	binder.bind(ILabelProvider.class).annotatedWith(ResourceServiceDescriptionLabelProvider.class).to(OCCIDescriptionLabelProvider.class);
}
 
Example 26
Project: gw4e.project   File: AbstractDSLPoliciesUiModule.java   Source Code and License 4 votes vote down vote up
public void configureResourceUIServiceLabelProvider(Binder binder) {
	binder.bind(ILabelProvider.class).annotatedWith(ResourceServiceDescriptionLabelProvider.class).to(DSLPoliciesDescriptionLabelProvider.class);
}
 
Example 27
Project: ProjectAres   File: MessageBinder.java   Source Code and License 4 votes vote down vote up
public MessageBinder(Binder binder) {
    this.messages = Multibinder.newSetBinder(binder, new Key<MessageMeta<?>>(){});
}
 
Example 28
Project: ProjectAres   File: SetBinder.java   Source Code and License 4 votes vote down vote up
protected SetBinder(Binder binder, @Nullable TypeLiteral<T> type) {
    this(binder, type == null ? null : Key.get(type));
}
 
Example 29
Project: org.xtext.dsl.restaurante   File: AbstractRestauranteUiModule.java   Source Code and License 4 votes vote down vote up
public void configureHighlightingTokenDefProvider(Binder binder) {
	binder.bind(ITokenDefProvider.class)
		.annotatedWith(Names.named(LexerIdeBindings.HIGHLIGHTING))
		.to(AntlrTokenDefProvider.class);
}
 
Example 30
Project: gemoc-studio   File: AbstractGExpressionsRuntimeModule.java   Source Code and License 4 votes vote down vote up
public void configureFileExtensions(Binder binder) {
	if (properties == null || properties.getProperty(Constants.FILE_EXTENSIONS) == null)
		binder.bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("gexpressions");
}
 
Example 31
Project: empiria.player   File: HTML5VideoMediaWrapperJUnitTest.java   Source Code and License 4 votes vote down vote up
@Override
public void configure(Binder binder) {
    binder.install(new FactoryModuleBuilder().build(MediaWrapperFactory.class));
}
 
Example 32
Project: bromium   File: AbstractBromiumUiModule.java   Source Code and License 4 votes vote down vote up
public void configureHighlightingTokenDefProvider(Binder binder) {
	binder.bind(ITokenDefProvider.class)
		.annotatedWith(Names.named(LexerIdeBindings.HIGHLIGHTING))
		.to(AntlrTokenDefProvider.class);
}
 
Example 33
Project: Xtext_Xtend_HTML_Generator   File: AbstractMyDslRuntimeModule.java   Source Code and License 4 votes vote down vote up
public void configureIgnoreCaseLinking(Binder binder) {
	binder.bindConstant().annotatedWith(IgnoreCaseLinking.class).to(false);
}
 
Example 34
Project: n4js   File: DefaultTestTreeTransformerModule.java   Source Code and License 4 votes vote down vote up
@Override
public void configure(final Binder binder) {
	binder.bind(TestTreeTransformer.class).to(DefaultTestTreeTransformer.class);
}
 
Example 35
Project: SurveyDSL   File: AbstractQueryITRuntimeModule.java   Source Code and License 4 votes vote down vote up
@Override
public void configure(Binder binder) {
	properties = tryBindProperties(binder, "xtext/QueryIT.properties");
	super.configure(binder);
}
 
Example 36
Project: ProjectAres   File: MockBinder.java   Source Code and License 4 votes vote down vote up
public MockBinder(Binder binder) {
    this.binder = binder;
}
 
Example 37
Project: Saturn   File: AbstractKronusRuntimeModule.java   Source Code and License 4 votes vote down vote up
public void configureLanguageName(Binder binder) {
	binder.bind(String.class).annotatedWith(Names.named(Constants.LANGUAGE_NAME)).toInstance("com.ms.qaTools.saturn.Kronus");
}
 
Example 38
Project: n4js   File: AbstractTypesRuntimeModule.java   Source Code and License 4 votes vote down vote up
public void configureFileExtensions(Binder binder) {
	if (properties == null || properties.getProperty(Constants.FILE_EXTENSIONS) == null)
		binder.bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("n4ts");
}
 
Example 39
Project: Xtext_Xtend_HTML_Generator   File: AbstractMyDslUiModule.java   Source Code and License 4 votes vote down vote up
public void configureResourceUIServiceLabelProvider(Binder binder) {
	binder.bind(ILabelProvider.class).annotatedWith(ResourceServiceDescriptionLabelProvider.class).to(MyDslDescriptionLabelProvider.class);
}
 
Example 40
Project: bromium   File: AbstractBromiumUiModule.java   Source Code and License 4 votes vote down vote up
public void configureIPreferenceStoreInitializer(Binder binder) {
	binder.bind(IPreferenceStoreInitializer.class)
		.annotatedWith(Names.named("RefactoringPreferences"))
		.to(RefactoringPreferences.Initializer.class);
}