下面列出了com.google.inject.name.Names#named ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressWarnings("unchecked")
private void bindConfig(final Config config)
{
traverse(this.binder(), "", config.root());
for (Entry<String, ConfigValue> entry : config.entrySet()) {
String name = entry.getKey();
Named named = Names.named(name);
Object value = entry.getValue().unwrapped();
if (value instanceof List) {
List<Object> values = (List<Object>) value;
Type listType = (values.size() == 0)
? String.class
: Types.listOf(values.iterator().next().getClass());
Key<Object> key = (Key<Object>) Key.get(listType, Names.named(name));
this.binder().bind(key).toInstance(values);
} else {
this.binder().bindConstant().annotatedWith(named).to(value.toString());
}
}
Config referenceConfig = ConfigFactory.load(ConfigFactory.defaultReference());
this.config = ConfigFactory.load(config).withFallback(referenceConfig);
log.debug(this.config.toString());
this.binder().bind(Config.class).toInstance(config);
}
private TermFacetViewModelFactory findViewModelFactory(final TermFacetedSearchFormSettings<?> settings) {
if (settings.getMapperSettings() != null) {
try {
final Named named = Names.named(settings.getMapperSettings().getName());
return injector.getInstance(Key.get(TermFacetViewModelFactory.class, named));
} catch (ConfigurationException e) {
LOGGER.warn("Could not find term facet mapper with name \"{}\"", settings.getFieldName());
}
}
return termFacetViewModelFactory;
}
public static List<IOAuth2Provider> getOAuth2Providers() {
OrienteerWebApplication app = OrienteerWebApplication.lookupApplication();
if (app == null) {
return Collections.emptyList();
}
Named named = Names.named("orienteer.oauth2.providers");
Key<List<IOAuth2Provider>> key = Key.get(new TypeLiteral<List<IOAuth2Provider>>() {}, named);
return app.getInjector().getInstance(key);
}
public TcpRxServerProvider(String name, Class<I> iType, Class<O> oType) {
nameAnnotation = Names.named(name);
connectionHandlerKey = keyFor(ConnectionHandler.class, iType, oType, nameAnnotation);
pipelineConfiguratorKey = Key.get(PipelineConfigurator.class, nameAnnotation);
metricEventsListenerFactoryKey = Key.get(MetricEventsListenerFactory.class, nameAnnotation);
serverConfigKey = Key.get(ServerConfig.class, nameAnnotation);
}
public HttpRxServerProvider(String name, Class<I> iType, Class<O> oType) {
nameAnnotation = Names.named(name);
routerKey = keyFor(RequestHandler.class, iType, oType, nameAnnotation);
interceptorSupportKey = keyFor(GovernatorHttpInterceptorSupport.class, iType, oType, nameAnnotation);
pipelineConfiguratorKey = Key.get(PipelineConfigurator.class, nameAnnotation);
metricEventsListenerFactoryKey = Key.get(MetricEventsListenerFactory.class, nameAnnotation);
serverConfigKey = Key.get(ServerConfig.class, nameAnnotation);
}
public WebSocketsRxServerProvider(String name, Class<I> iType, Class<O> oType) {
nameAnnotation = Names.named(name);
connectionHandlerKey = keyFor(ConnectionHandler.class, iType, oType, nameAnnotation);
pipelineConfiguratorKey = Key.get(PipelineConfigurator.class, nameAnnotation);
metricEventsListenerFactoryKey = Key.get(MetricEventsListenerFactory.class, nameAnnotation);
serverConfigKey = Key.get(AbstractServerModule.ServerConfig.class, nameAnnotation);
}
protected AbstractServerModule(String moduleName, Class<I> iType, Class<O> oType) {
nameAnnotation = Names.named(moduleName);
this.iType = iType;
this.oType = oType;
pipelineConfiguratorKey = Key.get(PipelineConfigurator.class, nameAnnotation);
serverConfigKey = Key.get(ServerConfig.class, nameAnnotation);
serverConfigBuilder = newServerConfigBuilder();
}
protected Named named() {
return Names.named(name() + "." + type().name().toLowerCase());
}
@Nonnull
Annotation annotation() {
return Names.named(name);
}
private void bindConstants(ProfilerConfig profilerConfig) {
bind(TraceDataFormatVersion.class).toProvider(TraceDataFormatVersionProvider.class).in(Scopes.SINGLETON);
Named callstackMaxDepth = Names.named("profiler.callstack.max.depth");
bindConstant().annotatedWith(callstackMaxDepth).to(profilerConfig.getCallStackMaxDepth());
bindConstant().annotatedWith(TraceAgentActiveThread.class).to(profilerConfig.isTraceAgentActiveThread());
bindConstant().annotatedWith(DeadlockMonitorEnable.class).to(profilerConfig.isDeadlockMonitorEnable());
bindConstant().annotatedWith(DeadlockMonitorInterval.class).to(profilerConfig.getDeadlockMonitorInterval());
}