X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fcallhome-provider%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fcallhome%2Fmount%2FConfiguration.java;h=ab6c997ef3d9e007af43e82c6ae7877ae2c6fa89;hb=9916153467456756d7f6a8678bb2ee1b990915e5;hp=6a5c11b677e21d66117f98b3be40c4dc035c841e;hpb=6d7e12bf3ef64e5004703a1d540e7e26f30a9595;p=netconf.git diff --git a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/Configuration.java b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/Configuration.java index 6a5c11b677..ab6c997ef3 100644 --- a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/Configuration.java +++ b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/Configuration.java @@ -16,25 +16,31 @@ import java.util.Properties; public class Configuration { public abstract static class ConfigurationException extends RuntimeException { - ConfigurationException(String msg) { + private static final long serialVersionUID = -7759423506815697761L; + + ConfigurationException(final String msg) { super(msg); } - ConfigurationException(String msg, Exception cause) { + ConfigurationException(final String msg, final Exception cause) { super(msg, cause); } } public static class ReadException extends ConfigurationException { - ReadException(String msg, Exception exc) { + private static final long serialVersionUID = 1661483843463184121L; + + ReadException(final String msg, final Exception exc) { super(msg, exc); } } public static class MissingException extends ConfigurationException { + private static final long serialVersionUID = 3406998256398889038L; + private final String key; - MissingException(String key) { + MissingException(final String key) { super("Key not found: " + key); this.key = key; } @@ -45,15 +51,23 @@ public class Configuration { } public static class IllegalValueException extends ConfigurationException { + private static final long serialVersionUID = -1172346869408302687L; + private final String key; private final String value; - IllegalValueException(String key, String value) { + IllegalValueException(final String key, final String value) { super("Key has an illegal value. Key: " + key + ", Value: " + value); this.key = key; this.value = value; } + IllegalValueException(final String key, final String value, final Exception cause) { + super("Key has an illegal value. Key: " + key + ", Value: " + value, cause); + this.key = key; + this.value = value; + } + public String getKey() { return key; } @@ -63,16 +77,13 @@ public class Configuration { } } - private String path; private Properties properties; public Configuration() { - path = ""; properties = new Properties(); } - public Configuration(String path) throws ConfigurationException { - this.path = path; + public Configuration(final String path) throws ConfigurationException { try { this.properties = readFromPath(path); } catch (IOException ioe) { @@ -80,27 +91,27 @@ public class Configuration { } } - private Properties readFromPath(String path) throws IOException { - return readFromFile(new File(path)); + private Properties readFromPath(final String filePath) throws IOException { + return readFromFile(new File(filePath)); } - private Properties readFromFile(File file) throws IOException { + private Properties readFromFile(final File file) throws IOException { FileInputStream stream = new FileInputStream(file); properties = readFrom(stream); return properties; } - private Properties readFrom(InputStream stream) throws IOException { + private static Properties readFrom(final InputStream stream) throws IOException { Properties properties = new Properties(); properties.load(stream); return properties; } - public void set(String key, String value) { + public void set(final String key, final String value) { properties.setProperty(key, value); } - String get(String key) { + String get(final String key) { String result = (String) properties.get(key); if (result == null) { throw new MissingException(key); @@ -108,7 +119,7 @@ public class Configuration { return result; } - public int getAsPort(String key) { + public int getAsPort(final String key) { String keyValue = get(key); try { int newPort = Integer.parseInt(keyValue); @@ -117,7 +128,7 @@ public class Configuration { } return newPort; } catch (NumberFormatException e) { - throw new IllegalValueException(key, keyValue); + throw new IllegalValueException(key, keyValue, e); } } }