Mercurial > hg > openmind
view src/main/java/org/mpi/openmind/configuration/ConfigurationService.java @ 85:1aff84e5048d
configuration option for queryBrowserUrl.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 20 Oct 2017 12:48:31 +0200 |
parents | 58659e865279 |
children |
line wrap: on
line source
package org.mpi.openmind.configuration; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; import org.apache.log4j.Logger; import org.mpi.openmind.configuration.ownvalue.OwnValueRule; import org.mpi.openmind.configuration.ownvalue.PrintRule; import org.mpi.openmind.configuration.ownvalue.loader.OwnValueRulesLoader; import org.mpi.openmind.configuration.ownvalue.loader.PrintRulesLoader; public class ConfigurationService { private static Logger logger = Logger.getLogger(ConfigurationService.class); /* static{ logger.setLevel(Level.DEBUG); PatternLayout layout = new PatternLayout("%d{ABSOLUTE} %5p %c{1}:%L - %m%n"); Appender stdout = new ConsoleAppender(layout, "System.out"); logger.addAppender(stdout); } */ //Property's names public static String SCHEDULING_PATH = "scheduling-path"; public static String SCHEDULING_ENABLE = "scheduling-enable"; public static String INSTANCE_NAME = "instance-name"; public static String QUERY_BROWSER_URL = "query-browser-url"; public static String DEBUG_MODUS = "debug-modus"; //File's names private static String OWN_VALUE_CONF = "own-value.cfg.xml"; private static String OM_PROPERTIES = "openmind.properties"; //private static String OWN_VALUE_CONF = "conf/own-value.cfg.xml"; private Properties props = new Properties(); private Map<String, OwnValueRule> ownValueRules = new HashMap<String, OwnValueRule>(); private List<PrintRule> printRules = new ArrayList<PrintRule>(); private String schedulingPath; private String instanceName; private String queryBrowserUrl; private boolean schedulingEnable = false; private boolean debugModus = false; public ConfigurationService(){ logger.info("\n### Initialize Configuration Service ###\n"); loadOwnValueRules(); loadProperties(); } private void loadProperties(){ try { InputStream in = this.getClass().getClassLoader().getResourceAsStream(OM_PROPERTIES); props.load(in); in.close(); String s = "Property's List"; for (Object key : props.keySet()) { s += "\n" + key + "=\t" + props.getProperty(key.toString()); if (SCHEDULING_ENABLE.equals(key.toString())) { try { Boolean b = new Boolean(props.getProperty(key.toString())); this.schedulingEnable = b; } catch (Exception e) { } } else if (SCHEDULING_PATH.equals(key.toString())) { this.schedulingPath = props.getProperty(key.toString()); } else if (INSTANCE_NAME.equals(key.toString())) { this.instanceName = props.getProperty(key.toString()); } else if (QUERY_BROWSER_URL.equals(key.toString())) { this.queryBrowserUrl = props.getProperty(key.toString()); } else if (DEBUG_MODUS.equals(key.toString())) { try { Boolean b = new Boolean(props.getProperty(key.toString())); this.debugModus = b; } catch (Exception e) { } } } s += "\n"; logger.info(s); } catch (IOException e) { logger.error("Properties file \'" + OM_PROPERTIES + " no found."); } } private void loadOwnValueRules(){ try{ this.ownValueRules = OwnValueRulesLoader.load(OWN_VALUE_CONF); this.printRules = PrintRulesLoader.load(OWN_VALUE_CONF); String s = "\n### Print Rules ###\n"; for(PrintRule printRule : this.printRules){ s += printRule + "\n"; } s += "### Own Value Rules ###\n"; for(OwnValueRule ownValueRule : this.ownValueRules.values()){ s += ownValueRule + "\n"; } logger.info(s); }catch(Exception e){ e.printStackTrace(); } } public List<PrintRule> getPrintRules(String objectClass){ List<PrintRule> ruleList = new ArrayList<PrintRule>(); for(PrintRule rule : this.printRules){ if(rule.containObjectClass(objectClass)){ ruleList.add(rule); } } return ruleList; } public OwnValueRule getOwnValueRule(String id){ return this.ownValueRules.get(id); } public Map<String, OwnValueRule> getOwnValueRules() { return ownValueRules; } public void setPrintRules(List<PrintRule> printRules) { this.printRules = printRules; } public String getSchedulingPath() { return schedulingPath; } public boolean isSchedulingEnable() { return schedulingEnable; } public String getInstanceName() { return instanceName; } /** * @return the queryBrowserUrl */ public String getQueryBrowserUrl() { return queryBrowserUrl; } public boolean isDebugModus() { return debugModus; } }