@Override public String getAttribute(String attributeName) { return getAttribute(attributeName, null); }
public ConfigurationProperty(String propertyName, String value) { super("Property", new HashMap<String, String>()); this.addAttribute("Name", propertyName); this.addAttribute("Value", value); } }
@Override public List<Configuration> getChildren() { return convertNodeList(configurationNode.getChildNodes()); }
public JasDBConfigurationLoader() throws ConfigurationException { try { String overrideConfigProperty = System.getProperty("jasdb-config"); if(StringUtils.stringEmpty(overrideConfigProperty)) { this.configuration = XMLConfiguration.loadConfiguration(JASDB_CONFIG); } else { LOG.info("Override configuration path specified: {}", overrideConfigProperty); this.configuration = XMLConfiguration.loadConfiguration(overrideConfigProperty); } } catch (CoreConfigException e) { try { this.configuration = XMLConfiguration.loadConfiguration(FALLBACK_JASDB_XML); } catch(CoreConfigException ex) { throw new ConfigurationException("Unable to load Default JasDB configuration file", ex); } } }
@Override public Configuration getChildConfiguration(String configurationPath) { try { XPath xpath = getXpath(); Node foundNode = (Node) xpath.evaluate(configurationPath, this.configurationNode, XPathConstants.NODE); if(foundNode != null) { return new XMLConfiguration(foundNode); } } catch(XPathExpressionException e) { LOG.error("Unable to find the configuration for path: " + configurationPath, e.getMessage()); } return null; }
@Override public List<Configuration> getChildConfigurations(String configurationPath) { try { XPath xpath = getXpath(); NodeList foundNodes = (NodeList) xpath.evaluate(configurationPath, this.configurationNode, XPathConstants.NODESET); return convertNodeList(foundNodes); } catch(XPathExpressionException e) { LOG.error("Unable to find the child configurations for path: " + configurationPath, e.getMessage()); } return Collections.emptyList(); }
private List<Configuration> convertNodeList(NodeList nodeList) { List<Configuration> loadedConfigurations = new ArrayList<Configuration>(); for(int i=0; i<nodeList.getLength(); i++) { if(nodeList.item(i) instanceof Element) { loadedConfigurations.add(new XMLConfiguration(nodeList.item(i))); } } return loadedConfigurations; }
@Override public String getAttribute(String attributeName, String defaultValue) { try { XPath xpath = getXpath(); String result = (String) xpath.evaluate("./@" + attributeName, this.configurationNode, XPathConstants.STRING); if(result != null && !result.isEmpty()) { return result; } else { return defaultValue; } } catch(XPathExpressionException e) { LOG.error("Unable to find the value for attribute: " + attributeName, e.getMessage()); return defaultValue; } }
private static synchronized void loadKeyFactories() { try { Map<String, KeyFactoryDefinition> definitions = new HashMap<>(); Configuration keyFactoriesConfig = XMLConfiguration.loadConfiguration("db_keyfactories.xml"); List<Configuration> keyFactoryConfigs = keyFactoriesConfig.getChildConfigurations("/keyFactories/keyFactory"); for(Configuration keyFactoryConfig : keyFactoryConfigs) { String keyFactoryClass = keyFactoryConfig.getAttribute("class"); String keyFactoryId = keyFactoryConfig.getAttribute("id"); KeyFactoryDefinition definition = new KeyFactoryDefinition(keyFactoryClass, keyFactoryId); definitions.put(keyFactoryId, definition); } instance = new KeyFactoryManager(definitions); } catch(CoreConfigException e) { LOG.error("unable to load key factories", e); } }
@Override public boolean hasAttribute(String attributeName) { return getAttribute(attributeName) != null ? true : false; }
public static Configuration loadConfiguration(String fileName) throws CoreConfigException { LOG.info("Loading configuration: {}", fileName); Document document = XMLReader.getDocument(fileName); return new XMLConfiguration(document.getDocumentElement()); }
@Override public boolean getAttribute(String attributeName, boolean defaultValue) { String value = getAttribute(attributeName, null); if(value != null) { return Boolean.valueOf(value) ? true : defaultValue; } else { return defaultValue; } }
@Override public int getAttribute(String attributeName, int defaultValue) { String value = getAttribute(attributeName, null); if(value != null) { try { return Integer.parseInt(value); } catch(NumberFormatException e) { LOG.error("Unable to parse configuration attribute: {} with value: {}", attributeName, value); } } return defaultValue; }