當前位置: 首頁>>代碼示例>>Java>>正文


Java Names類代碼示例

本文整理匯總了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());
}
 
開發者ID:KyoriPowered,項目名稱:violet,代碼行數:18,代碼來源:LazyTest.java

示例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");
}
 
開發者ID:KyoriPowered,項目名稱:violet,代碼行數:25,代碼來源:DuplexTest.java

示例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);
}
 
開發者ID:bibryam,項目名稱:rotabuilder,代碼行數:24,代碼來源:DomainApplication.java

示例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);
}
 
開發者ID:hermannpencole,項目名稱:nifi-config,代碼行數:22,代碼來源:ProcessorServiceTest.java

示例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);
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:18,代碼來源:PropertiesModule.java

示例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();
}
 
開發者ID:ccremer,項目名稱:clustercode,代碼行數:21,代碼來源:CancelTaskIT.java

示例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);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:17,代碼來源:InstitutionModule.java

示例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("/\\*\\*[^*]");
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:18,代碼來源:N4JSRuntimeModule.java

示例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());
}
 
開發者ID:hermannpencole,項目名稱:nifi-config,代碼行數:20,代碼來源:PortServiceTest.java

示例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);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:23,代碼來源:GuicePlugin.java

示例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);
		}

	});
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:19,代碼來源:UT2004TCServerModule.java

示例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); 
		}

	});
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:20,代碼來源:HSObserverModule.java

示例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"));
}
 
開發者ID:hermannpencole,項目名稱:nifi-config,代碼行數:22,代碼來源:MainTest.java

示例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);
}
 
開發者ID:mbari-media-management,項目名稱:vars-annotation,代碼行數:17,代碼來源:MBARIInjectorModule.java

示例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());
		}
		
	});
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:21,代碼來源:UT2004CommunicationModule.java


注:本文中的com.google.inject.name.Names類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。