/** Access a field of a JSON object, return an {@code int} or a default value. */ public static int getInt(JsonObject obj, String field, int dftValue) { JsonValue jv = obj.get(field); if ( jv == null ) return dftValue; return getInt(jv, dftValue); }
/** Parse a configuration file. */ public Builder parse(String configFile) { Path path = Paths.get(configFile); if ( ! Files.exists(path) ) throw new DeltaConfigException("File not found: "+configFile); // -- version JsonObject obj = JSON.read(configFile); int version = JSONX.getInt(obj, F_VERSION, -99); if ( version == -99 ) { LOG.warn("No version number for the configuration file : assuming 'current'"); version = DeltaConst.SYSTEM_VERSION; } if ( version != SYSTEM_VERSION ) throw new DeltaConfigException("Version number for LocalServer must be "+DeltaConst.SYSTEM_VERSION+"."); this.configFile = configFile; // -- log provider logProvider = DPS.PatchStoreFileProvider; String logTypeName = JSONX.getStrOrNull(obj, F_LOG_TYPE); if ( logTypeName != null ) { String providerName = PatchStoreMgr.canonical(logTypeName); if ( providerName == null ) providerName = DeltaConst.LOG_FILE; logProvider = providerName; } setProperty(DeltaConst.pDeltaFile, path.getParent().toString()); return this; }