Package org.apache.commons.configuration

Examples of org.apache.commons.configuration.HierarchicalConfiguration$NodeVisitor


    /**
     * Tests fetching nested bean declarations if none are defined.
     */
    public void testGetNestedBeanDeclarationsEmpty()
    {
        HierarchicalConfiguration config = new HierarchicalConfiguration();
        setupBeanDeclaration(config, KEY, TEST_PROPS, TEST_VALUES);
        decl = new XMLBeanDeclaration(config, KEY);
        Map nested = decl.getNestedBeanDeclarations();
        assertTrue("Found nested declarations", nested == null
                || nested.isEmpty());
View Full Code Here


    /**
     * Tests whether interpolation of bean properties works.
     */
    public void testGetInterpolatedBeanProperties()
    {
        HierarchicalConfiguration config = new HierarchicalConfiguration();
        String[] varValues = new String[TEST_PROPS.length];
        for(int i = 0; i < TEST_PROPS.length; i++)
        {
            varValues[i] = "${" + VARS + TEST_PROPS[i] + "}";
            config.addProperty(VARS + TEST_PROPS[i], TEST_VALUES[i]);
        }
        setupBeanDeclaration(config, KEY, TEST_PROPS, varValues);
        decl = new XMLBeanDeclaration(config, KEY);
        checkProperties(decl, TEST_PROPS, TEST_VALUES);
    }
View Full Code Here

     * Tests constructing a bean declaration from an undefined key. This should
     * cause an exception.
     */
    public void testInitFromUndefinedKey()
    {
        HierarchicalConfiguration config = new HierarchicalConfiguration();
        setupBeanDeclaration(config, KEY, TEST_PROPS, TEST_VALUES);
        try
        {
            decl = new XMLBeanDeclaration(config, "undefined_key");
            fail("Could create declaration from an undefined key!");
View Full Code Here

     * created, which can be used for creating beans as long as a default class
     * is provided.
     */
    public void testInitFromUndefinedKeyOptional()
    {
        HierarchicalConfiguration config = new HierarchicalConfiguration();
        setupBeanDeclaration(config, KEY, TEST_PROPS, TEST_VALUES);
        decl = new XMLBeanDeclaration(config, "undefined_key", true);
        assertNull("Found a bean class", decl.getBeanClassName());
    }
View Full Code Here

     * Tests constructing a bean declaration from a key with multiple values.
     * This should cause an exception because keys must be unique.
     */
    public void testInitFromMultiValueKey()
    {
        HierarchicalConfiguration config = new HierarchicalConfiguration();
        config.addProperty(KEY, "myFirstKey");
        config.addProperty(KEY, "mySecondKey");
        try
        {
            decl = new XMLBeanDeclaration(config, KEY);
            fail("Could create declaration from multi-valued property!");
        }
View Full Code Here

        {
            throw new ConfigurationException("Only one external virtualhosts configuration file allowed, multiple filenames found.");
        }

        // Virtualhost configuration object
        Configuration vhostConfiguration = new HierarchicalConfiguration();

        // Load from embedded configuration if possible
        if (!vhostConfig.subset("virtualhost").isEmpty())
        {
            vhostConfiguration = vhostConfig;
        }
        else
        {
        // Load from the external configuration if possible
        for (String fileName : vhostFiles)
          {
              // Open the vhosts XML file and copy values from it to our config
                _vhostsFile = new File(fileName);
                if (!_vhostsFile.exists())
                {
                    throw new ConfigurationException("Virtualhosts file does not exist");
                }
            vhostConfiguration = parseConfig(new File(fileName));

                // save the default virtualhost name
                String defaultVirtualHost = vhostConfiguration.getString("default");
                getConfig().setProperty("virtualhosts.default", defaultVirtualHost);
            }
        }

        // Now extract the virtual host names from the configuration object
        List hosts = vhostConfiguration.getList("virtualhost.name");
        for (int j = 0; j < hosts.size(); j++)
        {
            String name = (String) hosts.get(j);

            // Add the virtual hosts to the server configuration
            VirtualHostConfiguration virtualhost = new VirtualHostConfiguration(name, vhostConfiguration.subset("virtualhost." + name));
            _virtualHosts.put(virtualhost.getName(), virtualhost);
        }
    }
View Full Code Here

public class TestHierarchicalConfigurationEvents extends
        AbstractTestConfigurationEvents
{
    protected AbstractConfiguration createConfiguration()
    {
        return new HierarchicalConfiguration();
    }
View Full Code Here

    /**
     * Tests events generated by the clearTree() method.
     */
    public void testClearTreeEvent()
    {
        HierarchicalConfiguration hc = (HierarchicalConfiguration) config;
        String key = EXIST_PROPERTY.substring(0, EXIST_PROPERTY.indexOf('.'));
        Collection nodes = hc.getExpressionEngine()
                .query(hc.getRootNode(), key);
        hc.clearTree(key);
        l.checkEvent(HierarchicalConfiguration.EVENT_CLEAR_TREE, key, null,
                true);
        l.checkEvent(HierarchicalConfiguration.EVENT_CLEAR_TREE, key, nodes,
                false);
        l.done();
View Full Code Here

    /**
     * Tests events generated by the addNodes() method.
     */
    public void testAddNodesEvent()
    {
        HierarchicalConfiguration hc = (HierarchicalConfiguration) config;
        Collection nodes = new ArrayList(1);
        nodes.add(new DefaultConfigurationNode("a_key", TEST_PROPVALUE));
        hc.addNodes(TEST_PROPNAME, nodes);
        l.checkEvent(HierarchicalConfiguration.EVENT_ADD_NODES, TEST_PROPNAME,
                nodes, true);
        l.checkEvent(HierarchicalConfiguration.EVENT_ADD_NODES, TEST_PROPNAME,
                nodes, false);
        l.done();
View Full Code Here

      }
      child = Property();
            if (child.getValue() instanceof HierarchicalConfiguration)
            {
                // prune & graft the nested configuration to the parent configuration
                HierarchicalConfiguration conf = (HierarchicalConfiguration) child.getValue();
                Node root = conf.getRoot();
                root.setName(child.getName());
                children.add(root);
            }
            else
            {
View Full Code Here

TOP

Related Classes of org.apache.commons.configuration.HierarchicalConfiguration$NodeVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.