use of org.apache.commons.configuration2.SubnodeConfiguration in project commons-configuration by apache.
the class BaseHierarchicalConfiguration method createConnectedSubConfiguration.
/**
* Creates a sub configuration from the specified key which is connected to this configuration. This implementation
* creates a {@link SubnodeConfiguration} with a tracked node identified by the passed in key.
*
* @param key the key of the sub configuration
* @return the new sub configuration
*/
private BaseHierarchicalConfiguration createConnectedSubConfiguration(final String key) {
final NodeSelector selector = getSubConfigurationNodeSelector(key);
getSubConfigurationParentModel().trackNode(selector, this);
return createSubConfigurationForTrackedNode(selector, this);
}
use of org.apache.commons.configuration2.SubnodeConfiguration in project commons-configuration by apache.
the class INIConfiguration method getGlobalSection.
/**
* Creates a sub configuration for the global section of the represented INI configuration.
*
* @return the sub configuration for the global section
*/
private SubnodeConfiguration getGlobalSection() {
final InMemoryNodeModel parentModel = getSubConfigurationParentModel();
// selects parent
final NodeSelector selector = new NodeSelector(null);
parentModel.trackNode(selector, this);
final GlobalSectionNodeModel model = new GlobalSectionNodeModel(this, selector);
final SubnodeConfiguration sub = new SubnodeConfiguration(this, model);
initSubConfigurationForThisParent(sub);
return sub;
}
use of org.apache.commons.configuration2.SubnodeConfiguration in project commons-configuration by apache.
the class TestSubnodeConfiguration method testClose.
/**
* Tests whether the configuration can be closed.
*/
@Test
public void testClose() {
final TrackedNodeModel model = EasyMock.createMock(TrackedNodeModel.class);
EasyMock.expect(model.getSelector()).andReturn(SELECTOR).anyTimes();
model.close();
EasyMock.replay(model);
final SubnodeConfiguration config = new SubnodeConfiguration(parent, model);
config.close();
EasyMock.verify(model);
}
use of org.apache.commons.configuration2.SubnodeConfiguration in project commons-configuration by apache.
the class TestSubnodeConfiguration method testClone.
/**
* Tests whether a clone of a sub configuration can be created.
*/
@Test
public void testClone() {
setUpSubnodeConfig();
final SubnodeConfiguration copy = (SubnodeConfiguration) config.clone();
assertNotSame("Same model", config.getModel(), copy.getModel());
final TrackedNodeModel subModel = (TrackedNodeModel) copy.getModel();
assertEquals("Wrong selector", SELECTOR, subModel.getSelector());
final InMemoryNodeModel parentModel = (InMemoryNodeModel) parent.getModel();
assertEquals("Wrong parent model", parentModel, subModel.getParentModel());
// Check whether the track count was increased
parentModel.untrackNode(SELECTOR);
parentModel.untrackNode(SELECTOR);
assertTrue("Wrong finalize flag", subModel.isReleaseTrackedNodeOnFinalize());
}
use of org.apache.commons.configuration2.SubnodeConfiguration in project commons-configuration by apache.
the class TestBaseHierarchicalConfigurationSynchronization method isDetached.
/**
* Tests whether the specified configuration is detached.
*
* @param c the configuration to test
* @return a flag whether the root node of this configuration is detached
*/
private static boolean isDetached(final HierarchicalConfiguration<ImmutableNode> c) {
assertTrue("Not a sub configuration", c instanceof SubnodeConfiguration);
final InMemoryNodeModel nodeModel = ((SubnodeConfiguration) c).getRootNodeModel();
return nodeModel.isTrackedNodeDetached(((SubnodeConfiguration) c).getRootSelector());
}
Aggregations