private void populateAlternateKeyMap(HierarchicalConfiguration config) { List<SubnodeConfiguration> configurationsAt = config.configurationsAt("/*/" + ALTERNATE_KEY); alternateKeysMap = new HashMap<>(configurationsAt.size()); for (SubnodeConfiguration node : configurationsAt) { String rootKey = node.getRootNode() .getParentNode().getName(); String[] alternateKeys = config.getStringArray("/" + rootKey + "/" + ALTERNATE_KEY); for (String token : alternateKeys) { alternateKeysMap.put(token, rootKey); } } }
/** * This takes a configuration and looks in it for a given name for the tag. Called by {@link #findConfiguration(String, String, String)}. * @param cfg * @param cfgName * @param topNodeTag * @return */ protected static ConfigurationNode findNamedConfig(XMLConfiguration cfg, String cfgName, String topNodeTag) { ConfigurationNode cn = null; if (cfgName == null) { cn = cfg.configurationAt(topNodeTag).getRootNode(); } else { cn = Configurations.getConfig(cfg, topNodeTag, cfgName); } return cn; }
/** * Finds the override configurations that are defined as top level elements * in the configuration definition file. This method will fetch the child * elements of the root node and remove the nodes that represent other * configuration sections. The remaining nodes are treated as definitions * for override configurations. * * @return a list with subnode configurations for the top level override * configurations */ private List<SubnodeConfiguration> fetchTopLevelOverrideConfigs() { List<SubnodeConfiguration> configs = fetchChildConfigs(getRootNode()); for (Iterator<SubnodeConfiguration> it = configs.iterator(); it.hasNext();) { String nodeName = it.next().getRootNode().getName(); for (int i = 0; i < CONFIG_SECTIONS.length; i++) { if (CONFIG_SECTIONS[i].equals(nodeName)) { it.remove(); break; } } } return configs; }
/** * Finds the override configurations that are defined as top level elements * in the configuration definition file. This method will fetch the child * elements of the root node and remove the nodes that represent other * configuration sections. The remaining nodes are treated as definitions * for override configurations. * * @return a list with subnode configurations for the top level override * configurations */ private List<SubnodeConfiguration> fetchTopLevelOverrideConfigs() { List<SubnodeConfiguration> configs = fetchChildConfigs(getRootNode()); for (Iterator<SubnodeConfiguration> it = configs.iterator(); it.hasNext();) { String nodeName = it.next().getRootNode().getName(); for (int i = 0; i < CONFIG_SECTIONS.length; i++) { if (CONFIG_SECTIONS[i].equals(nodeName)) { it.remove(); break; } } } return configs; }
protected static ConfigurationNode getConfig(XMLConfiguration cfg, String topNodeName, String configName, TreeSet<String> checkedAliases) { List list = cfg.configurationsAt(topNodeName); ConfigurationNode configurationNode = null; for (int i = 0; i < list.size(); i++) { SubnodeConfiguration cn = (SubnodeConfiguration) list.get(i); List nameAttribs = cn.getRootNode().getAttributes("name"); for (int j = 0; j < nameAttribs.size(); j++) { ConfigurationNode attrcn = (ConfigurationNode) nameAttribs.get(j); if (attrcn.getValue().equals(configName)) { configurationNode = cn.getRootNode(); } } if (configurationNode != null) { String alias = getFirstAttribute(configurationNode, "alias"); if (alias != null && 0 < alias.length()) { if (checkedAliases.contains(alias)) { throw new MyConfigurationException("Recursive error. The configuration \"" + configName + "\" contains an alias \"" + alias + "\" which refers to itself on resolution. Configuration load is aborted."); } checkedAliases.add(alias); return getConfig(cfg, topNodeName, alias, checkedAliases); } return configurationNode; } } throw new MyConfigurationException("Configuration \"" + configName + "\" not found"); }
if (config.getRootNode().equals(node))
if (config.getRootNode().equals(node))
node = configuration.getRootNode();
tmpnode = tmpconfiguration.getRootNode();