当前位置: 首页>>代码示例>>Java>>正文


Java Binder类代码示例

本文整理汇总了Java中org.glassfish.hk2.utilities.Binder的典型用法代码示例。如果您正苦于以下问题:Java Binder类的具体用法?Java Binder怎么用?Java Binder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Binder类属于org.glassfish.hk2.utilities包,在下文中一共展示了Binder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ResourceConfig

import org.glassfish.hk2.utilities.Binder; //导入依赖的package包/类
/**
 * Constructor.
 *
 * @throws ClassNotFoundException if a class was not found when attempting to load it
 * @throws InstantiationException if a class was not able to be instantiated
 * @throws IllegalAccessException if there was a problem accessing something due to security restrictions
 */
public ResourceConfig() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    // Build the binder using the configured factory
    Class<?> binderClass = Class.forName(bindingFactory);
    BinderFactory binderFactory = (BinderFactory) binderClass.newInstance();
    Binder binder = binderFactory.buildBinder();

    // Register Instrumentation
    register(new InstrumentedResourceMethodApplicationListener(MetricRegistryFactory.getRegistry()));
    registerMetricsAppender();

    register(binder);
    registerFilters();

    // Call post-registration hook to allow for additional registration
    binderFactory.afterRegistration(this);
}
 
开发者ID:yahoo,项目名称:fili,代码行数:24,代码来源:ResourceConfig.java

示例2: testLog4J

import org.glassfish.hk2.utilities.Binder; //导入依赖的package包/类
@Test
public void testLog4J()
{
    AbstractBinder binder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            install(loginject(Logger.class, LogManager::getLogger, currentClass()).as(Binder.class));
            addActiveDescriptor(TestClass.class);
        }
    };
    ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(testName.getMethodName(), binder);
    TestClass service = serviceLocator.getService(TestClass.class);
    assertEquals(TestClass.class.getName(), service.logger.getName());
}
 
开发者ID:raner,项目名称:loginject,代码行数:17,代码来源:LogInjectLog4JTest.java

示例3: testInferredLog4J

import org.glassfish.hk2.utilities.Binder; //导入依赖的package包/类
@Test
public void testInferredLog4J()
{
    AbstractBinder binder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            install(loginject(LogManager::getLogger, currentClass()).as(Binder.class));
            addActiveDescriptor(TestClass.class);
        }
    };
    ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(testName.getMethodName(), binder);
    TestClass service = serviceLocator.getService(TestClass.class);
    assertEquals(TestClass.class.getName(), service.logger.getName());
}
 
开发者ID:raner,项目名称:loginject,代码行数:17,代码来源:LogInjectLog4JTest.java

示例4: testGetLoggerWithoutParameters

import org.glassfish.hk2.utilities.Binder; //导入依赖的package包/类
@Test
public void testGetLoggerWithoutParameters()
{
    AbstractBinder binder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            install(loginject(Logger.class, Logger::getAnonymousLogger).as(Binder.class));
            addActiveDescriptor(TestClass.class);
        }
    };
    ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(testName.getMethodName(), binder);
    TestClass service = serviceLocator.getService(TestClass.class);
    assertNull(service.injectedLogger.getName());
}
 
开发者ID:raner,项目名称:loginject,代码行数:17,代码来源:JavaUtilLoggingLoggerTest.java

示例5: testGetLoggerWithStringParameter

import org.glassfish.hk2.utilities.Binder; //导入依赖的package包/类
@Test
public void testGetLoggerWithStringParameter()
{
	AbstractBinder binder = new AbstractBinder()
	{
		@Override
		protected void configure()
		{
			install(loginject(Logger.class, Logger::getLogger, currentClassName()).as(Binder.class));
			addActiveDescriptor(TestClass.class);
		}
	};
	ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(testName.getMethodName(), binder);
	TestClass service = serviceLocator.getService(TestClass.class);
	assertEquals(TestClass.class.getName(), service.injectedLogger.getName());
}
 
开发者ID:raner,项目名称:loginject,代码行数:17,代码来源:JavaUtilLoggingLoggerTest.java

示例6: testGetInferredLoggerWithStringParameter

