本文整理汇总了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);
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
};
}
示例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);
}
};
}