private INIFile local() { if (this.globalOnly) { throw new ConfigException(StatusCode.INVALID_LOCATION); } return this.local; }
@Override public File iniFile() { if (repoDirectory == null) { throw new ConfigException(StatusCode.INVALID_LOCATION); } File localConfigFile = new File(repoDirectory, "config"); return localConfigFile; } };
public Map<String, String> getAllSectionGlobal(String section) { try { return global.getSection(section); } catch (StringIndexOutOfBoundsException e) { throw new ConfigException(e, StatusCode.SECTION_OR_KEY_INVALID); } catch (IllegalArgumentException e) { throw new ConfigException(e, null); } catch (IOException e) { throw new ConfigException(e, null); } }
public List<String> getAllSubsectionsGlobal(String section) { try { return global.listSubsections(section); } catch (StringIndexOutOfBoundsException e) { throw new ConfigException(e, StatusCode.SECTION_OR_KEY_INVALID); } catch (IllegalArgumentException e) { throw new ConfigException(e, null); } catch (IOException e) { throw new ConfigException(e, null); } }
public Map<String, String> getAllGlobal() { try { return global.getAll(); } catch (StringIndexOutOfBoundsException e) { throw new ConfigException(e, StatusCode.SECTION_OR_KEY_INVALID); } catch (IllegalArgumentException e) { throw new ConfigException(e, null); } catch (IOException e) { throw new ConfigException(e, null); } }
public List<String> getAllSubsectionsGlobal(String section) { try { return global.listSubsections(section); } catch (StringIndexOutOfBoundsException e) { throw new ConfigException(e, StatusCode.SECTION_OR_KEY_INVALID); } catch (IllegalArgumentException e) { throw new ConfigException(e, null); } catch (IOException e) { throw new ConfigException(e, null); } }
public Map<String, String> getAllSection(String section) { try { return local().getSection(section); } catch (StringIndexOutOfBoundsException e) { throw new ConfigException(e, StatusCode.SECTION_OR_KEY_INVALID); } catch (IllegalArgumentException e) { throw new ConfigException(e, null); } catch (IOException e) { throw new ConfigException(e, null); } }
public List<String> getAllSubsections(String section) { try { return local().listSubsections(section); } catch (StringIndexOutOfBoundsException e) { throw new ConfigException(e, StatusCode.SECTION_OR_KEY_INVALID); } catch (IllegalArgumentException e) { throw new ConfigException(e, null); } catch (IOException e) { throw new ConfigException(e, null); } }
public Map<String, String> getAll() { try { return local().getAll(); } catch (StringIndexOutOfBoundsException e) { throw new ConfigException(e, StatusCode.SECTION_OR_KEY_INVALID); } catch (IllegalArgumentException e) { throw new ConfigException(e, null); } catch (IOException e) { throw new ConfigException(e, null); } }
public void putGlobal(String key, Object value) { String[] parsed = parse(key); try { global.set(parsed[0], parsed[1], stringify(value)); } catch (StringIndexOutOfBoundsException e) { throw new ConfigException(e, StatusCode.SECTION_OR_KEY_INVALID); } catch (IllegalArgumentException e) { throw new ConfigException(e, null); } catch (IOException e) { throw new ConfigException(e, null); } }
public void remove(String key) { String[] parsed = parse(key); try { local().remove(parsed[0], parsed[1]); } catch (StringIndexOutOfBoundsException e) { throw new ConfigException(e, StatusCode.SECTION_OR_KEY_INVALID); } catch (IllegalArgumentException e) { throw new ConfigException(e, null); } catch (IOException e) { throw new ConfigException(e, null); } }
public void putGlobal(String key, Object value) { String[] parsed = parse(key); try { global.set(parsed[0], parsed[1], stringify(value)); } catch (StringIndexOutOfBoundsException e) { throw new ConfigException(e, StatusCode.SECTION_OR_KEY_INVALID); } catch (IllegalArgumentException e) { throw new ConfigException(e, null); } catch (IOException e) { throw new ConfigException(e, null); } }
public void put(String key, Object value) { String[] parsed = parse(key); try { local().set(parsed[0], parsed[1], stringify(value)); } catch (StringIndexOutOfBoundsException e) { throw new ConfigException(e, StatusCode.SECTION_OR_KEY_INVALID); } catch (IllegalArgumentException e) { throw new ConfigException(e, null); } catch (IOException e) { throw new ConfigException(e, null); } }
private void checkKeyFormat(String qualifiedKey) { if (qualifiedKey == null) { throw new ConfigException(StatusCode.SECTION_OR_KEY_INVALID); } int firstQualifierIndex = qualifiedKey.indexOf('.'); if (firstQualifierIndex < 1) { throw new ConfigException(StatusCode.SECTION_OR_NAME_NOT_PROVIDED); } if (qualifiedKey.length() == firstQualifierIndex + 1) { throw new ConfigException(StatusCode.SECTION_OR_NAME_NOT_PROVIDED); } }
private void checkKeyFormat(String qualifiedKey) { if (qualifiedKey == null) { throw new ConfigException(StatusCode.SECTION_OR_KEY_INVALID); } int firstQualifierIndex = qualifiedKey.indexOf('.'); if (firstQualifierIndex < 1) { throw new ConfigException(StatusCode.SECTION_OR_NAME_NOT_PROVIDED); } if (qualifiedKey.length() == firstQualifierIndex + 1) { throw new ConfigException(StatusCode.SECTION_OR_NAME_NOT_PROVIDED); } }
@Override public Optional<String> get(String key) { try { return get(new Entry(key), String.class, local()); } catch (IllegalArgumentException e) { throw new ConfigException(e, null); } }
private void removeSection(ConcurrentMap<String, String> config, String section) { checkNotNull(section); final String prefix = section + "."; Set<String> matching = new HashSet<>( Sets.filter(config.keySet(), (k) -> k.startsWith(prefix))); if (matching.isEmpty()) { throw new ConfigException(StatusCode.MISSING_SECTION); } matching.forEach((k) -> { config.remove(k); }); }
@Test public void testConstructors() { RuntimeException parentException = new RuntimeException("message"); ConfigException exception = new ConfigException(ConfigException.StatusCode.CANNOT_WRITE); assertEquals(null, exception.getCause()); assertEquals(ConfigException.StatusCode.CANNOT_WRITE, exception.statusCode); exception = new ConfigException(parentException, ConfigException.StatusCode.CANNOT_WRITE); assertEquals(parentException, exception.getCause()); assertEquals(ConfigException.StatusCode.CANNOT_WRITE, exception.statusCode); }
@Test public void testGetLocalWithNoLocalRepository() { ConfigDatabase database = mock(ConfigDatabase.class); when(database.get(anyString())).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION)); ConfigOp config = new ConfigOp(database); exception.expect(ConfigException.class); config.setScope(ConfigScope.LOCAL).setAction(ConfigAction.CONFIG_GET).setName("section.key") .setValue(null).call(); }
@Test public void testGetLocalWithNoLocalRepository() { ConfigDatabase database = mock(ConfigDatabase.class); when(database.get(anyString())).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION)); ConfigOp config = new ConfigOp(database); exception.expect(ConfigException.class); config.setScope(ConfigScope.LOCAL).setAction(ConfigAction.CONFIG_GET).setName("section.key") .setValue(null).call(); }