Package org.apache.commons.configuration2.event

Examples of org.apache.commons.configuration2.event.EventSource


    @Test
    public void testGetPropertyTrimNoSplit()
    {
        MapConfiguration config = (MapConfiguration) getConfiguration();
        config.getMap().put(KEY, SPACE_VALUE);
        config.setListDelimiterHandler(new DisabledListDelimiterHandler());
        assertEquals("Wrong trimmed value", SPACE_VALUE, config.getProperty(KEY));
    }
View Full Code Here


        // first clone this configuration
        AbstractConfiguration c = (AbstractConfiguration) ConfigurationUtils
                .cloneConfiguration(this);

        // now perform interpolation
        c.setListDelimiterHandler(new DisabledListDelimiterHandler());
        for (Iterator<String> it = getKeys(); it.hasNext();)
        {
            String key = it.next();
            c.setProperty(key, getList(key));
        }
View Full Code Here

     * @param value the value to be added
     */
    @Override
    protected void addPropertyInternal(String key, Object value)
    {
        ListDelimiterHandler oldHandler = getListDelimiterHandler();
        try
        {
            // temporarily disable delimiter parsing
            setListDelimiterHandler(DisabledListDelimiterHandler.INSTANCE);
            super.addPropertyInternal(key, value);
View Full Code Here

     * from the parent.
     */
    @Test
    public void testSetListDelimiterHandler()
    {
        ListDelimiterHandler handler1 = new DefaultListDelimiterHandler('/');
        ListDelimiterHandler handler2 = new DefaultListDelimiterHandler(';');
        parent.setListDelimiterHandler(handler1);
        setUpSubnodeConfig();
        parent.setListDelimiterHandler(handler2);
        assertEquals("List delimiter handler not obtained from parent",
                handler1, config.getListDelimiterHandler());
View Full Code Here

     * @return Properties created from the Configuration
     */
    public static Properties getProperties(Configuration config)
    {
        Properties props = new Properties();
        ListDelimiterHandler listHandler;
        boolean useDelimiterHandler;

        if(config instanceof AbstractConfiguration)
        {
            listHandler = ((AbstractConfiguration) config).getListDelimiterHandler();
            useDelimiterHandler = true;
        }
        else
        {
            listHandler = null;
            useDelimiterHandler = false;
        }

        for (Iterator<String> keys = config.getKeys(); keys.hasNext();)
        {
            String key = keys.next();
            List<Object> list = config.getList(key);

            String propValue;
            if (useDelimiterHandler)
            {
                try
                {
                    propValue =
                            String.valueOf(listHandler.escapeList(list,
                                    ListDelimiterHandler.NOOP_TRANSFORMER));
                }
                catch (Exception ex)
                {
                    // obviously, the list handler does not support splitting
View Full Code Here

     * test is related to CONFIGURATION-315.
     */
    @Test
    public void testInvalidateEventBeforeAndAfterChange()
    {
        ConfigurationEvent event =
                new ConfigurationEvent(config, ConfigurationEvent.ANY, null, null, true);
        config.onEvent(event);
        assertEquals("No invalidate event fired", 1, listener.invalidateEvents);
        event = new ConfigurationEvent(config, ConfigurationEvent.ANY, null, null, false);
        config.onEvent(event);
        assertEquals("Another invalidate event fired", 1,
                listener.invalidateEvents);
    }
View Full Code Here

        conf = new PotentialErrorJNDIConfiguration(ctx);

        nonStringTestHolder = new NonStringTestHolder();
        nonStringTestHolder.setConfiguration(conf);

        listener = new ErrorListenerTestImpl(conf);
        conf.addEventListener(ConfigurationErrorEvent.ANY, listener);
    }
View Full Code Here

     */
    @Test
    public void testCloneModify()
    {
        MapConfiguration config = (MapConfiguration) getConfiguration();
        config.addEventListener(ConfigurationEvent.ANY, new EventListenerTestImpl(config));
        MapConfiguration copy = (MapConfiguration) config.clone();
        assertTrue("Event listeners were copied", copy
                .getEventListeners(ConfigurationEvent.ANY).isEmpty());

        config.addProperty("cloneTest", Boolean.TRUE);
View Full Code Here

        ConfigurationBuilder<BaseHierarchicalConfiguration> builder =
                createBuilderMock(conf);
        EasyMock.replay(builder);
        BuilderConfigurationWrapperFactory factory =
                new BuilderConfigurationWrapperFactory(EventSourceSupport.DUMMY);
        EventSource src =
                (EventSource) factory.createBuilderConfigurationWrapper(
                        HierarchicalConfiguration.class, builder);
        src.addEventListener(ConfigurationEvent.ANY, null);
    }
View Full Code Here

        EventListener<ConfigurationEvent> l1 = new EventListenerTestImpl(null);
        EventListener<ConfigurationEvent> l2 = new EventListenerTestImpl(null);
        BuilderConfigurationWrapperFactory factory =
                new BuilderConfigurationWrapperFactory(
                        EventSourceSupport.BUILDER);
        EventSource src =
                (EventSource) factory.createBuilderConfigurationWrapper(
                        Configuration.class, builder);

        src.addEventListener(ConfigurationEvent.ANY, l1);
        src.addEventListener(ConfigurationEvent.ANY_HIERARCHICAL, l2);
        assertTrue(
                "Wrong result for existing listener",
                src.removeEventListener(ConfigurationEvent.ANY_HIERARCHICAL, l2));
        assertFalse(
                "Wrong result for non-existing listener",
                src.removeEventListener(ConfigurationEvent.ANY_HIERARCHICAL, l2));
        PropertiesConfiguration config = builder.getConfiguration();
        Collection<EventListener<? super ConfigurationEvent>> listeners =
                config.getEventListeners(ConfigurationEvent.ANY_HIERARCHICAL);
        assertTrue("Registered listener not found", listeners.contains(l1));
        assertFalse("Removed listener still found", listeners.contains(l2));
View Full Code Here

TOP

Related Classes of org.apache.commons.configuration2.event.EventSource

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.