From f8df95996f40215aef7377afd2cab74dbc023944 Mon Sep 17 00:00:00 2001 From: Sasha Date: Fri, 26 Apr 2013 18:24:44 +0100 Subject: [PATCH] Add new methods --- .../compbio/engine/conf/PropertyHelperManager.java | 90 +++++++++++--------- 1 file changed, 52 insertions(+), 38 deletions(-) diff --git a/engine/compbio/engine/conf/PropertyHelperManager.java b/engine/compbio/engine/conf/PropertyHelperManager.java index b3d2b66..bf33409 100644 --- a/engine/compbio/engine/conf/PropertyHelperManager.java +++ b/engine/compbio/engine/conf/PropertyHelperManager.java @@ -35,18 +35,27 @@ public final class PropertyHelperManager { public static final String confDir = "conf" + File.separator; /** - * Ways to fix path problem: 1) find a path to WEB-INF directory based on - * the path to a known class. Then prepend this absolute path to the rest of - * paths pros: no input from user cons: relocation of the source may cause - * problems 2) Require users to add configuration directories to the class - * path and then load entries from it. pros: cons: Many paths needs to be - * added. Put significant burden on the user. Hard to tell web appl server - * to add these entries to its class path. 3) Ask for project source - * directory explicitly in the configuration. pros cons: similar to 1, but - * this initial configuration file must reside in well known location! Why - * ask users what can be found automatically? 4) Have everything in the - * location already in class path for tomcat. cons: only classes and - * lib/*.jar are added, eclipse will remove non classses from classes dir. + * Ways to fix path problem: + * 1) find a path to WEB-INF directory based on the path to a known class. + * Then prepend this absolute path to the rest of paths + * pros: no input from user + * cons: relocation of the source may cause problems + * + * 2) Require users to add configuration directories to the class + * path and then load entries from it. + * pros: + * cons: Many paths needs to be added. Put significant burden on the user. + * Hard to tell web appl server to add these entries to its class path. + * + * 3) Ask for project source directory explicitly in the configuration. + * pros: + * cons: similar to 1, but this initial configuration file must reside in + * well known location! Why ask users what can be found automatically? + * + * 4) Have everything in the location already in class path for tomcat. + * pros: + * cons: only classes and lib/*.jar are added, Eclipse will remove non + * classses from classes dir. * * Try 1 - succeed. * @@ -55,20 +64,13 @@ public final class PropertyHelperManager { public static PropertyHelper getPropertyHelper() { if (ph == null) { try { - File locEngineProp = getResourceFromClasspath(confDir - + "Engine.local.properties"); - File clustEngineProp = getResourceFromClasspath(confDir - + "Engine.cluster.properties"); - File execProp = getResourceFromClasspath(confDir - + "Executable.properties"); - File gaProp = getResourceFromClasspath(confDir - + "GA.properties"); - ph = new PropertyHelper(locEngineProp, clustEngineProp, - execProp, gaProp); + File locEngineProp = getResourceFromClasspath(confDir + "Engine.local.properties"); + File clustEngineProp = getResourceFromClasspath(confDir + "Engine.cluster.properties"); + File execProp = getResourceFromClasspath(confDir + "Executable.properties"); + File gaProp = getResourceFromClasspath(confDir + "GA.properties"); + ph = new PropertyHelper(locEngineProp, clustEngineProp, execProp, gaProp); } catch (IOException e) { - log.warn( - "Cannot read property files! Reason: " - + e.getLocalizedMessage(), e.getCause()); + log.warn("Cannot read property files! Reason: " + e.getLocalizedMessage(), e.getCause()); } } return ph; @@ -79,17 +81,19 @@ public final class PropertyHelperManager { String locPath = getLocalPath(); File prop = new File(locPath + resourceName); if (!prop.exists()) { - log.warn("Could not find a resource " + resourceName - + " in the classpath!"); + log.warn("Could not find a resource " + resourceName + " in the classpath!"); } return prop; } /** * Method return the absolute path to the project root directory. It assumes - * the following structure of the project project root conf settings - * binaries WEB-INF classes compbio engine conf If the structure changes it - * must be reflected in this method + * the following structure of the project: + * project-root: + * conf/settings + * binaries + * WEB-INF/classes/compbio/engine/conf/PropertyHelperManager.class + * If the structure changes it must be reflected in this method * * @return the local path * @throws RuntimeException @@ -106,8 +110,7 @@ public final class PropertyHelperManager { f = f.getParentFile(); } } catch (URISyntaxException e) { - String message = "Could not find resources path! Problems locating PropertyHelperManager class! " - + e.getLocalizedMessage(); + String message = "Could not find resources path! Problems locating PropertyHelperManager class! " + e.getLocalizedMessage(); log.error(message, e.getCause()); throw new RuntimeException(message, e.getCause()); } catch (IllegalArgumentException e) { @@ -129,14 +132,25 @@ public final class PropertyHelperManager { f = f.getParentFile(); } } catch (URISyntaxException e1) { - log.error( - "Could not find resources path! " - + e1.getLocalizedMessage(), e1.getCause()); - throw new RuntimeException("Could not find resources path! ", - e1.getCause()); + log.error("Could not find resources path! " + e1.getLocalizedMessage(), e1.getCause()); + throw new RuntimeException("Could not find resources path! ", e1.getCause()); } } log.debug("Project directory is: " + f.getAbsolutePath()); return f.getAbsolutePath() + File.separator; } -} + + public static int getIntProperty(String propValue) { + if (!Util.isEmpty(propValue)) { + return Integer.parseInt(propValue.trim()); + } + return -1; + } + + public static boolean getBooleanProperty(String propValue) { + if (!Util.isEmpty(propValue)) { + propValue = propValue.trim(); + return Boolean.parseBoolean(propValue); + } + return false; + }} -- 1.7.10.2