Return-Path:
X-Original-To: apmail-commons-commits-archive@minotaur.apache.org
Delivered-To: apmail-commons-commits-archive@minotaur.apache.org
Received: from mail.apache.org (hermes.apache.org [140.211.11.3])
by minotaur.apache.org (Postfix) with SMTP id B1462E2E1
for ;
Tue, 1 Jan 2013 10:47:34 +0000 (UTC)
Received: (qmail 98072 invoked by uid 500); 1 Jan 2013 10:47:34 -0000
Delivered-To: apmail-commons-commits-archive@commons.apache.org
Received: (qmail 97967 invoked by uid 500); 1 Jan 2013 10:47:34 -0000
Mailing-List: contact commits-help@commons.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: dev@commons.apache.org
Delivered-To: mailing list commits@commons.apache.org
Received: (qmail 97959 invoked by uid 99); 1 Jan 2013 10:47:34 -0000
Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230)
by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Jan 2013 10:47:34 +0000
X-ASF-Spam-Status: No, hits=-2000.0 required=5.0
tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4)
by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Jan 2013 10:47:29 +0000
Received: from eris.apache.org (localhost [127.0.0.1])
by eris.apache.org (Postfix) with ESMTP id 40E4F238890D;
Tue, 1 Jan 2013 10:47:08 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r1427351 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration/builder/combined/
test/java/org/apache/commons/configuration/builder/combined/ test/resources/
Date: Tue, 01 Jan 2013 10:47:07 -0000
To: commits@commons.apache.org
From: oheger@apache.org
X-Mailer: svnmailer-1.0.8-patched
Message-Id: <20130101104708.40E4F238890D@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
Author: oheger
Date: Tue Jan 1 10:47:07 2013
New Revision: 1427351
URL: http://svn.apache.org/viewvc?rev=1427351&view=rev
Log:
Added a specialized combined configuration builder with reloading support.
Added:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/ReloadingCombinedConfigurationBuilder.java (with props)
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestReloadingCombinedConfigurationBuilder.java (with props)
commons/proper/configuration/trunk/src/test/resources/testCCReloading.xml (with props)
commons/proper/configuration/trunk/src/test/resources/testCCReloadingNested.xml (with props)
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilderProvider.java
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilderProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilderProvider.java?rev=1427351&r1=1427350&r2=1427351&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilderProvider.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/CombinedConfigurationBuilderProvider.java Tue Jan 1 10:47:07 2013
@@ -47,6 +47,10 @@ public class CombinedConfigurationBuilde
private static final String BUILDER_CLASS =
"org.apache.commons.configuration.builder.combined.CombinedConfigurationBuilder";
+ /** Constant for the name of the supported reloading builder class. */
+ private static final String RELOADING_BUILDER_CLASS =
+ "org.apache.commons.configuration.builder.combined.ReloadingCombinedConfigurationBuilder";
+
/** Constant for the name of the supported configuration class. */
private static final String CONFIGURATION_CLASS =
"org.apache.commons.configuration.CombinedConfiguration";
@@ -64,8 +68,8 @@ public class CombinedConfigurationBuilde
*/
public CombinedConfigurationBuilderProvider()
{
- super(BUILDER_CLASS, BUILDER_CLASS, CONFIGURATION_CLASS, Arrays.asList(
- COMBINED_PARAMS, FILE_PARAMS));
+ super(BUILDER_CLASS, RELOADING_BUILDER_CLASS, CONFIGURATION_CLASS,
+ Arrays.asList(COMBINED_PARAMS, FILE_PARAMS));
}
/**
@@ -80,8 +84,15 @@ public class CombinedConfigurationBuilde
ConfigurationDeclaration decl, Collection params)
throws Exception
{
- CombinedConfigurationBuilder builder =
- new CombinedConfigurationBuilder();
+ CombinedConfigurationBuilder builder;
+ if (decl.isReload())
+ {
+ builder = new ReloadingCombinedConfigurationBuilder();
+ }
+ else
+ {
+ builder = new CombinedConfigurationBuilder();
+ }
decl.getConfigurationBuilder().initChildEventListeners(builder);
return builder;
}
Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/ReloadingCombinedConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/ReloadingCombinedConfigurationBuilder.java?rev=1427351&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/ReloadingCombinedConfigurationBuilder.java (added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/ReloadingCombinedConfigurationBuilder.java Tue Jan 1 10:47:07 2013
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration.builder.combined;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Map;
+
+import org.apache.commons.configuration.CombinedConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.configuration.builder.BuilderParameters;
+import org.apache.commons.configuration.builder.ConfigurationBuilder;
+import org.apache.commons.configuration.builder.ReloadingFileBasedConfigurationBuilder;
+import org.apache.commons.configuration.reloading.CombinedReloadingController;
+import org.apache.commons.configuration.reloading.ReloadingController;
+import org.apache.commons.configuration.reloading.ReloadingControllerSupport;
+
+/**
+ *
+ * An extension of {@code CombinedConfigurationBuilder} which also supports
+ * reloading operations.
+ *
+ *
+ * This class differs from its super class in the following aspects:
+ *
+ * - A {@link ReloadingController} is created which manages all child
+ * configuration builders supporting reloading operations.
+ * - If no {@code ConfigurationBuilder} is provided for the definition
+ * configuration, a builder with reloading support is created.
+ *
+ *
+ *
+ * This class can be used exactly as its super class for creating combined
+ * configurations from multiple configuration sources. In addition, the combined
+ * reloading controller managed by an instance can be used to react on changes
+ * in one of these configuration sources or in the definition configuration.
+ *
+ *
+ * @version $Id$
+ * @since 2.0
+ */
+public class ReloadingCombinedConfigurationBuilder extends
+ CombinedConfigurationBuilder implements ReloadingControllerSupport
+{
+ /** The reloading controller used by this builder. */
+ private ReloadingController reloadingController;
+
+ /**
+ * Creates a new instance of {@code ReloadingCombinedConfigurationBuilder}.
+ * No parameters are set.
+ */
+ public ReloadingCombinedConfigurationBuilder()
+ {
+ super();
+ }
+
+ /**
+ * Creates a new instance of {@code ReloadingCombinedConfigurationBuilder}
+ * and sets the specified initialization parameters and the
+ * allowFailOnInit flag.
+ *
+ * @param params a map with initialization parameters
+ * @param allowFailOnInit the allowFailOnInit flag
+ */
+ public ReloadingCombinedConfigurationBuilder(Map params,
+ boolean allowFailOnInit)
+ {
+ super(params, allowFailOnInit);
+ }
+
+ /**
+ * Creates a new instance of {@code ReloadingCombinedConfigurationBuilder}
+ * and sets the specified initialization parameters.
+ *
+ * @param params a map with initialization parameters
+ */
+ public ReloadingCombinedConfigurationBuilder(Map params)
+ {
+ super(params);
+ }
+
+ /**
+ * {@inheritDoc} This implementation returns a
+ * {@link CombinedReloadingController} which contains sub controllers for
+ * all child configuration sources with reloading support. If the definition
+ * builder supports reloading, its controller is contained, too. Note that
+ * the combined reloading controller is initialized when the result
+ * configuration is created (i.e. when calling {@code getConfiguration()}
+ * for the first time). So this method does not return a meaningful result
+ * before.
+ */
+ public synchronized ReloadingController getReloadingController()
+ {
+ return reloadingController;
+ }
+
+ /**
+ * {@inheritDoc} This implementation creates a builder for XML
+ * configurations with reloading support.
+ */
+ @Override
+ protected ConfigurationBuilder extends HierarchicalConfiguration> createXMLDefinitionBuilder(
+ BuilderParameters builderParams)
+ {
+ return new ReloadingFileBasedConfigurationBuilder(
+ XMLConfiguration.class).configure(builderParams);
+ }
+
+ /**
+ * {@inheritDoc} This implementation first calls the super method to
+ * actually initialize the result configuration. Then it creates the
+ * {@link CombinedReloadingController} for all child configuration sources
+ * with reloading support.
+ */
+ @Override
+ protected void initResultInstance(CombinedConfiguration result)
+ throws ConfigurationException
+ {
+ super.initResultInstance(result);
+ reloadingController = createReloadingController();
+ }
+
+ /**
+ * Creates the {@code ReloadingController} for this builder. This method is
+ * called after the result configuration has been created and initialized.
+ * It is called from a synchronized block. This implementation creates a
+ * {@link CombinedReloadingController}.
+ *
+ * @return the {@code ReloadingController} for this builder
+ * @throws ConfigurationException if an error occurs
+ */
+ protected ReloadingController createReloadingController()
+ throws ConfigurationException
+ {
+ Collection subControllers =
+ new LinkedList();
+ ConfigurationBuilder extends HierarchicalConfiguration> defBuilder =
+ getDefinitionBuilder();
+ obtainReloadingController(subControllers, defBuilder);
+
+ for (ConfigurationBuilder extends Configuration> b : getChildBuilders())
+ {
+ obtainReloadingController(subControllers, b);
+ }
+
+ return new CombinedReloadingController(subControllers);
+ }
+
+ /**
+ * Checks whether the passed in builder object supports reloading. If yes,
+ * its reloading controller is obtained and added to the given list.
+ *
+ * @param subControllers the list with sub controllers
+ * @param builder the builder object to be checked
+ */
+ public static void obtainReloadingController(
+ Collection subControllers, Object builder)
+ {
+ if (builder instanceof ReloadingControllerSupport)
+ {
+ subControllers.add(((ReloadingControllerSupport) builder)
+ .getReloadingController());
+ }
+ }
+}
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/ReloadingCombinedConfigurationBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/ReloadingCombinedConfigurationBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/ReloadingCombinedConfigurationBuilder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestReloadingCombinedConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestReloadingCombinedConfigurationBuilder.java?rev=1427351&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestReloadingCombinedConfigurationBuilder.java (added)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestReloadingCombinedConfigurationBuilder.java Tue Jan 1 10:47:07 2013
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration.builder.combined;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.Collection;
+
+import org.apache.commons.configuration.CombinedConfiguration;
+import org.apache.commons.configuration.ConfigurationAssert;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.configuration.builder.FileBasedBuilderParametersImpl;
+import org.apache.commons.configuration.builder.FileBasedConfigurationBuilder;
+import org.apache.commons.configuration.reloading.CombinedReloadingController;
+import org.apache.commons.configuration.reloading.ReloadingController;
+import org.apache.commons.configuration.reloading.ReloadingControllerSupport;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test class for {@code ReloadingCombinedConfigurationBuilder}.
+ *
+ * @version $Id$
+ */
+public class TestReloadingCombinedConfigurationBuilder
+{
+ /** The builder to be tested. */
+ private ReloadingCombinedConfigurationBuilder builder;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ builder = new ReloadingCombinedConfigurationBuilder();
+ }
+
+ /**
+ * Tests a definition configuration which does not contain sources with
+ * reloading support.
+ */
+ @Test
+ public void testNoReloadableSources() throws ConfigurationException
+ {
+ File testFile =
+ ConfigurationAssert
+ .getTestFile("testDigesterConfiguration.xml");
+ builder.configure(new CombinedBuilderParametersImpl()
+ .setDefinitionBuilder(
+ new FileBasedConfigurationBuilder(
+ XMLConfiguration.class))
+ .setDefinitionBuilderParameters(
+ new FileBasedBuilderParametersImpl().setFile(testFile)));
+ builder.getConfiguration();
+ CombinedReloadingController rc =
+ (CombinedReloadingController) builder.getReloadingController();
+ assertTrue("Got sub reloading controllers", rc.getSubControllers()
+ .isEmpty());
+ }
+
+ /**
+ * Tests whether the definition builder created by default supports
+ * reloading.
+ */
+ @Test
+ public void testReloadableDefinitionBuilder() throws ConfigurationException
+ {
+ File testFile =
+ ConfigurationAssert
+ .getTestFile("testDigesterConfiguration.xml");
+ builder.configure(new FileBasedBuilderParametersImpl()
+ .setFile(testFile));
+ builder.getConfiguration();
+ CombinedReloadingController rc =
+ (CombinedReloadingController) builder.getReloadingController();
+ Collection subControllers = rc.getSubControllers();
+ assertEquals("Wrong number of sub controllers", 1,
+ subControllers.size());
+ ReloadingController subctrl =
+ ((ReloadingControllerSupport) builder.getDefinitionBuilder())
+ .getReloadingController();
+ assertSame("Wrong sub controller", subctrl, subControllers.iterator()
+ .next());
+ }
+
+ /**
+ * Tests whether a nested combined configuration definition can be loaded
+ * with reloading support.
+ */
+ @Test
+ public void testNestedReloadableSources() throws ConfigurationException
+ {
+ File testFile =
+ ConfigurationAssert.getTestFile("testCCReloadingNested.xml");
+ builder.configure(new FileBasedBuilderParametersImpl()
+ .setFile(testFile));
+ builder.getConfiguration();
+ CombinedReloadingController rc =
+ (CombinedReloadingController) builder.getReloadingController();
+ Collection subControllers = rc.getSubControllers();
+ assertEquals("Wrong number of sub controllers", 2,
+ subControllers.size());
+ ReloadingControllerSupport ccBuilder =
+ (ReloadingControllerSupport) builder.getNamedBuilder("cc");
+ assertTrue("Sub controller not found",
+ subControllers.contains(ccBuilder.getReloadingController()));
+ CombinedReloadingController rc2 =
+ (CombinedReloadingController) ccBuilder
+ .getReloadingController();
+ assertEquals("Wrong number of sub controllers (2)", 3, rc2
+ .getSubControllers().size());
+ }
+
+ /**
+ * Tests whether initialization parameters are correctly processed.
+ */
+ @Test
+ public void testInitWithParameters() throws ConfigurationException
+ {
+ FileBasedBuilderParametersImpl params =
+ new FileBasedBuilderParametersImpl();
+ params.setFile(ConfigurationAssert
+ .getTestFile("testDigesterConfiguration.xml"));
+ builder =
+ new ReloadingCombinedConfigurationBuilder(
+ params.getParameters());
+ CombinedConfiguration cc = builder.getConfiguration();
+ assertTrue("Property not found", cc.getBoolean("test.boolean"));
+ }
+
+ /**
+ * Tests whether the failOnInit flag is passed to the super constructor.
+ */
+ @Test
+ public void testInitWithFailOnInitFlag()
+ {
+ builder = new ReloadingCombinedConfigurationBuilder(null, true);
+ assertTrue("Flag not set", builder.isAllowFailOnInit());
+ }
+}
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestReloadingCombinedConfigurationBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestReloadingCombinedConfigurationBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestReloadingCombinedConfigurationBuilder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/proper/configuration/trunk/src/test/resources/testCCReloading.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/resources/testCCReloading.xml?rev=1427351&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/resources/testCCReloading.xml (added)
+++ commons/proper/configuration/trunk/src/test/resources/testCCReloading.xml Tue Jan 1 10:47:07 2013
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
Propchange: commons/proper/configuration/trunk/src/test/resources/testCCReloading.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/test/resources/testCCReloading.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/test/resources/testCCReloading.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: commons/proper/configuration/trunk/src/test/resources/testCCReloadingNested.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/resources/testCCReloadingNested.xml?rev=1427351&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/resources/testCCReloadingNested.xml (added)
+++ commons/proper/configuration/trunk/src/test/resources/testCCReloadingNested.xml Tue Jan 1 10:47:07 2013
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
Propchange: commons/proper/configuration/trunk/src/test/resources/testCCReloadingNested.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/configuration/trunk/src/test/resources/testCCReloadingNested.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/configuration/trunk/src/test/resources/testCCReloadingNested.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml