henning 2003/06/07 11:24:00 Modified: configuration/src/java/org/apache/commons/configuration BaseConfiguration.java BasePropertiesConfiguration.java ConfigurationFactory.java DOM4JConfiguration.java PropertiesConfiguration.java XMLConfiguration.java Added: configuration/src/java/org/apache/commons/configuration BasePathConfiguration.java Log: Add a layer class which adds the setBasePath/getBasePath method to all of the file based methods. This simplifies the ConfigurationFactory to have only one inner class for all path based configuration objects. Revision Changes Path 1.12 +3 -2 jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/BaseConfiguration.java Index: BaseConfiguration.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/BaseConfiguration.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- BaseConfiguration.java 18 Mar 2003 21:41:56 -0000 1.11 +++ BaseConfiguration.java 7 Jun 2003 18:24:00 -0000 1.12 @@ -113,7 +113,8 @@ * Empty constructor. You must add all the values to this configuration. */ public BaseConfiguration() - {} + { + } /** * Add a property to the configuration. If it already exists then the value 1.6 +2 -2 jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java Index: BasePropertiesConfiguration.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/BasePropertiesConfiguration.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- BasePropertiesConfiguration.java 7 Feb 2003 00:21:50 -0000 1.5 +++ BasePropertiesConfiguration.java 7 Jun 2003 18:24:00 -0000 1.6 @@ -159,7 +159,7 @@ * @version $Id$ */ public abstract class BasePropertiesConfiguration - extends BaseConfiguration + extends BasePathConfiguration { /** Allow file inclusion or not */ private boolean includesAllowed = false; 1.5 +17 -38 jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/ConfigurationFactory.java Index: ConfigurationFactory.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/ConfigurationFactory.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ConfigurationFactory.java 7 Jun 2003 17:57:29 -0000 1.4 +++ ConfigurationFactory.java 7 Jun 2003 18:24:00 -0000 1.5 @@ -213,8 +213,8 @@ protected void initDefaultDigesterRules(Digester digester) { // Properties and DOM4J need a base path. Supply it with inner classes - setupDigesterInstance(digester, "configuration/properties", new PropertiesConfigurationFactory()); - setupDigesterInstance(digester, "configuration/dom4j", new DOM4JConfigurationFactory()); + setupDigesterInstance(digester, "configuration/properties", new BasePathConfigurationFactory(PropertiesConfiguration.class)); + setupDigesterInstance(digester, "configuration/dom4j", new BasePathConfigurationFactory(DOM4JConfiguration.class)); // JNDI can be instantiated directly. setupDigesterInstance(digester, "configuration/jndi", JNDIConfiguration.class); @@ -318,61 +318,40 @@ /** * A tiny inner class that allows the Configuration Factory to - * let the digester construct PropertiesConfiguration objects + * let the digester construct BasePathConfiguration objects * that already have the correct base Path set. * */ - public class PropertiesConfigurationFactory + public class BasePathConfigurationFactory extends AbstractObjectCreationFactory implements ObjectCreationFactory { + /** Actual class to use. */ + private Class clazz; + /** * C'tor - */ - public PropertiesConfigurationFactory() - { - } - - /** - * Gets called by the digester. We ignore the attributes * - * @param attributes ignored - */ - public Object createObject(Attributes attributes) - { - PropertiesConfiguration pc = new PropertiesConfiguration(); - pc.setBasePath(getBasePath()); - return pc; - } - } - - /** - * A tiny inner class that allows the Configuration Factory to - * let the digester construct DOM4JConfiguration objects - * that already have the correct base Path set. - * - */ - public class DOM4JConfigurationFactory - extends AbstractObjectCreationFactory - implements ObjectCreationFactory - { - /** - * C'tor + * @param clazz The class which we should instantiate. */ - public DOM4JConfigurationFactory() + public BasePathConfigurationFactory(Class clazz) { + this.clazz = clazz; } /** * Gets called by the digester. We ignore the attributes * * @param attributes ignored + * + * @throws Exception Couldn't instantiate the requested object. */ public Object createObject(Attributes attributes) + throws Exception { - DOM4JConfiguration dc = new DOM4JConfiguration(); - dc.setBasePath(getBasePath()); - return dc; + BasePathConfiguration bpc = (BasePathConfiguration) clazz.newInstance(); + bpc.setBasePath(getBasePath()); + return bpc; } } } 1.4 +4 -25 jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/DOM4JConfiguration.java Index: DOM4JConfiguration.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/DOM4JConfiguration.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- DOM4JConfiguration.java 22 Mar 2003 05:19:50 -0000 1.3 +++ DOM4JConfiguration.java 7 Jun 2003 18:24:00 -0000 1.4 @@ -102,9 +102,6 @@ */ private static final String NODE_DELIMITER = "."; - /** The base path to our data source */ - private String basePath; - /** * A handle to our data source. */ @@ -377,9 +374,9 @@ */ public File getFile() { - File file = null; - if (StringUtils.isEmpty(basePath)) + + if (StringUtils.isEmpty(getBasePath())) { // Good luck... This will fail 99 out of 100 times. file = new File(getFileName()); @@ -387,10 +384,10 @@ else { StringBuffer fileName = new StringBuffer(); - fileName.append(basePath); + fileName.append(getBasePath()); // My best friend. Paranoia. - if (!basePath.endsWith(fileSeparator)) + if (!getBasePath().endsWith(fileSeparator)) { fileName.append(fileSeparator); } @@ -432,15 +429,6 @@ } /** - * Returns the basePath. - * @return String - */ - public String getBasePath() - { - return basePath; - } - - /** * Returns the fileName. * @return String */ @@ -448,13 +436,4 @@ { return fileName; } - /** - * Sets the basePath. - * @param basePath The basePath to set - */ - public void setBasePath(String basePath) - { - this.basePath = basePath; - } - } 1.10 +15 -28 jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/PropertiesConfiguration.java Index: PropertiesConfiguration.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/PropertiesConfiguration.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- PropertiesConfiguration.java 24 Mar 2003 07:23:47 -0000 1.9 +++ PropertiesConfiguration.java 7 Jun 2003 18:24:00 -0000 1.10 @@ -93,7 +93,9 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Eric Pugh</a> * @version $Id$ */ -public class PropertiesConfiguration extends BasePropertiesConfiguration implements Configuration +public class PropertiesConfiguration + extends BasePropertiesConfiguration + implements Configuration { /** Static logger */ Log log = LogFactory.getLog(PropertiesConfiguration.class); @@ -102,14 +104,6 @@ protected String fileSeparator = System.getProperty("file.separator"); /** - * Base path of the configuration file used to - * create this Configuration object. Might be null, then a - * "synthetic" PropertyConfiguration has been created which - * is not loaded from a file - **/ - protected String basePath = null; - - /** * The name of the file to be loaded. This is used in conjuction with * the load method. */ protected String fileName = null; @@ -229,7 +223,7 @@ else { - if (StringUtils.isEmpty(basePath)) + if (StringUtils.isEmpty(getBasePath())) { // Good luck... This will fail 99 out of 100 times. file = new File(resourceName); @@ -237,10 +231,10 @@ else { StringBuffer fileName = new StringBuffer(); - fileName.append(basePath); + fileName.append(getBasePath()); // My best friend. Paranoia. - if (!basePath.endsWith(fileSeparator)) + if (!getBasePath().endsWith(fileSeparator)) { fileName.append(fileSeparator); } @@ -284,7 +278,7 @@ if (baseFile != null) { - basePath = baseFile.getAbsolutePath(); + setBasePath(baseFile.getAbsolutePath()); setIncludesAllowed(true); } else @@ -296,6 +290,7 @@ return resource; } + /** * Returns the fileName. * @return String @@ -312,25 +307,17 @@ public void setFileName(String fileName) { this.fileName = fileName; - - } - - /** - * Returns the basePath. - * @return String - */ - public String getBasePath() - { - return basePath; } /** - * Sets the basePath. - * @param basePath The basePath to set + * Extend the setBasePath method to turn includes + * on and off based on the existence of a base path. + * + * @param basePath The new basePath to set. */ public void setBasePath(String basePath) { - this.basePath = basePath; + super.setBasePath(basePath); + setIncludesAllowed(StringUtils.isNotEmpty(basePath)); } - } 1.3 +1 -1 jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/XMLConfiguration.java Index: XMLConfiguration.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/XMLConfiguration.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- XMLConfiguration.java 11 Mar 2003 17:38:12 -0000 1.2 +++ XMLConfiguration.java 7 Jun 2003 18:24:00 -0000 1.3 @@ -61,6 +61,6 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a> * @since 0.8.1 */ -public abstract class XMLConfiguration extends BaseConfiguration +public abstract class XMLConfiguration extends BasePathConfiguration { } 1.1 jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/BasePathConfiguration.java Index: BasePathConfiguration.java =================================================================== package org.apache.commons.configuration; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ /** * This is exactly the same as the BaseConfiguration but the backing * store is based on a path (e.g. a file path) from which it is loaded. * * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a> * @version $Id: BasePathConfiguration.java,v 1.1 2003/06/07 18:24:00 henning Exp $ */ public abstract class BasePathConfiguration extends BaseConfiguration { /** * Base path of the configuration file used to * create this Configuration object. Might be null, then a * "synthetic" PropertyConfiguration has been created which * is not loaded from a file */ protected String basePath = null; /** * Returns the Base path from which this Configuration Factory operates. * This is never null. If you set the BasePath to null, then "." is returned. * * @return The base Path of this configuration factory. */ public String getBasePath() { return basePath; } /** * Sets the basePath for all file references from this Configuration Factory. * If you pass null in, this is interpreted as "current directory". * * @param basePath The new basePath to set. */ public void setBasePath(String basePath) { this.basePath = basePath; } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]