Java Code Examples for com.typesafe.config.ConfigBeanFactory#create()
The following examples show how to use
com.typesafe.config.ConfigBeanFactory#create() .
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: LoadTestApplication.java From casquatch with Apache License 2.0 | 6 votes |
public static void main(String[] args) { //Create CasquatchDao from config CasquatchDao db=CasquatchDao.builder().build(); //Load loadtest config ConfigFactory.invalidateCaches(); Config config = ConfigFactory.load().getConfig("loadtest"); if(log.isTraceEnabled()) { for (Map.Entry<String, ConfigValue> entry : config.entrySet()) { log.trace("Config: {} -> {}", entry.getKey(), entry.getValue().render()); } } LoadTestConfig loadTestConfig = ConfigBeanFactory.create(config,LoadTestConfig.class); //Run for each entity if(loadTestConfig.getEntities().size()>0) { for (Class entity : loadTestConfig.getEntityClasses()) { new LoadWrapper<>(entity, db).run(loadTestConfig); } } System.exit(0); }
Example 2
Source File: TypesafeConfigModule.java From typesafeconfig-guice with Apache License 2.0 | 5 votes |
@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); }
Example 3
Source File: GoogleAssistantClient.java From google-assistant-java-demo with GNU General Public License v3.0 | 4 votes |
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); IoConf ioConf = ConfigBeanFactory.create(root.getConfig("io"), IoConf.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(), ioConf); // Build the objects to record and play the conversation AudioRecorder audioRecorder = new AudioRecorder(audioConf); AudioPlayer audioPlayer = new AudioPlayer(audioConf); // Initiating Scanner to take user input Scanner scanner = new Scanner(System.in); // 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()); } // Get input (text or voice) byte[] request = getInput(ioConf, scanner, audioRecorder); // requesting assistant with text query assistantClient.requestAssistant(request); LOGGER.info(assistantClient.getTextResponse()); if (Boolean.TRUE.equals(ioConf.getOutputAudio())) { byte[] audioResponse = assistantClient.getAudioResponse(); if (audioResponse.length > 0) { audioPlayer.play(audioResponse); } else { LOGGER.info("No response from the API"); } } } }
Example 4
Source File: FirebaseAuthModule.java From curiostack with MIT License | 4 votes |
@Provides @Singleton static FirebaseAuthConfig firebaseConfig(Config config) { return ConfigBeanFactory.create( config.getConfig("firebaseAuth"), ModifiableFirebaseAuthConfig.class); }
Example 5
Source File: GeneratorExternalTests.java From casquatch with Apache License 2.0 | 3 votes |
@Test public void testGenerator() throws Exception { CasquatchGeneratorConfiguration casquatchGeneratorConfiguration = ConfigBeanFactory.create(ConfigLoader.generator(),CasquatchGeneratorConfiguration.class); new CasquatchTestDaoBuilder().withDDL("CREATE TABLE IF NOT EXISTS table_name (key_one int,key_two int,col_one text,col_two text,PRIMARY KEY ((key_one), key_two))"); new CasquatchGenerator(casquatchGeneratorConfiguration).run(); assertTrue(new File(casquatchGeneratorConfiguration.getOutputFolder()+"/src/main/java/"+casquatchGeneratorConfiguration.getPackageName().replace(".","/")+"/TableName.java").exists()); }
Example 6
Source File: CasquatchGenerator.java From casquatch with Apache License 2.0 | 2 votes |
/** * Initialize CasquatchGenerator * @throws Exception relays any exception found */ public CasquatchGenerator() throws Exception { this(ConfigBeanFactory.create(ConfigLoader.generator(),CasquatchGeneratorConfiguration.class)); }