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

The following examples show how to use com.google.inject.name.Names#bindProperties() . 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: Config.java    From newts with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {

    bind(SampleRepository.class).to(CassandraSampleRepository.class);
    bind(CassandraSession.class).to(CassandraSessionImpl.class);

    Properties properties = new Properties();
    properties.put("cassandra.keyspace", System.getProperty("cassandra.keyspace", "newts"));
    properties.put("cassandra.hostname", System.getProperty("cassandra.host", "localhost"));
    properties.put("cassandra.port", System.getProperty("cassandra.port", "9042"));
    properties.put("cassandra.username", System.getProperty("cassandra.username", "admin"));
    properties.put("cassandra.password", System.getProperty("cassandra.password", "admin"));
    properties.put("cassandra.ssl", System.getProperty("cassandra.ssl", "false"));
    properties.put("cassandra.compression", System.getProperty("cassandra.compression", "NONE"));
    properties.put("samples.cassandra.time-to-live", System.getProperty("cassandra.time-to-live", "0"));
    Names.bindProperties(binder(), properties);

    bind(MetricRegistry.class).toInstance(new MetricRegistry());

}
 
Example 2
Source File: AbstractBaseModule.java    From EDDI with Apache License 2.0 6 votes vote down vote up
protected void registerConfigFiles(InputStream... configFiles) {
    try {
        /**
         * Allow *.properties config to be overridden by system properties
         */
        final Properties systemProperties = System.getProperties();
        for (InputStream configFile : configFiles) {
            Properties properties = new Properties();
            properties.load(configFile);
            properties.entrySet().forEach(propertyEntry -> {
                if (systemProperties.containsKey(propertyEntry.getKey())) {
                    propertyEntry.setValue(systemProperties.getProperty((String) propertyEntry.getKey()));
                }
            });
            Names.bindProperties(binder(), properties);
            systemProperties.putAll(properties);
        }
    } catch (IOException e) {
        System.out.println(Arrays.toString(e.getStackTrace()));
    }
}
 
Example 3
Source File: MySQLAuthenticationProviderModule.java    From guacamole-client with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(Binder binder) {

    // Check which MySQL-compatible driver is in use
    switch(mysqlDriver) {
        
        // Bind MySQL-specific properties
        case MYSQL:
            JdbcHelper.MySQL.configure(binder);
            break;
            
        // Bind MariaDB-specific properties
        case MARIADB:
            JdbcHelper.MariaDB.configure(binder);
            break;
            
        default:
            throw new UnsupportedOperationException(
                "A driver has been specified that is not supported by this module."
            );
    }

    // Bind MyBatis properties
    Names.bindProperties(binder, myBatisProperties);

    // Bind JDBC driver properties
    binder.bind(Properties.class)
        .annotatedWith(Names.named("JDBC.driverProperties"))
        .toInstance(driverProperties);

}
 
Example 4
Source File: ConfigurablePropertiesModule.java    From attic-rave with Apache License 2.0 5 votes vote down vote up
private void bindNonConstantProperties() {
    Properties p = getProperties();
    for (String overridableProperty : constantGuiceProperties()) {
        p.remove(overridableProperty);
    }
    Names.bindProperties(this.binder(), p);
}
 
Example 5
Source File: OrienteerInitModule.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureServlets() {
	Map<String, String> params = new HashMap<String, String>();    
       params.put(WicketFilter.FILTER_MAPPING_PARAM, "/*");  
       params.put("applicationFactoryClassName", GuiceWebApplicationFactory.class.getName());
       params.put("injectorContextAttribute", Injector.class.getName());
       bind(WicketFilter.class).in(Singleton.class);
       filter("/*").through(WicketFilter.class, params);  
	
	Names.bindProperties(binder(), properties);
	bindOrientDbProperties(properties);
	String applicationClass = properties.getProperty("orienteer.application");
	Class<? extends OrienteerWebApplication> appClass = OrienteerWebApplication.class;
	if (applicationClass != null) {
		try {
			Class<?> customAppClass = Class.forName(applicationClass);

			if (OrienteerWebApplication.class.isAssignableFrom(appClass)) {
				appClass = (Class<? extends OrienteerWebApplication>) customAppClass;
			} else {
				LOG.error("Orienteer application class '" + applicationClass + "' is not child class of '" + OrienteerWebApplication.class + "'. Using default.");
			}
		} catch (ClassNotFoundException e) {
			LOG.error("Orienteer application class '" + applicationClass + "' was not found. Using default.");
		}
	}
	bind(appClass).asEagerSingleton();
	Provider<? extends OrienteerWebApplication> appProvider = binder().getProvider(appClass);
	if (!OrienteerWebApplication.class.equals(appClass)) {
		bind(OrienteerWebApplication.class).toProvider(appProvider);
	}
	bind(OrientDbWebApplication.class).toProvider(appProvider);
	bind(WebApplication.class).toProvider(appProvider);

	bind(Properties.class).annotatedWith(Orienteer.class).toInstance(properties);

	install(
	        loadFromClasspath(new OrienteerModule())
       );
}
 
