/** * Checks if this configuration is empty. Empty means that there are no keys * with any values, though there can be some (empty) nodes. * * @return a flag if this configuration is empty */ public boolean isEmpty() { return !nodeDefined(getRootNode()); }
@Override public ConfigurationNode getRootNode() { return getConfig().getRootNode(); }
@Override public ConfigurationNode getRootNode() { return getConfig().getRootNode(); }
/** * Checks if this configuration is empty. Empty means that there are no keys * with any values, though there can be some (empty) nodes. * * @return a flag if this configuration is empty */ public boolean isEmpty() { return !nodeDefined(getRootNode()); }
/** * {@inheritDoc} */ @Override public void serialize(HierarchicalConfiguration configuration, OutputStream output) throws ConfigurationException { StringWriter writer = new StringWriter(); yaml.dump(traverseTreeAndEmit(configuration.getRootNode()), writer); try { output.write(writer.toString().getBytes()); } catch (IOException e) { throw new ConfigurationException("IOException caught.", e); } } }
List<HierarchicalConfiguration> nodes = config.configurationsAt("attrs/attr"); for(HierarchicalConfiguration c : nodes ) { ConfigurationNode node = c.getRootNode(); System.out.println( "name:" + ((ConfigurationNode) node.getAttributes("name").get(0)).getValue() + " VAL:" + ((ConfigurationNode) node.getAttributes("val").get(0)).getValue()); }
/** * Clears this configuration. This is a more efficient implementation than * the one inherited from the base class. It directly removes all data from * the root node. */ @Override public void clear() { fireEvent(EVENT_CLEAR, null, null, true); getRootNode().removeAttributes(); getRootNode().removeChildren(); getRootNode().setValue(null); fireEvent(EVENT_CLEAR, null, null, false); }
/** * Clears this configuration. This is a more efficient implementation than * the one inherited from the base class. It directly removes all data from * the root node. */ @Override public void clear() { fireEvent(EVENT_CLEAR, null, null, true); getRootNode().removeAttributes(); getRootNode().removeChildren(); getRootNode().setValue(null); fireEvent(EVENT_CLEAR, null, null, false); }
/** * Helper method for fetching a list of all nodes that are addressed by the * specified key. * * @param key the key * @return a list with all affected nodes (never <b>null </b>) */ protected List<ConfigurationNode> fetchNodeList(String key) { return getExpressionEngine().query(getRootNode(), key); }
/** * Helper method for fetching a list of all nodes that are addressed by the * specified key. * * @param key the key * @return a list with all affected nodes (never <b>null </b>) */ protected List<ConfigurationNode> fetchNodeList(String key) { return getExpressionEngine().query(getRootNode(), key); }
/** * Returns an iterator with all keys defined in this configuration. * Note that the keys returned by this method will not contain any * indices. This means that some structure will be lost.</p> * * @return an iterator with the defined keys in this configuration */ public Iterator<String> getKeys() { DefinedKeysVisitor visitor = new DefinedKeysVisitor(); getRootNode().visit(visitor); return visitor.getKeyList().iterator(); }
/** * Returns an iterator with all keys defined in this configuration. * Note that the keys returned by this method will not contain any * indices. This means that some structure will be lost.</p> * * @return an iterator with the defined keys in this configuration */ public Iterator<String> getKeys() { DefinedKeysVisitor visitor = new DefinedKeysVisitor(); getRootNode().visit(visitor); return visitor.getKeyList().iterator(); }
public static boolean iterateAllKeys(ConfigKeyFactory factory, HierarchicalConfiguration config, ConfigKeyHandler handler) { List<ConfigurationNode> configNodes = config.getRootNode().getChildren(); for (ConfigurationNode node : configNodes) { ConfigKey key = factory.generateByPropertiesKey(node.getName()); if (!handler.handle(key)) { return true; } } return false; }
/** * Obtains a list with the nodes referred to by the specified key. This * method queries the expression engine of the wrapped configuration to * resolve the key. * * @param key the configuration key * @return a list with the configuration nodes this key points to */ private List<ConfigurationNode> nodesForKey(String key) { return getConfiguration().getExpressionEngine().query( getConfiguration().getRootNode(), key); }
/** * Adds the property with the specified key. This task will be delegated to * the associated {@code ExpressionEngine}, so the passed in key * must match the requirements of this implementation. * * @param key the key of the new property * @param obj the value of the new property */ @Override protected void addPropertyDirect(String key, Object obj) { NodeAddData data = getExpressionEngine().prepareAdd(getRootNode(), key); ConfigurationNode node = processNodeAddData(data); node.setValue(obj); }
/** * Adds the property with the specified key. This task will be delegated to * the associated {@code ExpressionEngine}, so the passed in key * must match the requirements of this implementation. * * @param key the key of the new property * @param obj the value of the new property */ @Override protected void addPropertyDirect(String key, Object obj) { NodeAddData data = getExpressionEngine().prepareAdd(getRootNode(), key); ConfigurationNode node = processNodeAddData(data); node.setValue(obj); }
/** * Creates a new instance of {@code HierarchicalConfiguration} and * copies all data contained in the specified configuration into the new * one. * * @param c the configuration that is to be copied (if <b>null</b>, this * constructor will behave like the standard constructor) * @since 1.4 */ public HierarchicalConfiguration(HierarchicalConfiguration c) { this(); if (c != null) { CloneVisitor visitor = new CloneVisitor(); c.getRootNode().visit(visitor); setRootNode(visitor.getClone()); } }
/** * Prints all configuration values. Is the actual execution of the 'get-all' action ('-a', '--all') */ private void printAllValues() { List<ConfigurationNode> configNodes = keysConfig.getRootNode().getChildren(); for (ConfigurationNode node : configNodes) { ConfigKey key = configKeyFactory.generateByPropertiesKey(node.getName()); // TODO - move to one statement for all - time permitting; try { printAllValuesForKey(key.getKey()); } catch (Exception exception) { log.error("Error while retrieving value for key \"{}\".", key.getKey(), exception); } } }
/** * Creates a new instance of {@code HierarchicalConfiguration} and * copies all data contained in the specified configuration into the new * one. * * @param c the configuration that is to be copied (if <b>null</b>, this * constructor will behave like the standard constructor) * @since 1.4 */ public HierarchicalConfiguration(HierarchicalConfiguration c) { this(); if (c != null) { CloneVisitor visitor = new CloneVisitor(); c.getRootNode().visit(visitor); setRootNode(visitor.getClone()); } }
/** * Prints all reloadable configuration keys. Is the actual execution of the 'list' action ('-l', '--list') with the * --only-reloadable flag */ public void printReloadableKeys() { List<ConfigurationNode> configNodes = keysConfig.getRootNode().getChildren(); for (ConfigurationNode node : configNodes) { ConfigKey key = configKeyFactory.generateByPropertiesKey(node.getName()); if (key.isReloadable()) { printKeyInFormat(key); } } }