/** * Loads existing settings from the context, when the property {@link #SETTINGS_LOCATION_PROPERTY} is defined; * or loads or generates default settings and stores them in the local user directory, subdirectory .KeyGenerator * * @param vertx * the instance of {@link Vertx} to be used * @param defaultClass * if Settings are created new, this is the generator class to be used * @param context * the context, which could contain the property {@link #SETTINGS_LOCATION_PROPERTY}, where the location of * the settings file is defined * @return */ public static KeyGeneratorSettings loadSettings(Vertx vertx, Class<? extends IKeyGenerator> defaultClass, Context context) throws Exception { String path = context.config().getString(SETTINGS_LOCATION_PROPERTY); if (path != null) { return loadSettings(vertx, defaultClass, path); } else { vertx.fileSystem().mkdirsBlocking(LOCAL_USER_DIRECTORY); String localSettingsFileName = LOCAL_USER_DIRECTORY + "/" + KeyGeneratorVerticle.class.getName() + ".settings.json"; return loadSettings(vertx, defaultClass, localSettingsFileName); } }
/** * Initialize the {@link KeyGeneratorSettings} which are used to init the current instance * * @return * @throws Exception */ protected KeyGeneratorSettings initSettings() { try { KeyGeneratorSettings s = KeyGeneratorSettings.loadSettings(vertx, MongoKeyGenerator.class, context); if (!s.isEdited()) { throw new InitException( "The settings are not yet edited. Change the value of property 'edited' to true inside the appropriate file"); } return s; } catch (Exception e) { LOGGER.error("", e); throw ExceptionUtil.createRuntimeException(e); } }