Example 6
Source File: SQLServerAuthenticationProviderModule.java    From guacamole-client with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(Binder binder) {

    // Bind SQLServer-specific properties with the configured driver.
    switch(sqlServerDriver) {
        case JTDS:
            JdbcHelper.SQL_Server_jTDS.configure(binder);
            break;

        case DATA_DIRECT:
            JdbcHelper.SQL_Server_DataDirect.configure(binder);
            break;

        case MICROSOFT_LEGACY:
            JdbcHelper.SQL_Server_MS_Driver.configure(binder);
            break;

        case MICROSOFT_2005:
            JdbcHelper.SQL_Server_2005_MS_Driver.configure(binder);
            break;

        default:
            throw new UnsupportedOperationException(
                "A driver has been specified that is not supported by this module."
            );
    }
    
    // Bind MyBatis properties
    Names.bindProperties(binder, myBatisProperties);

    // Bind JDBC driver properties
    binder.bind(Properties.class)
        .annotatedWith(Names.named("JDBC.driverProperties"))
        .toInstance(driverProperties);

}
 
Example 7
Source File: Module.java    From mangooio with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    Names.bindProperties(binder(), config.toProperties());
    
    bind(JobFactory.class).to(SchedulerFactory.class);
    bind(Cache.class).toProvider(CacheProvider.class);
    bind(MangooAuthorizationService.class).to(AuthorizationService.class);
}
 
Example 8
Source File: AbstractGenericModule.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected Properties tryBindProperties(Binder binder, String propertyFilePath) {
	try {
		InputStream in = getClass().getClassLoader().getResourceAsStream(propertyFilePath);
		if (in != null) {
			Properties properties = new Properties();
			properties.load(in);
			Names.bindProperties(binder, properties);
			return properties;
		} else
			return null;
	} catch (IOException e) {
		return null;
	}
}
 
