Skip to content

Commit

Permalink
PropertyManager design fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg-Maximchuk committed Jan 12, 2016
1 parent c37eee3 commit 57626ed
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/java/imcode/util/PropertyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import java.util.Properties;

/**
* Intended to load and cache properties from *.properties files.
* Intended to load and cache properties from *.properties files. Be sure that
* {@link PropertyManager#setConfigPathsByRoot} are called before server's configurations was read.
*/
public class PropertyManager {

Expand Down Expand Up @@ -139,7 +140,13 @@ public static String getServerConfProperty(String property) throws IOException {
*/
public static Properties getServerConfProperties() throws IOException {
if (null == configPath || null == serverPropertiesPath) {
setConfigPathsByRoot(Imcms.getPath());
File path = Imcms.getPath();
if (null != path) {
setConfigPathsByRoot(path);
} else {
throw new IOException("ImCMS not initialized yet. Use this to read properties ONLY when " +
"setConfigPathsByRoot() was called before, or use getPropertiesFrom()");
}
}
return getProperties(serverPropertiesPath);
}
Expand All @@ -159,12 +166,9 @@ public static void flush() {
* @throws IOException Throws {@code IOException} if file not found.
*/
private static Properties getProperties(File file) throws IOException {
if (null == configPath) {
setConfigPathsByRoot(Imcms.getPath());
}
Properties properties = CACHE.get(file);
if (properties == null) {
try (FileInputStream in = new FileInputStream(file)) {
try (FileInputStream in = new FileInputStream(file.getAbsolutePath())) {
properties = new Properties();
properties.load(in);
CACHE.put(file, properties);
Expand Down

0 comments on commit 57626ed

Please sign in to comment.