Search in sources :

Example 1 with SubnodeConfiguration

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);
}
Also used : NodeSelector(org.apache.commons.configuration2.tree.NodeSelector)

Example 2 with SubnodeConfiguration

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;
}
Also used : InMemoryNodeModel(org.apache.commons.configuration2.tree.InMemoryNodeModel) NodeSelector(org.apache.commons.configuration2.tree.NodeSelector)

Example 3 with SubnodeConfiguration

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);
}
Also used : TrackedNodeModel(org.apache.commons.configuration2.tree.TrackedNodeModel) Test(org.junit.Test)

Example 4 with SubnodeConfiguration

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());
}
Also used : InMemoryNodeModel(org.apache.commons.configuration2.tree.InMemoryNodeModel) TrackedNodeModel(org.apache.commons.configuration2.tree.TrackedNodeModel) Test(org.junit.Test)

Example 5 with SubnodeConfiguration

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());
}
Also used : InMemoryNodeModel(org.apache.commons.configuration2.tree.InMemoryNodeModel)

Aggregations

InMemoryNodeModel (org.apache.commons.configuration2.tree.InMemoryNodeModel)3 TrackedNodeModel (org.apache.commons.configuration2.tree.TrackedNodeModel)3 Test (org.junit.Test)3 SubnodeConfiguration (org.apache.commons.configuration2.SubnodeConfiguration)2 NodeSelector (org.apache.commons.configuration2.tree.NodeSelector)2 PgBouncerIniParameter (io.stackgres.apiweb.dto.pooling.PgBouncerIniParameter)1 PoolingConfigDto (io.stackgres.apiweb.dto.pooling.PoolingConfigDto)1 PoolingConfigPgBouncer (io.stackgres.apiweb.dto.pooling.PoolingConfigPgBouncer)1 PoolingConfigPgBouncerStatus (io.stackgres.apiweb.dto.pooling.PoolingConfigPgBouncerStatus)1 PoolingConfigSpec (io.stackgres.apiweb.dto.pooling.PoolingConfigSpec)1 PoolingConfigStatus (io.stackgres.apiweb.dto.pooling.PoolingConfigStatus)1 StackGresPoolingConfig (io.stackgres.common.crd.sgpooling.StackGresPoolingConfig)1 StackGresPoolingConfigPgBouncer (io.stackgres.common.crd.sgpooling.StackGresPoolingConfigPgBouncer)1 StackGresPoolingConfigPgBouncerPgbouncerIni (io.stackgres.common.crd.sgpooling.StackGresPoolingConfigPgBouncerPgbouncerIni)1 StackGresPoolingConfigSpec (io.stackgres.common.crd.sgpooling.StackGresPoolingConfigSpec)1 StackGresPoolingConfigStatus (io.stackgres.common.crd.sgpooling.StackGresPoolingConfigStatus)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1