本文整理汇总了Java中com.google.inject.name.Names类的典型用法代码示例。如果您正苦于以下问题:Java Names类的具体用法?Java Names怎么用?Java Names使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Names类属于com.google.inject.name包,在下文中一共展示了Names类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLazy
import com.google.inject.name.Names; //导入依赖的package包/类
@Test
public void testLazy() {
final Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
this.bind(Thing.class).to(ThingA.class);
this.bindLazy(Thing.class).annotatedWith(Names.named("b")).to(ThingB.class);
this.bindLazy(Thing.class).annotatedWith(Names.named("c")).to(ThingC.class);
}
});
final Things things = injector.getInstance(Things.class);
assertNotSame(things.ap.get(), things.ap.get());
assertSame(things.al.get(), things.al.get());
assertSame(things.bl.get(), things.bl.get());
assertSame(things.cl.get(), things.cl.get());
assertSame(things.dl.get(), things.dl.get());
}
示例2: testNotExposed
import com.google.inject.name.Names; //导入依赖的package包/类
@Test
public void testNotExposed() {
final Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
DuplexBinder.create(this.binder()).install(new DuplexModule() {
@Override
protected void configure() {
this.bind(Thing.class).annotatedWith(Names.named("r0")).toInstance(new Thing("r0"));
}
});
}
});
try {
injector.getInstance(ShouldNotWork.class);
} catch(final ConfigurationException expected) {
final String message = expected.getMessage();
if(message.contains("It was already configured on one or more child injectors or private modules")
&& message.contains("If it was in a PrivateModule, did you forget to expose the binding?")) {
return;
}
}
fail("should not be exposed");
}
示例3: newIsisWicketModule
import com.google.inject.name.Names; //导入依赖的package包/类
@Override
protected Module newIsisWicketModule() {
final Module isisDefaults = super.newIsisWicketModule();
final Module overrides = new AbstractModule() {
@Override
protected void configure() {
bind(ComponentFactoryRegistrar.class).to(MyComponentFactoryRegistrar.class);
bind(String.class).annotatedWith(Names.named("applicationName")).toInstance("RotaBuilder");
bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance("RotaBuilder");
bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(
Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
// if uncommented, then overrides isis.appManifest in config file.
// bind(AppManifest.class).toInstance(new DomainAppAppManifest());
}
};
return Modules.override(isisDefaults).with(overrides);
}
示例4: setStateExceptionTest
import com.google.inject.name.Names; //导入依赖的package包/类
@Test(expected = ConfigException.class)
public void setStateExceptionTest() {
Injector injector = Guice.createInjector(new AbstractModule() {
protected void configure() {
bind(ProcessorsApi.class).toInstance(processorsApiMock);
bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(1);
bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(1);
bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false);
}
});
ProcessorService processorService = injector.getInstance(ProcessorService.class);
ProcessorEntity processor = TestUtils.createProcessorEntity("id", "name");
processor.getComponent().setState(ProcessorDTO.StateEnum.STOPPED);
ProcessorEntity processorResponse = TestUtils.createProcessorEntity("id", "name");
processorResponse.getComponent().setState(ProcessorDTO.StateEnum.RUNNING);
when(processorsApiMock.updateProcessor(eq("id"), any() )).thenThrow(new ApiException());
when(processorsApiMock.getProcessor(eq("id") )).thenReturn(processorResponse);
processorService.setState(processor, ProcessorDTO.StateEnum.RUNNING);
}
示例5: bindClass
import com.google.inject.name.Names; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected <T> void bindClass(TypeLiteral<T> key, String property)
{
String value = Strings.nullToEmpty(getPropString(property)).trim();
if( !Check.isEmpty(value) )
{
try
{
Class<?> clazz = getClass().getClassLoader().loadClass(value);
bind(key).annotatedWith(Names.named(property)).toInstance((T) clazz);
}
catch( ClassNotFoundException e )
{
throw new ProvisionException("Class not found in property: " + property);
}
}
}
示例6: setUp
import com.google.inject.name.Names; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
Properties properties = getMinimalConfiguration();
injector = Guice.createInjector(Arrays.asList(
new ApiModule(properties),
new ClusterModule(),
new TranscodeModule(properties),
new ProcessModule(),
new GlobalModule(),
new AbstractModule() {
@Override
protected void configure() {
bind(MediaScanSettings.class).to(MediaScanSettingsImpl.class);
Names.bindProperties(binder(), properties);
}
}
));
injector.getInstance(ClusterService.class).joinCluster();
}
示例7: configure
import com.google.inject.name.Names; //导入依赖的package包/类
@SuppressWarnings("nls")
@Override
protected void configure()
{
NodeProvider node = node(InstitutionSection.class);
node.child(ProgressSection.class);
node.child(TabsSection.class);
node.child(AutoTestSetupSection.class);
node.innerChild(AdminTab.class);
node.innerChild(ImportTab.class);
node.innerChild(DatabaseTab.class);
node.innerChild(serverTab());
node.innerChild(ThreadDumpTab.class);
node.innerChild(HealthTab.class);
bind(Object.class).annotatedWith(Names.named("/institutions")).toProvider(node);
}
示例8: configure
import com.google.inject.name.Names; //导入依赖的package包/类
@Override
public void configure(Binder binder) {
super.configure(binder);
binder.bindConstant()
.annotatedWith(Names.named("org.eclipse.xtext.validation.CompositeEValidator.USE_EOBJECT_VALIDATOR"))
.to(false);
// set-up infrastructure for custom scopes
final ScopeManager scopeManager = new ScopeManager();
binder.bind(ScopeManager.class).toInstance(scopeManager);
binder.bindScope(TransformationScoped.class, scopeManager);
// setup documentation provider to match jsdoc-style exactly two stars only:
binder.bind(String.class)
.annotatedWith(Names.named(AbstractMultiLineCommentProvider.START_TAG))
.toInstance("/\\*\\*[^*]");
}
示例9: getByIdOutputTest
import com.google.inject.name.Names; //导入依赖的package包/类
@Test
public void getByIdOutputTest() throws ApiException, IOException, URISyntaxException {
Injector injector = Guice.createInjector(new AbstractModule() {
protected void configure() {
bind(InputPortsApi.class).toInstance(inputPortsApiMock);
bind(OutputPortsApi.class).toInstance(outputPortsApiMock);
bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(1);
bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(1);
bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false);
}
});
PortService portService = injector.getInstance(PortService.class);
PortEntity port = new PortEntity();
port.setComponent(new PortDTO());
port.getComponent().setId("id");
when(outputPortsApiMock.getOutputPort("id")).thenReturn(port);
PortEntity portResult = portService.getById("id", PortDTO.TypeEnum.OUTPUT_PORT);
assertEquals("id", portResult.getComponent().getId());
}
示例10: getBean
import com.google.inject.name.Names; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T getBean(String beanId)
{
Injector injector = ensureInjector();
Key<Object> nameKey = Key.get(Object.class, Names.named(beanId));
Binding<Object> binding = injector.getExistingBinding(nameKey);
if( binding != null )
{
return (T) binding.getProvider().get();
}
ClassLoader classLoader = privatePluginService.getClassLoader(pluginId);
try
{
Class<?> clazz = classLoader.loadClass(beanId);
return (T) injector.getInstance(clazz);
}
catch( ClassNotFoundException e )
{
throw new RuntimeException(e);
}
}
示例11: configureModules
import com.google.inject.name.Names; //导入依赖的package包/类
@Override
protected void configureModules() {
super.configureModules();
addModule(new AbstractModule() {
@Override
public void configure() {
bind(IWorldMessageTranslator.class).to(ServerFSM.class);
bind(IWorldView.class).to(IVisionWorldView.class);
bind(IVisionWorldView.class).to(UT2004WorldView.class);
bind(ComponentDependencies.class).annotatedWith(Names.named(UT2004WorldView.WORLDVIEW_DEPENDENCY)).toProvider(worldViewDependenciesProvider);
bind(IAgent.class).to(IWorldServer.class);
bind(IWorldServer.class).to(IUT2004Server.class);
bind(IUT2004Server.class).to(UT2004TCServer.class);
}
});
}
示例12: configureModules
import com.google.inject.name.Names; //导入依赖的package包/类
@Override
protected void configureModules() {
super.configureModules();
addModule(new AbstractModule() {
@Override
public void configure() {
bind(IWorldMessageTranslator.class).to(ObserverFSM.class);
bind(IWorldView.class).to(IVisionWorldView.class);
bind(IVisionWorldView.class).to(UT2004WorldView.class);
bind(ComponentDependencies.class).annotatedWith(Names.named(UT2004WorldView.WORLDVIEW_DEPENDENCY)).toProvider(worldViewDependenciesProvider);
bind(IAgent.class).to(IUT2004Observer.class);
// THIS tells guice it should instantiate our class and not default one
bind(IUT2004Observer.class).to(HSObserver.class);
}
});
}
示例13: mainHttpsUndeployTest
import com.google.inject.name.Names; //导入依赖的package包/类
@Test
public void mainHttpsUndeployTest() throws Exception {
Injector injector = Guice.createInjector(new AbstractModule() {
protected void configure() {
bind(AccessService.class).toInstance(accessServiceMock);
bind(InformationService.class).toInstance(informationServiceMock);
bind(TemplateService.class).toInstance(templateServiceMock);
bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(10);
bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(10);
bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false);
bind(Double.class).annotatedWith(Names.named("placeWidth")).toInstance(1200d);
bind(PositionDTO.class).annotatedWith(Names.named("startPosition")).toInstance(new PositionDTO());
}
});
//given
PowerMockito.mockStatic(Guice.class);
Mockito.when(Guice.createInjector((AbstractModule)anyObject())).thenReturn(injector);
Main.main(new String[]{"-nifi","https://localhost:8080/nifi-api","-branch","\"root>N2\"","-m","undeploy","-noVerifySsl"});
verify(templateServiceMock).undeploy(Arrays.asList("root","N2"));
}
示例14: configureAnnotationService
import com.google.inject.name.Names; //导入依赖的package包/类
private void configureAnnotationService(Binder binder) {
String endpoint = config.getString("annotation.service.url");
String clientSecret = config.getString("annotation.service.client.secret");
Duration timeout = config.getDuration("annotation.service.timeout");
AnnoWebServiceFactory factory = new AnnoWebServiceFactory(endpoint, timeout);
AuthService authService = new BasicJWTAuthService(factory,
new Authorization("APIKEY", clientSecret));
binder.bind(String.class)
.annotatedWith(Names.named("ANNO_ENDPOINT"))
.toInstance(endpoint);
binder.bind(AuthService.class)
.annotatedWith(Names.named("ANNO_AUTH"))
.toInstance(authService);
binder.bind(AnnoWebServiceFactory.class).toInstance(factory);
binder.bind(AnnotationService.class).to(AnnoService.class);
}
示例15: configureModules
import com.google.inject.name.Names; //导入依赖的package包/类
@Override
protected void configureModules() {
super.configureModules();
addModule(new AbstractModule() {
@Override
public void configure() {
bind(IWorldConnection.class).to(SocketConnection.class);
bind(ComponentDependencies.class).annotatedWith(Names.named(SocketConnection.CONNECTION_DEPENDENCY)).toProvider(connectionDependenciesProvider);
bind(ISocketConnectionAddress.class).annotatedWith(Names.named(SocketConnection.CONNECTION_ADDRESS_DEPENDENCY)).toProvider((Provider<ISocketConnectionAddress>) getAddressProvider());
bind(IWorldMessageParser.class).to(UT2004Parser.class);
bind(ItemTypeTranslator.class).to(UT2004ItemTypeTranslator.class);
bind(IYylex.class).to(IUT2004Yylex.class);
bind(IUT2004Yylex.class).to(Yylex.class);
bind(IYylexObserver.class).to(IYylexObserver.LogObserver.class);
bind(UT2004AgentParameters.class).toProvider(getAgentParamsProvider());
}
});
}