Java Code Examples for com.google.inject.name.Names#named()

The following examples show how to use com.google.inject.name.Names#named() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigModule.java    From proteus with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 2
Source File: TermFacetSelectorViewModelFactory.java    From commercetools-sunrise-java with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: OUsersCommonUtils.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 4
Source File: TcpRxServerProvider.java    From karyon with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: HttpRxServerProvider.java    From karyon with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 6
Source File: WebSocketsRxServerProvider.java    From karyon with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: AbstractServerModule.java    From karyon with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 8
Source File: CapabilityDispatcherModule.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
protected Named named() {
	return Names.named(name() + "." + type().name().toLowerCase());
}
 
Example 9
Source File: ProjectModule.java    From json2java4idea with Apache License 2.0 4 votes vote down vote up
@Nonnull
Annotation annotation() {
    return Names.named(name);
}
 
Example 10
Source File: ConfigModule.java    From pinpoint with Apache License 2.0 3 votes vote down vote up
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());
    }