import org.glassfish.hk2.utilities.Binder; //导入依赖的package包/类
@Test
public void testGetInferredLoggerWithStringParameter()
{
    AbstractBinder binder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            install(loginject(Logger::getLogger, currentClassName()).as(Binder.class));
            addActiveDescriptor(TestClass.class);
        }
    };
    ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(testName.getMethodName(), binder);
    TestClass service = serviceLocator.getService(TestClass.class);
    assertEquals(TestClass.class.getName(), service.injectedLogger.getName());
}
 
开发者ID:raner,项目名称:loginject,代码行数:17,代码来源:JavaUtilLoggingLoggerTest.java

示例7: testSubclassLoggerInjection

import org.glassfish.hk2.utilities.Binder; //导入依赖的package包/类
@Test
public void testSubclassLoggerInjection()
{
    AbstractBinder binder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            install(loginject(Logger::getLogger, currentClassName()).as(Binder.class));
            addActiveDescriptor(TestClass.class);
            addActiveDescriptor(SubClass1.class);
            addActiveDescriptor(SubClass2.class);
        }
    };
    ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(testName.getMethodName(), binder);
    assertEquals(SubClass1.class.getName(), serviceLocator.getService(SubClass1.class).injectedLogger.getName());
    assertEquals(SubClass2.class.getName(), serviceLocator.getService(SubClass2.class).injectedLogger.getName());
}
 
开发者ID:raner,项目名称:loginject,代码行数:19,代码来源:JavaUtilLoggingLoggerTest.java

示例8: testGetLoggerWithClassNameAndBundleNameParameters

import org.glassfish.hk2.utilities.Binder; //导入依赖的package包/类
@Test
public void testGetLoggerWithClassNameAndBundleNameParameters()
{
    final String bundleName = "ResourceBundle";
    AbstractBinder binder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            LogParameter<String> parameter = constantString(bundleName);
            install(loginject(Logger.class, Logger::getLogger, currentClassName(), parameter).as(Binder.class));
            addActiveDescriptor(TestClass.class);
        }
    };
    ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(testName.getMethodName(), binder);
    TestClass service = serviceLocator.getService(TestClass.class);
    String[] expected = {TestClass.class.getName(), bundleName};
    String[] actual = {service.injectedLogger.getName(), service.injectedLogger.getResourceBundleName()};
    assertArrayEquals(expected, actual);
}
 
开发者ID:raner,项目名称:loginject,代码行数:21,代码来源:JavaUtilLoggingLoggerTest.java

示例9: link

import org.glassfish.hk2.utilities.Binder; //导入依赖的package包/类
/**
 * @see #link(ServiceLocator, Injector)
 * @see #newChildInjector(Injector, ServiceLocator)
 */
private static ServiceLocator link(ServiceLocator locator, 
    Injector injector, Iterable<? extends Binder> binders) {
  
  DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
  DynamicConfiguration dc = dcs.createDynamicConfiguration();
  
  GuiceJustInTimeResolver resolver = new GuiceJustInTimeResolver(locator, injector);
  dc.bind(BuilderHelper.createConstantDescriptor(resolver));
  
  dc.addActiveDescriptor(GuiceScopeContext.class);
  
  bind(locator, dc, new MessagingBinders.HeaderDelegateProviders());
  
  for (Binder binder : binders) {
    bind(locator, dc, binder);
  }
  
  dc.commit();
  return locator;
}
 
开发者ID:Squarespace,项目名称:jersey2-guice,代码行数:25,代码来源:JerseyGuiceUtils.java

示例10: constructorWithBinderBuildsValidServiceLocatorAndSetsConfigContextAndResourceConfig

import org.glassfish.hk2.utilities.Binder; //导入依赖的package包/类
@Test
public void constructorWithBinderBuildsValidServiceLocatorAndSetsConfigContextAndResourceConfig() {
    Binder binder = new AbstractBinder() {
        @Override
        protected void configure() {
            bind(applicationResolver).to(ApplicationResolver.class).to(LateBoundApplicationResolver.class);
            bind(configContext).to(new GenericClass<ConfigContext<JerseyConfigSection>>() { }.getGenericClass());
            bind(resourceConfig).to(ResourceConfig.class);
        }
    };

    JerseyApplication<JerseyConfigSection> application =
            new JerseyApplicationBase<JerseyConfigSection>(binder) { };

    assertThat(application.serviceLocator()).isNotNull();
    assertThat(application.configContext()).isEqualTo(configContext);

    ConfigContext<JerseyConfigSection> configContextFromServiceLocator = application.serviceLocator()
            .getService(new GenericClass<ConfigContext<JerseyConfigSection>>() { }.getGenericClass());

    assertThat(configContextFromServiceLocator).isEqualTo(configContext);

    assertThat(application.resourceConfig()).isEqualTo(resourceConfig);

    ApplicationResolver applicationResolverFromServiceLocator = application.serviceLocator()
            .getService(ApplicationResolver.class);

    assertThat(applicationResolverFromServiceLocator.application()).isEqualTo(application);
}
 