Example 9
Source File: AbstractGenericModule.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void bindProperties(Binder binder, String propertyFilePath) {
	try {
		InputStream in = getClass().getClassLoader().getResourceAsStream(propertyFilePath);
		if (in != null) {
			Properties properties = new Properties();
			properties.load(in);
			Names.bindProperties(binder, properties);
		} else {
			throw new IllegalStateException("Couldn't find property file : " + propertyFilePath);
		}
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example 10
Source File: SQLServerAuthenticationProviderModule.java    From guacamole-client with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(Binder binder) {

    // Bind SQLServer-specific properties with the configured driver.
    switch(sqlServerDriver) {
        case JTDS:
            JdbcHelper.SQL_Server_jTDS.configure(binder);
            break;

        case DATA_DIRECT:
            JdbcHelper.SQL_Server_DataDirect.configure(binder);
            break;

        case MICROSOFT_LEGACY:
            JdbcHelper.SQL_Server_MS_Driver.configure(binder);
            break;

        case MICROSOFT_2005:
            JdbcHelper.SQL_Server_2005_MS_Driver.configure(binder);
            break;

        default:
            throw new UnsupportedOperationException(
                "A driver has been specified that is not supported by this module."
            );
    }
    
    // Bind MyBatis properties
    Names.bindProperties(binder, myBatisProperties);

    // Bind JDBC driver properties
    binder.bind(Properties.class)
        .annotatedWith(Names.named("JDBC.driverProperties"))
        .toInstance(driverProperties);

}
 
Example 11
Source File: PostgreSQLAuthenticationProviderModule.java    From guacamole-client with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(Binder binder) {

    // Bind PostgreSQL-specific properties
    JdbcHelper.PostgreSQL.configure(binder);
    
    // Bind MyBatis properties
    Names.bindProperties(binder, myBatisProperties);

    // Bind JDBC driver properties
    binder.bind(Properties.class)
        .annotatedWith(Names.named("JDBC.driverProperties"))
        .toInstance(driverProperties);

}
 
Example 12
Source File: ApplicationMainModule.java    From zerocode with Apache License 2.0 5 votes vote down vote up
@Override
public void configure() {
    /*
     * Install other guice modules
     */
    install(new ObjectMapperModule());
    install(new HttpClientModule());
    install(new GsonModule());
    install(new PropertiesInjectorModule(serverEnv));
    install(new CsvParserModule());
    //install(new KafkaModule());

    /*
     * Bind Direct classes, classes to interfaces etc
     */
    bind(ZeroCodeMultiStepsScenarioRunner.class).to(ZeroCodeMultiStepsScenarioRunnerImpl.class);
    bind(ApiServiceExecutor.class).to(ApiServiceExecutorImpl.class);
    bind(HttpApiExecutor.class).to(HttpApiExecutorImpl.class);
    bind(JavaMethodExecutor.class).to(JavaMethodExecutorImpl.class);
    bind(ZeroCodeAssertionsProcessor.class).to(ZeroCodeAssertionsProcessorImpl.class);
    bind(ZeroCodeValidator.class).to(ZeroCodeValidatorImpl.class);
    bind(ZeroCodeReportGenerator.class).to(ZeroCodeReportGeneratorImpl.class);
    bind(ZeroCodeExternalFileProcessor.class).to(ZeroCodeExternalFileProcessorImpl.class);
    bind(ZeroCodeParameterizedProcessor.class).to(ZeroCodeParameterizedProcessorImpl.class);

    // ------------------------------------------------
    // Bind properties for localhost, CI, DIT, SIT etc
    // ------------------------------------------------
    Names.bindProperties(binder(), getProperties(serverEnv));
}
 
Example 13
Source File: PostgreSQLAuthenticationProviderModule.java    From guacamole-client with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(Binder binder) {

    // Bind PostgreSQL-specific properties
    JdbcHelper.PostgreSQL.configure(binder);
    
    // Bind MyBatis properties
    Names.bindProperties(binder, myBatisProperties);

    // Bind JDBC driver properties
    binder.bind(Properties.class)
        .annotatedWith(Names.named("JDBC.driverProperties"))
        .toInstance(driverProperties);

}
 
Example 14
Source File: PropertiesRegistrationGuiceModule.java    From riposte with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    /*
        Grab all the string properties and register them with Guice so they can be @Inject-ed
        without any further configuration.
     */
    Map<String, String> props = getPropertiesMap();
    Names.bindProperties(binder(), props);
}
 
Example 15
Source File: PropertiesLoaderModule.java    From bobcat with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
  try {
    Names.bindProperties(binder(), getProperties());
  } catch (IOException e) {
    throwIfUnchecked(e);
    throw new RuntimeException(e);
  }
}
 
Example 16
Source File: PaasPropertiesModule.java    From staash with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    try {
        Properties props = loadProperties();
        Names.bindProperties(binder(), props);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 17
Source File: PropertyLoadingModule.java    From joynr with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure() {
    Names.bindProperties(binder(), properties);
    logProperties();
}
 
Example 18
Source File: AppModule.java    From diver with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure() {
  Names.bindProperties(binder(), properties);
}
 
Example 19
Source File: GossipConfigModule.java    From gossip with MIT License 4 votes vote down vote up
@Override
protected void configure() {
    Names.bindProperties(binder(), gossipConfig);
}
 
Example 20
Source File: PropertyBinder.java    From bobcat with Apache License 2.0 2 votes vote down vote up
/**
 * This method reads property files and creates following bindings:
 * <ul>
 * <li>a named binding for each property,
 * <li>a binding for Properties class; bound Property instance contains all the properties.
 * </ul>
 * Property file paths are retrieved from configuration.paths property. If configuration.paths is not set,
 * bindProperties will look in default location, i.e. "src/main/config". Property configuration.paths can
 * contain any number of paths. Paths in configuration.paths should be separated with semicolons.
 *
 * @param binder The Binder instance that will store the newly created property bindings.
 * @param configStrategy the selected configuration strategy
 */
public static void bindProperties(Binder binder, ConfigStrategy configStrategy) {
  Properties properties = configStrategy.gatherProperties();
  Names.bindProperties(binder, properties);
  binder.bind(Properties.class).toInstance(properties);
}