Java 类com.typesafe.config.ConfigBeanFactory 实例源码

项目:curiostack    文件:MonitoringModule.java   
@Provides
@Singleton
static MonitoringConfig monitoringConfig(Config config) {
  return ConfigBeanFactory.create(
          config.getConfig("monitoring"), ModifiableMonitoringConfig.class)
      .toImmutable();
}
项目:curiostack    文件:ServerModule.java   
@Provides
@Singleton
static JavascriptStaticConfig javascriptStaticConfig(Config config) {
  return ConfigBeanFactory.create(
          config.getConfig("javascriptConfig"), ModifiableJavascriptStaticConfig.class)
      .toImmutable();
}
项目:typesafeconfig-guice    文件:TypesafeConfigModule.java   
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object getConfigValue(Class<?> paramClass, Type paramType, String path) {
    Optional<Object> extractedValue = ConfigExtractors.extractConfigValue(config, paramClass, path);
    if (extractedValue.isPresent()) {
        return extractedValue.get();
    }

    ConfigValue configValue = config.getValue(path);
    ConfigValueType valueType = configValue.valueType();
    if (valueType.equals(ConfigValueType.OBJECT) && Map.class.isAssignableFrom(paramClass)) {
        ConfigObject object = config.getObject(path);
           return object.unwrapped();
    } else if (valueType.equals(ConfigValueType.OBJECT)) {
        Object bean = ConfigBeanFactory.create(config.getConfig(path), paramClass);
        return bean;
    } else if (valueType.equals(ConfigValueType.LIST) && List.class.isAssignableFrom(paramClass)) {
        Type listType = ((ParameterizedType) paramType).getActualTypeArguments()[0];

        Optional<List<?>> extractedListValue = 
            ListExtractors.extractConfigListValue(config, listType, path);

        if (extractedListValue.isPresent()) {
            return extractedListValue.get();
        } else {
            List<? extends Config> configList = config.getConfigList(path);
            return configList.stream()
                .map(cfg -> {
                    Object created = ConfigBeanFactory.create(cfg, (Class) listType);
                    return created;
                })
                .collect(Collectors.toList());
        }
    }

    throw new RuntimeException("Cannot obtain config value for " + paramType + " at path: " + path);
}
项目:google-assistant-java-demo    文件:GoogleAssistantClient.java   
public static void main(String[] args) throws AuthenticationException, AudioException, ConverseException, DeviceRegisterException {

        Config root = ConfigFactory.load();
        AuthenticationConf authenticationConf = ConfigBeanFactory.create(root.getConfig("authentication"), AuthenticationConf.class);
        DeviceRegisterConf deviceRegisterConf = ConfigBeanFactory.create(root.getConfig("deviceRegister"), DeviceRegisterConf.class);
        AssistantConf assistantConf = ConfigBeanFactory.create(root.getConfig("assistant"), AssistantConf.class);
        AudioConf audioConf = ConfigBeanFactory.create(root.getConfig("audio"), AudioConf.class);

        // Authentication
        AuthenticationHelper authenticationHelper = new AuthenticationHelper(authenticationConf);
        authenticationHelper
                .authenticate()
                .orElseThrow(() -> new AuthenticationException("Error during authentication"));

        // Check if we need to refresh the access token to request the api
        if (authenticationHelper.expired()) {
            authenticationHelper
                    .refreshAccessToken()
                    .orElseThrow(() -> new AuthenticationException("Error refreshing access token"));
        }

        // Register Device model and device
        DeviceRegister deviceRegister = new DeviceRegister(deviceRegisterConf, authenticationHelper.getOAuthCredentials().getAccessToken());
        deviceRegister.register();

        // Build the client (stub)
        AssistantClient assistantClient = new AssistantClient(authenticationHelper.getOAuthCredentials(), assistantConf,
                deviceRegister.getDeviceModel(), deviceRegister.getDevice());

        // Build the objects to record and play the conversation
        AudioRecorder audioRecorder = new AudioRecorder(audioConf);
        AudioPlayer audioPlayer = new AudioPlayer(audioConf);

        // Main loop
        while (true) {
            // Check if we need to refresh the access token to request the api
            if (authenticationHelper.expired()) {
                authenticationHelper
                        .refreshAccessToken()
                        .orElseThrow(() -> new AuthenticationException("Error refreshing access token"));

                // Update the token for the assistant client
                assistantClient.updateCredentials(authenticationHelper.getOAuthCredentials());
            }

            // Record
            byte[] request = audioRecorder.getRecord();

            // Request the api
            byte[] response = assistantClient.requestAssistant(request);

            // Play result if any
            if (response.length > 0) {
                audioPlayer.play(response);
            } else {
                LOGGER.info("No response from the API");
            }
        }
    }
项目:curiostack    文件:DatabaseModule.java   
@Provides
@Singleton
static DatabaseConfig dbConfig(Config config) {
  return ConfigBeanFactory.create(config.getConfig("database"), ModifiableDatabaseConfig.class)
      .toImmutable();
}
项目:curiostack    文件:RedisModule.java   
@Provides
@Singleton
static RedisConfig redisConfig(Config config) {
  return ConfigBeanFactory.create(config.getConfig("redis"), ModifiableRedisConfig.class)
      .toImmutable();
}
项目:curiostack    文件:FirebaseAuthModule.java   
@Provides
@Singleton
static FirebaseAuthConfig firebaseConfig(Config config) {
  return ConfigBeanFactory.create(
      config.getConfig("firebaseAuth"), ModifiableFirebaseAuthConfig.class);
}
项目:curiostack    文件:ServerModule.java   
@Provides
@Singleton
static ServerConfig serverConfig(Config config) {
  return ConfigBeanFactory.create(config.getConfig("server"), ModifiableServerConfig.class)
      .toImmutable();
}
项目:curiostack    文件:YummlyApiModule.java   
@Provides
static YummlyConfig yummlyConfig(Config config) {
  return ConfigBeanFactory.create(config.getConfig("yummly"), ModifiableYummlyConfig.class)
      .toImmutable();
}
项目:sample-spark    文件:SparkSample.java   
public void run() {
    logger.info("Starting application...");

    final Config config = ConfigFactory.load();
    final SparkSettings sparkConf = ConfigBeanFactory.create(config.getConfig("spark"), SparkSettings.class);

    logger.info("Loaded config: " + config.toString());

    new SparkInitializer(sparkConf).init();
}