开发者ID:joeyb,项目名称:undercarriage,代码行数:30,代码来源:JerseyApplicationBaseTests.java

示例11: getMockServiceLocator

import org.glassfish.hk2.utilities.Binder; //导入依赖的package包/类
private ServiceLocator getMockServiceLocator(Consumer<AbstractBinder> binderConsumer) {
    Binder binder = new AbstractBinder() {
        @Override
        protected void configure() {
            binderConsumer.accept(this);

            bind(applicationResolver).to(ApplicationResolver.class).to(LateBoundApplicationResolver.class);
            bind(configContext).to(new GenericClass<ConfigContext<JerseyConfigSection>>() { }.getGenericClass());
            bind(resourceConfig).to(ResourceConfig.class);
        }
    };

    return ServiceLocatorUtilities.bind(UUID.randomUUID().toString(), binder);
}
 
开发者ID:joeyb,项目名称:undercarriage,代码行数:15,代码来源:JerseyApplicationBaseTests.java

示例12: registerAuthorizationProviders

import org.glassfish.hk2.utilities.Binder; //导入依赖的package包/类
private void registerAuthorizationProviders(final AugmentedConfiguration augmentedConfiguration, final Environment environment) {
    final UserDao userDao = injector.getInstance(UserDao.class);
    final BasicAuthenticator basicAuthenticator = new BasicAuthenticator(userDao);
    final CachingAuthenticator cachingAuthenticator = new CachingAuthenticator(environment.metrics(), basicAuthenticator,
            augmentedConfiguration.getAuthCacheBuilder());
    final Binder authBinder = AuthFactory.binder(new BasicAuthFactory(cachingAuthenticator, "Basic auth", User.class));
    environment.jersey().register(authBinder);
}
 
开发者ID:blstream,项目名称:AugumentedSzczecin_java,代码行数:9,代码来源:AugmentedApplication.java

示例13: initialize

import org.glassfish.hk2.utilities.Binder; //导入依赖的package包/类
@Override
public ApplicationContext initialize(Binder applicationConfig) {
    requireNonNull(applicationConfig, "ApplicationConfig must be non-null for configuring HK2.");

    ServiceLocatorFactory locatorFactory = ServiceLocatorFactory.getInstance();
    locator = locatorFactory.create(JOYREST_BEAN_CONTEXT);
    ServiceLocatorUtilities.bind(locator, applicationConfig);

    return initializeContext();
}
 
开发者ID:petrbouda,项目名称:joyrest,代码行数:11,代码来源:HK2Configurer.java

示例14: getBindings

import org.glassfish.hk2.utilities.Binder; //导入依赖的package包/类
@Override
   public Binder getBindings(LogInject<_Logger_> logInject)
{
	return new AbstractBinder()
	{
		@Override
		protected void configure()
		{
			bind(logInject).to(LogInject.class);
			addActiveDescriptor(HK2LogInjectionResolver.class);
		}
	};
}
 
开发者ID:raner,项目名称:loginject,代码行数:14,代码来源:HK2LogInjectionService.java

示例15: getBinder

import org.glassfish.hk2.utilities.Binder; //导入依赖的package包/类
public static Binder getBinder() {
    return new AbstractBinder() {
        @Override
        protected void configure() {
            bindFactory(ListFilteringFactory.class).to(ListFiltering.class);
        }
    };
}
 
开发者ID:Lugribossk,项目名称:dropwizard-experiment,代码行数:9,代码来源:ListFilteringFactory.java


注:本文中的org.glassfish.hk2.utilities.Binder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。