Java 类com.google.inject.Binder 实例源码

项目:jboot    文件:JbootInjectManager.java   
/**
 * 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));
            }
        }
    }
}
项目:vars-annotation    文件:MBARIInjectorModule.java   
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);

}
项目:hadoop    文件:TestNodesPage.java   
@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);
            }
          }
        });
}
项目:presto-manager    文件:DynamicAnnouncementBinder.java   
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);
}
项目:drift    文件:ThriftCodecModule.java   
@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);
}
项目:Wechat-Group    文件:ApiTestModule.java   
@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();
  }
}
项目:violet    文件:DuplexBinder.java   
/**
 * 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());
}
项目:presto-manager    文件:DynamicAnnouncementModule.java   
@Override
public void configure(Binder binder)
{
    httpClientBinder(binder).addGlobalFilterBinding()
            .to(DynamicAnnouncementFilter.class)
            .asEagerSingleton();

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

    // Initialize various multibinders
    DynamicAnnouncementBinder.dynamicAnnouncementBinder(binder);
}
项目:solidity-ide    文件:SolidityCompilerModule.java   
@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());
}
项目:EasyController    文件:ActionModule.java   
@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);
}
项目:Equella    文件:ListProvider.java   
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);
    }
}
项目:n4js    文件:N4JSUiModule.java   
/**
 * 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);
}
项目:ProjectAres    文件:SetBinder.java   
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);
}
项目:presto-ethereum    文件:EthereumConnectorModule.java   
@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);
}
项目:vars-annotation    文件:MBARIInjectorModule.java   
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);
}
项目:n4js    文件:N4JSRuntimeModule.java   
/**
 * 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);
}
项目:n4js    文件:N4JSRuntimeModule.java   
/** Configures the formatter preference value provider */
@Override
public void configureFormatterPreferences(Binder binder) {
    binder
            .bind(IPreferenceValuesProvider.class)
            .annotatedWith(FormatterPreferences.class)
            .to(N4JSSimpleFormattingPreferenceProvider.class);
}
项目:incubator-netbeans    文件:ExtensionModule.java   
@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);
    }
项目:hadoop    文件:TestRMWebAppFairScheduler.java   
@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);
}
项目:org.xtext.dsl.restaurante    文件:AbstractRestauranteUiModule.java   
public void configureBuilderPreferenceStoreInitializer(Binder binder) {
    binder.bind(IPreferenceStoreInitializer.class)
        .annotatedWith(Names.named("builderPreferenceInitializer"))
        .to(BuilderPreferenceAccess.Initializer.class);
}
项目:empiria.player    文件:ItemDataProviderJUnitTest.java   
@Override
public void configure(Binder binder) {
    binder.bind(DataSourceManager.class).toInstance(dataSourceManager);
    binder.bind(PageScopeFactory.class).toInstance(pageScopeFactory);
}
项目:SurveyDSL    文件:AbstractQueryITRuntimeModule.java   
public void configureIgnoreCaseLinking(com.google.inject.Binder binder) {
    binder.bindConstant().annotatedWith(org.eclipse.xtext.scoping.IgnoreCaseLinking.class).to(false);
}
项目:SurveyDSL    文件:AbstractQueryITRuntimeModule.java   
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);
}
项目:pokemon-tcgo-deck-generator    文件:AbstractPkmntcgoRuntimeModule.java   
public void configureIResourceDescriptions(Binder binder) {
    binder.bind(IResourceDescriptions.class).to(ResourceSetBasedResourceDescriptions.class);
}
项目:OCCI-Studio    文件:AbstractOCCIUiModule.java   
public void configureResourceUIServiceLabelProvider(Binder binder) {
    binder.bind(ILabelProvider.class).annotatedWith(ResourceServiceDescriptionLabelProvider.class).to(OCCIDescriptionLabelProvider.class);
}
项目:gw4e.project    文件:AbstractDSLPoliciesUiModule.java   
public void configureResourceUIServiceLabelProvider(Binder binder) {
    binder.bind(ILabelProvider.class).annotatedWith(ResourceServiceDescriptionLabelProvider.class).to(DSLPoliciesDescriptionLabelProvider.class);
}
项目:ProjectAres    文件:MessageBinder.java   
public MessageBinder(Binder binder) {
    this.messages = Multibinder.newSetBinder(binder, new Key<MessageMeta<?>>(){});
}
项目:ProjectAres    文件:SetBinder.java   
protected SetBinder(Binder binder, @Nullable TypeLiteral<T> type) {
    this(binder, type == null ? null : Key.get(type));
}
项目:org.xtext.dsl.restaurante    文件:AbstractRestauranteUiModule.java   
public void configureHighlightingTokenDefProvider(Binder binder) {
    binder.bind(ITokenDefProvider.class)
        .annotatedWith(Names.named(LexerIdeBindings.HIGHLIGHTING))
        .to(AntlrTokenDefProvider.class);
}
项目:gemoc-studio    文件:AbstractGExpressionsRuntimeModule.java   
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");
}
项目:empiria.player    文件:HTML5VideoMediaWrapperJUnitTest.java   
@Override
public void configure(Binder binder) {
    binder.install(new FactoryModuleBuilder().build(MediaWrapperFactory.class));
}
项目:bromium    文件:AbstractBromiumUiModule.java   
public void configureHighlightingTokenDefProvider(Binder binder) {
    binder.bind(ITokenDefProvider.class)
        .annotatedWith(Names.named(LexerIdeBindings.HIGHLIGHTING))
        .to(AntlrTokenDefProvider.class);
}
项目:Xtext_Xtend_HTML_Generator    文件:AbstractMyDslRuntimeModule.java   
public void configureIgnoreCaseLinking(Binder binder) {
    binder.bindConstant().annotatedWith(IgnoreCaseLinking.class).to(false);
}
项目:n4js    文件:DefaultTestTreeTransformerModule.java   
@Override
public void configure(final Binder binder) {
    binder.bind(TestTreeTransformer.class).to(DefaultTestTreeTransformer.class);
}
项目:SurveyDSL    文件:AbstractQueryITRuntimeModule.java   
@Override
public void configure(Binder binder) {
    properties = tryBindProperties(binder, "xtext/QueryIT.properties");
    super.configure(binder);
}
项目:ProjectAres    文件:MockBinder.java   
public MockBinder(Binder binder) {
    this.binder = binder;
}
项目:Saturn    文件:AbstractKronusRuntimeModule.java   
public void configureLanguageName(Binder binder) {
    binder.bind(String.class).annotatedWith(Names.named(Constants.LANGUAGE_NAME)).toInstance("com.ms.qaTools.saturn.Kronus");
}
项目:n4js    文件:AbstractTypesRuntimeModule.java   
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");
}
项目:Xtext_Xtend_HTML_Generator    文件:AbstractMyDslUiModule.java   
public void configureResourceUIServiceLabelProvider(Binder binder) {
    binder.bind(ILabelProvider.class).annotatedWith(ResourceServiceDescriptionLabelProvider.class).to(MyDslDescriptionLabelProvider.class);
}
项目:bromium    文件:AbstractBromiumUiModule.java   
public void configureIPreferenceStoreInitializer(Binder binder) {
    binder.bind(IPreferenceStoreInitializer.class)
        .annotatedWith(Names.named("RefactoringPreferences"))
        .to(RefactoringPreferences.Initializer.class);
}