Author: ebourg Date: Tue Sep 27 06:06:23 2005 New Revision: 291931 URL: http://svn.apache.org/viewcvs?rev=291931&view=rev Log: Implemented variable interpolation for all getters
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DataConfiguration.java jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDataConfiguration.java jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java?rev=291931&r1=291930&r2=291931&view=diff ============================================================================== --- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java (original) +++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java Tue Sep 27 06:06:23 2005 @@ -131,6 +131,25 @@ } /** + * Returns the interpolated value. Non String values are returned without change. + * + * @param value the value to interpolate + * + * @return returns the value with variables substituted + */ + protected Object interpolate(Object value) + { + if (value instanceof String) + { + return interpolate((String) value); + } + else + { + return value; + } + } + + /** * Recursive handler for multple levels of interpolation. * * When called the first time, priorVariables should be null. @@ -388,7 +407,7 @@ { try { - return PropertyConverter.toBoolean(value); + return PropertyConverter.toBoolean(interpolate(value)); } catch (ConversionException e) { @@ -436,7 +455,7 @@ { try { - return PropertyConverter.toByte(value); + return PropertyConverter.toByte(interpolate(value)); } catch (ConversionException e) { @@ -484,7 +503,7 @@ { try { - return PropertyConverter.toDouble(value); + return PropertyConverter.toDouble(interpolate(value)); } catch (ConversionException e) { @@ -532,7 +551,7 @@ { try { - return PropertyConverter.toFloat(value); + return PropertyConverter.toFloat(interpolate(value)); } catch (ConversionException e) { @@ -587,7 +606,7 @@ { try { - return PropertyConverter.toInteger(value); + return PropertyConverter.toInteger(interpolate(value)); } catch (ConversionException e) { @@ -635,7 +654,7 @@ { try { - return PropertyConverter.toLong(value); + return PropertyConverter.toLong(interpolate(value)); } catch (ConversionException e) { @@ -683,7 +702,7 @@ { try { - return PropertyConverter.toShort(value); + return PropertyConverter.toShort(interpolate(value)); } catch (ConversionException e) { @@ -727,7 +746,7 @@ { try { - return PropertyConverter.toBigDecimal(value); + return PropertyConverter.toBigDecimal(interpolate(value)); } catch (ConversionException e) { @@ -771,7 +790,7 @@ { try { - return PropertyConverter.toBigInteger(value); + return PropertyConverter.toBigInteger(interpolate(value)); } catch (ConversionException e) { @@ -887,12 +906,7 @@ Iterator it = l.iterator(); while (it.hasNext()) { - Object element = it.next(); - if (element instanceof String) { - list.add(interpolate((String) element)); - } else { - list.add(element); - } + list.add(interpolate(it.next())); } } Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DataConfiguration.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DataConfiguration.java?rev=291931&r1=291930&r2=291931&view=diff ============================================================================== --- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DataConfiguration.java (original) +++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DataConfiguration.java Tue Sep 27 06:06:23 2005 @@ -27,6 +27,7 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; +import java.io.Serializable; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.ArrayUtils; @@ -45,7 +46,7 @@ * @version $Revision$, $Date$ * @since 1.1 */ -public class DataConfiguration extends AbstractConfiguration +public class DataConfiguration extends AbstractConfiguration implements Serializable { /** The key of the property storing the user defined date format. */ public static final String DATE_FORMAT_KEY = "org.apache.commons.configuration.format.date"; @@ -130,7 +131,7 @@ { Object value = getProperty(key); - List list = null; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -154,7 +155,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - list.add(PropertyConverter.toBoolean(it.next())); + list.add(PropertyConverter.toBoolean(interpolate(it.next()))); } } else @@ -163,7 +164,7 @@ { // attempt to convert a single value list = new ArrayList(); - list.add(PropertyConverter.toBoolean(value)); + list.add(PropertyConverter.toBoolean(interpolate(value))); } catch (ConversionException e) { @@ -229,7 +230,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - array[i++] = PropertyConverter.toBoolean(it.next()).booleanValue(); + array[i++] = PropertyConverter.toBoolean(interpolate(it.next())).booleanValue(); } } else @@ -238,7 +239,7 @@ { // attempt to convert a single value array = new boolean[1]; - array[0] = PropertyConverter.toBoolean(value).booleanValue(); + array[0] = PropertyConverter.toBoolean(interpolate(value)).booleanValue(); } catch (ConversionException e) { @@ -280,7 +281,7 @@ { Object value = getProperty(key); - List list = null; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -304,7 +305,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - list.add(PropertyConverter.toByte(it.next())); + list.add(PropertyConverter.toByte(interpolate(it.next()))); } } else @@ -313,7 +314,7 @@ { // attempt to convert a single value list = new ArrayList(); - list.add(PropertyConverter.toByte(value)); + list.add(PropertyConverter.toByte(interpolate(value))); } catch (ConversionException e) { @@ -378,7 +379,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - array[i++] = PropertyConverter.toByte(it.next()).byteValue(); + array[i++] = PropertyConverter.toByte(interpolate(it.next())).byteValue(); } } else @@ -387,7 +388,7 @@ { // attempt to convert a single value array = new byte[1]; - array[0] = PropertyConverter.toByte(value).byteValue(); + array[0] = PropertyConverter.toByte(interpolate(value)).byteValue(); } catch (ConversionException e) { @@ -429,7 +430,7 @@ { Object value = getProperty(key); - List list = null; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -453,7 +454,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - list.add(PropertyConverter.toShort(it.next())); + list.add(PropertyConverter.toShort(interpolate(it.next()))); } } else @@ -462,7 +463,7 @@ { // attempt to convert a single value list = new ArrayList(); - list.add(PropertyConverter.toShort(value)); + list.add(PropertyConverter.toShort(interpolate(value))); } catch (ConversionException e) { @@ -527,7 +528,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - array[i++] = PropertyConverter.toShort(it.next()).shortValue(); + array[i++] = PropertyConverter.toShort(interpolate(it.next())).shortValue(); } } else @@ -536,7 +537,7 @@ { // attempt to convert a single value array = new short[1]; - array[0] = PropertyConverter.toShort(value).shortValue(); + array[0] = PropertyConverter.toShort(interpolate(value)).shortValue(); } catch (ConversionException e) { @@ -579,7 +580,7 @@ { Object value = getProperty(key); - List list = null; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -603,7 +604,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - list.add(PropertyConverter.toInteger(it.next())); + list.add(PropertyConverter.toInteger(interpolate(it.next()))); } } else @@ -612,7 +613,7 @@ { // attempt to convert a single value list = new ArrayList(); - list.add(PropertyConverter.toInteger(value)); + list.add(PropertyConverter.toInteger(interpolate(value))); } catch (ConversionException e) { @@ -677,7 +678,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - array[i++] = PropertyConverter.toInteger(it.next()).intValue(); + array[i++] = PropertyConverter.toInteger(interpolate(it.next())).intValue(); } } else @@ -686,7 +687,7 @@ { // attempt to convert a single value array = new int[1]; - array[0] = PropertyConverter.toInteger(value).intValue(); + array[0] = PropertyConverter.toInteger(interpolate(value)).intValue(); } catch (ConversionException e) { @@ -728,7 +729,7 @@ { Object value = getProperty(key); - List list = null; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -752,7 +753,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - list.add(PropertyConverter.toLong(it.next())); + list.add(PropertyConverter.toLong(interpolate(it.next()))); } } else @@ -761,7 +762,7 @@ { // attempt to convert a single value list = new ArrayList(); - list.add(PropertyConverter.toLong(value)); + list.add(PropertyConverter.toLong(interpolate(value))); } catch (ConversionException e) { @@ -826,7 +827,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - array[i++] = PropertyConverter.toLong(it.next()).longValue(); + array[i++] = PropertyConverter.toLong(interpolate(it.next())).longValue(); } } else @@ -835,7 +836,7 @@ { // attempt to convert a single value array = new long[1]; - array[0] = PropertyConverter.toLong(value).longValue(); + array[0] = PropertyConverter.toLong(interpolate(value)).longValue(); } catch (ConversionException e) { @@ -877,7 +878,7 @@ { Object value = getProperty(key); - List list = null; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -901,7 +902,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - list.add(PropertyConverter.toFloat(it.next())); + list.add(PropertyConverter.toFloat(interpolate(it.next()))); } } else @@ -910,7 +911,7 @@ { // attempt to convert a single value list = new ArrayList(); - list.add(PropertyConverter.toFloat(value)); + list.add(PropertyConverter.toFloat(interpolate(value))); } catch (ConversionException e) { @@ -975,7 +976,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - array[i++] = PropertyConverter.toFloat(it.next()).floatValue(); + array[i++] = PropertyConverter.toFloat(interpolate(it.next())).floatValue(); } } else @@ -984,7 +985,7 @@ { // attempt to convert a single value array = new float[1]; - array[0] = PropertyConverter.toFloat(value).floatValue(); + array[0] = PropertyConverter.toFloat(interpolate(value)).floatValue(); } catch (ConversionException e) { @@ -1027,7 +1028,7 @@ { Object value = getProperty(key); - List list = null; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -1051,7 +1052,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - list.add(PropertyConverter.toDouble(it.next())); + list.add(PropertyConverter.toDouble(interpolate(it.next()))); } } else @@ -1060,7 +1061,7 @@ { // attempt to convert a single value list = new ArrayList(); - list.add(PropertyConverter.toDouble(value)); + list.add(PropertyConverter.toDouble(interpolate(value))); } catch (ConversionException e) { @@ -1125,7 +1126,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - array[i++] = PropertyConverter.toDouble(it.next()).doubleValue(); + array[i++] = PropertyConverter.toDouble(interpolate(it.next())).doubleValue(); } } else @@ -1134,7 +1135,7 @@ { // attempt to convert a single value array = new double[1]; - array[0] = PropertyConverter.toDouble(value).doubleValue(); + array[0] = PropertyConverter.toDouble(interpolate(value)).doubleValue(); } catch (ConversionException e) { @@ -1176,7 +1177,7 @@ { Object value = getProperty(key); - List list = null; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -1195,7 +1196,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - list.add(PropertyConverter.toBigInteger(it.next())); + list.add(PropertyConverter.toBigInteger(interpolate(it.next()))); } } else @@ -1204,7 +1205,7 @@ { // attempt to convert a single value list = new ArrayList(); - list.add(PropertyConverter.toBigInteger(value)); + list.add(PropertyConverter.toBigInteger(interpolate(value))); } catch (ConversionException e) { @@ -1286,7 +1287,7 @@ { Object value = getProperty(key); - List list = null; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -1305,7 +1306,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - list.add(PropertyConverter.toBigDecimal(it.next())); + list.add(PropertyConverter.toBigDecimal(interpolate(it.next()))); } } else @@ -1314,7 +1315,7 @@ { // attempt to convert a single value list = new ArrayList(); - list.add(PropertyConverter.toBigDecimal(value)); + list.add(PropertyConverter.toBigDecimal(interpolate(value))); } catch (ConversionException e) { @@ -1403,7 +1404,7 @@ { try { - return PropertyConverter.toURL(value); + return PropertyConverter.toURL(interpolate(value)); } catch (ConversionException e) { @@ -1443,7 +1444,7 @@ { Object value = getProperty(key); - List list = null; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -1462,7 +1463,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - list.add(PropertyConverter.toURL(it.next())); + list.add(PropertyConverter.toURL(interpolate(it.next()))); } } else @@ -1471,7 +1472,7 @@ { // attempt to convert a single value list = new ArrayList(); - list.add(PropertyConverter.toURL(value)); + list.add(PropertyConverter.toURL(interpolate(value))); } catch (ConversionException e) { @@ -1598,7 +1599,7 @@ { try { - return PropertyConverter.toDate(value, format); + return PropertyConverter.toDate(interpolate(value), format); } catch (ConversionException e) { @@ -1681,7 +1682,7 @@ { Object value = getProperty(key); - List list = null; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -1710,7 +1711,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - list.add(PropertyConverter.toDate(it.next(), format)); + list.add(PropertyConverter.toDate(interpolate(it.next()), format)); } } else @@ -1719,7 +1720,7 @@ { // attempt to convert a single value list = new ArrayList(); - list.add(PropertyConverter.toDate(value, format)); + list.add(PropertyConverter.toDate(interpolate(value), format)); } catch (ConversionException e) { @@ -1890,7 +1891,7 @@ { try { - return PropertyConverter.toCalendar(value, format); + return PropertyConverter.toCalendar(interpolate(value), format); } catch (ConversionException e) { @@ -1973,7 +1974,7 @@ { Object value = getProperty(key); - List list = null; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -2004,7 +2005,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - list.add(PropertyConverter.toCalendar(it.next(), format)); + list.add(PropertyConverter.toCalendar(interpolate(it.next()), format)); } } else @@ -2013,7 +2014,7 @@ { // attempt to convert a single value list = new ArrayList(); - list.add(PropertyConverter.toCalendar(value, format)); + list.add(PropertyConverter.toCalendar(interpolate(value), format)); } catch (ConversionException e) { @@ -2152,7 +2153,7 @@ { try { - return PropertyConverter.toLocale(value); + return PropertyConverter.toLocale(interpolate(value)); } catch (ConversionException e) { @@ -2192,7 +2193,7 @@ { Object value = getProperty(key); - List list = null; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -2211,7 +2212,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - list.add(PropertyConverter.toLocale(it.next())); + list.add(PropertyConverter.toLocale(interpolate(it.next()))); } } else @@ -2220,7 +2221,7 @@ { // attempt to convert a single value list = new ArrayList(); - list.add(PropertyConverter.toLocale(value)); + list.add(PropertyConverter.toLocale(interpolate(value))); } catch (ConversionException e) { @@ -2309,7 +2310,7 @@ { try { - return PropertyConverter.toColor(value); + return PropertyConverter.toColor(interpolate(value)); } catch (ConversionException e) { @@ -2349,7 +2350,7 @@ { Object value = getProperty(key); - List list = null; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -2368,7 +2369,7 @@ Iterator it = values.iterator(); while (it.hasNext()) { - list.add(PropertyConverter.toColor(it.next())); + list.add(PropertyConverter.toColor(interpolate(it.next()))); } } else @@ -2377,7 +2378,7 @@ { // attempt to convert a single value list = new ArrayList(); - list.add(PropertyConverter.toColor(value)); + list.add(PropertyConverter.toColor(interpolate(value))); } catch (ConversionException e) { Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java?rev=291931&r1=291930&r2=291931&view=diff ============================================================================== --- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java (original) +++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java Tue Sep 27 06:06:23 2005 @@ -429,6 +429,36 @@ ListAssert.assertEquals("'array' property", list, config.getList("array")); } + public void testGetInterpolatedPrimitives() + { + config.addProperty("number", "1"); + config.addProperty("value", "${number}"); + + config.addProperty("boolean", "true"); + config.addProperty("booleanValue", "${boolean}"); + + // primitive types + assertEquals("boolean interpolation", true, config.getBoolean("booleanValue")); + assertEquals("byte interpolation", 1, config.getByte("value")); + assertEquals("short interpolation", 1, config.getShort("value")); + assertEquals("int interpolation", 1, config.getInt("value")); + assertEquals("long interpolation", 1, config.getLong("value")); + assertEquals("float interpolation", 1, config.getFloat("value"), 0); + assertEquals("double interpolation", 1, config.getDouble("value"), 0); + + // primitive wrappers + assertEquals("Boolean interpolation", Boolean.TRUE, config.getBoolean("booleanValue", null)); + assertEquals("Byte interpolation", new Byte("1"), config.getByte("value", null)); + assertEquals("Short interpolation", new Short("1"), config.getShort("value", null)); + assertEquals("Integer interpolation", new Integer("1"), config.getInteger("value", null)); + assertEquals("Long interpolation", new Long("1"), config.getLong("value", null)); + assertEquals("Float interpolation", new Float("1"), config.getFloat("value", null)); + assertEquals("Double interpolation", new Double("1"), config.getDouble("value", null)); + + assertEquals("BigInteger interpolation", new BigInteger("1"), config.getBigInteger("value", null)); + assertEquals("BigDecimal interpolation", new BigDecimal("1"), config.getBigDecimal("value", null)); + } + public void testCommaSeparatedString() { String prop = "hey, that's a test"; Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDataConfiguration.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDataConfiguration.java?rev=291931&r1=291930&r2=291931&view=diff ============================================================================== --- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDataConfiguration.java (original) +++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDataConfiguration.java Tue Sep 27 06:06:23 2005 @@ -1,5 +1,5 @@ /* - * Copyright 2004 The Apache Software Foundation. + * Copyright 2004-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License") * you may not use this file except in compliance with the License. @@ -16,17 +16,17 @@ package org.apache.commons.configuration; -import java.awt.Color; +import java.awt.*; import java.math.BigDecimal; import java.math.BigInteger; import java.net.URL; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.List; import java.util.Locale; -import java.util.Date; -import java.util.Calendar; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import junit.framework.TestCase; import junitx.framework.ArrayAssert; @@ -61,6 +61,7 @@ conf.addProperty("boolean.list6", booleans); conf.addProperty("boolean.string", "true"); conf.addProperty("boolean.object", Boolean.TRUE); + conf.addProperty("boolean.list.interpolated", "${boolean.string},false"); // lists of bytes conf.addProperty("byte.list1", "1"); @@ -76,6 +77,7 @@ conf.addProperty("byte.list6", bytes); conf.addProperty("byte.string", "1"); conf.addProperty("byte.object", new Byte("1")); + conf.addProperty("byte.list.interpolated", "${byte.string},2"); // lists of shorts conf.addProperty("short.list1", "1"); @@ -91,6 +93,7 @@ conf.addProperty("short.list6", shorts); conf.addProperty("short.string", "1"); conf.addProperty("short.object", new Short("1")); + conf.addProperty("short.list.interpolated", "${short.string},2"); // lists of integers conf.addProperty("integer.list1", "1"); @@ -106,6 +109,7 @@ conf.addProperty("integer.list6", integers); conf.addProperty("integer.string", "1"); conf.addProperty("integer.object", new Integer("1")); + conf.addProperty("integer.list.interpolated", "${integer.string},2"); // lists of longs conf.addProperty("long.list1", "1"); @@ -121,6 +125,7 @@ conf.addProperty("long.list6", longs); conf.addProperty("long.string", "1"); conf.addProperty("long.object", new Long("1")); + conf.addProperty("long.list.interpolated", "${long.string},2"); // lists of floats conf.addProperty("float.list1", "1"); @@ -136,6 +141,7 @@ conf.addProperty("float.list6", floats); conf.addProperty("float.string", "1"); conf.addProperty("float.object", new Float("1")); + conf.addProperty("float.list.interpolated", "${float.string},2"); // lists of doubles conf.addProperty("double.list1", "1"); @@ -151,6 +157,7 @@ conf.addProperty("double.list6", doubles); conf.addProperty("double.string", "1"); conf.addProperty("double.object", new Double("1")); + conf.addProperty("double.list.interpolated", "${double.string},2"); // lists of big integers conf.addProperty("biginteger.list1", "1"); @@ -165,6 +172,7 @@ conf.addProperty("biginteger.list6", bigintegers); conf.addProperty("biginteger.string", "1"); conf.addProperty("biginteger.object", new BigInteger("1")); + conf.addProperty("biginteger.list.interpolated", "${biginteger.string},2"); // lists of big decimals conf.addProperty("bigdecimal.list1", "1"); @@ -179,23 +187,29 @@ conf.addProperty("bigdecimal.list6", bigdecimals); conf.addProperty("bigdecimal.string", "1"); conf.addProperty("bigdecimal.object", new BigDecimal("1")); + conf.addProperty("bigdecimal.list.interpolated", "${bigdecimal.string},2"); // URLs - conf.addProperty("url.string", "http://jakarta.apache.org"); - conf.addProperty("url.object", new URL("http://jakarta.apache.org")); - conf.addProperty("url.list1", "http://jakarta.apache.org"); - conf.addProperty("url.list1", "http://www.apache.org"); - conf.addProperty("url.list2", "http://jakarta.apache.org, http://www.apache.org"); - conf.addProperty("url.list3", new URL("http://jakarta.apache.org")); - conf.addProperty("url.list3", new URL("http://www.apache.org")); - conf.addProperty("url.list4", new URL[] { new URL("http://jakarta.apache.org"), new URL("http://www.apache.org") }); + String url1 = "http://jakarta.apache.org"; + String url2 = "http://www.apache.org"; + conf.addProperty("url.string", url1); + conf.addProperty("url.string.interpolated", "${url.string}"); + conf.addProperty("url.object", new URL(url1)); + conf.addProperty("url.list1", url1); + conf.addProperty("url.list1", url2); + conf.addProperty("url.list2", url1 + ", " + url2); + conf.addProperty("url.list3", new URL(url1)); + conf.addProperty("url.list3", new URL(url2)); + conf.addProperty("url.list4", new URL[] { new URL(url1), new URL(url2) }); List urls = new ArrayList(); - urls.add(new URL("http://jakarta.apache.org")); - urls.add(new URL("http://www.apache.org")); + urls.add(new URL(url1)); + urls.add(new URL(url2)); conf.addProperty("url.list6", urls); + conf.addProperty("url.list.interpolated", "${url.string}," + url2); // Locales conf.addProperty("locale.string", "fr"); + conf.addProperty("locale.string.interpolated", "${locale.string}"); conf.addProperty("locale.object", Locale.FRENCH); conf.addProperty("locale.list1", "fr"); conf.addProperty("locale.list1", "de"); @@ -207,13 +221,17 @@ locales.add(Locale.FRENCH); locales.add(Locale.GERMAN); conf.addProperty("locale.list6", locales); + conf.addProperty("locale.list.interpolated", "${locale.string},de"); // Colors - conf.addProperty("color.string", "FF0000"); + String color1 = "FF0000"; + String color2 = "0000FF"; + conf.addProperty("color.string", color1); + conf.addProperty("color.string.interpolated", "${color.string}"); conf.addProperty("color.object", Color.red); - conf.addProperty("color.list1", "FF0000"); - conf.addProperty("color.list1", "0000FF"); - conf.addProperty("color.list2", "FF0000, 0000FF"); + conf.addProperty("color.list1", color1); + conf.addProperty("color.list1", color2); + conf.addProperty("color.list2", color1 + ", " + color2); conf.addProperty("color.list3", Color.red); conf.addProperty("color.list3", Color.blue); conf.addProperty("color.list4", new Color[] { Color.red, Color.blue }); @@ -221,6 +239,7 @@ colors.add(Color.red); colors.add(Color.blue); conf.addProperty("color.list6", colors); + conf.addProperty("color.list.interpolated", "${color.string}," + color2); // Dates & Calendars String pattern = "yyyy-MM-dd"; @@ -235,6 +254,7 @@ calendar2.setTime(date2); conf.addProperty("date.string", "2004-01-01"); + conf.addProperty("date.string.interpolated", "${date.string}"); conf.addProperty("date.object", date1); conf.addProperty("date.list1", "2004-01-01"); conf.addProperty("date.list1", "2004-12-31"); @@ -247,8 +267,10 @@ dates.add(date1); dates.add(date2); conf.addProperty("date.list6", dates); + conf.addProperty("date.list.interpolated", "${date.string},2004-12-31"); conf.addProperty("calendar.string", "2004-01-01"); + conf.addProperty("calendar.string.interpolated", "${calendar.string}"); conf.addProperty("calendar.object", calendar1); conf.addProperty("calendar.list1", "2004-01-01"); conf.addProperty("calendar.list1", "2004-12-31"); @@ -261,6 +283,7 @@ calendars.add(date1); calendars.add(date2); conf.addProperty("calendar.list6", calendars); + conf.addProperty("calendar.list.interpolated", "${calendar.string},2004-12-31"); } public void testGetBooleanArray() @@ -289,6 +312,9 @@ // list of Boolean objects ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list6")); + // list of interpolated values + ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list.interpolated")); + // single boolean values ArrayAssert.assertEquals(new boolean[] { true }, conf.getBooleanArray("boolean.string")); ArrayAssert.assertEquals(new boolean[] { true }, conf.getBooleanArray("boolean.object")); @@ -324,6 +350,9 @@ // list of Boolean objects ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list6")); + // list of interpolated values + ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list.interpolated")); + // single boolean values expected = new ArrayList(); expected.add(Boolean.TRUE); @@ -360,6 +389,9 @@ // list of Byte objects ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list6")); + // list of interpolated values + ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list.interpolated")); + // single byte values ArrayAssert.assertEquals(new byte[] { 1 }, conf.getByteArray("byte.string")); ArrayAssert.assertEquals(new byte[] { 1 }, conf.getByteArray("byte.object")); @@ -395,6 +427,9 @@ // list of Byte objects ListAssert.assertEquals(expected, conf.getByteList("byte.list6")); + // list of interpolated values + ListAssert.assertEquals(expected, conf.getByteList("byte.list.interpolated")); + // single byte values expected = new ArrayList(); expected.add(new Byte("1")); @@ -431,6 +466,9 @@ // list of Byte objects ArrayAssert.assertEquals(expected, conf.getShortArray("short.list6")); + // list of interpolated values + ArrayAssert.assertEquals(expected, conf.getShortArray("short.list.interpolated")); + // single byte values ArrayAssert.assertEquals(new short[] { 1 }, conf.getShortArray("short.string")); ArrayAssert.assertEquals(new short[] { 1 }, conf.getShortArray("short.object")); @@ -466,6 +504,9 @@ // list of Short objects ListAssert.assertEquals(expected, conf.getShortList("short.list6")); + // list of interpolated values + ListAssert.assertEquals(expected, conf.getShortList("short.list.interpolated")); + // single short values expected = new ArrayList(); expected.add(new Short("1")); @@ -502,6 +543,9 @@ // list of Integer objects ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list6")); + // list of interpolated values + ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list.interpolated")); + // single int values ArrayAssert.assertEquals(new int[] { 1 }, conf.getIntArray("integer.string")); ArrayAssert.assertEquals(new int[] { 1 }, conf.getIntArray("integer.object")); @@ -537,6 +581,9 @@ // list of Integer objects ListAssert.assertEquals(expected, conf.getIntegerList("integer.list6")); + // list of interpolated values + ListAssert.assertEquals(expected, conf.getIntegerList("integer.list.interpolated")); + // single int values expected = new ArrayList(); expected.add(new Integer("1")); @@ -573,6 +620,9 @@ // list of Long objects ArrayAssert.assertEquals(expected, conf.getLongArray("long.list6")); + // list of interpolated values + ArrayAssert.assertEquals(expected, conf.getLongArray("long.list.interpolated")); + // single long values ArrayAssert.assertEquals(new long[] { 1 }, conf.getLongArray("long.string")); ArrayAssert.assertEquals(new long[] { 1 }, conf.getLongArray("long.object")); @@ -608,6 +658,9 @@ // list of Long objects ListAssert.assertEquals(expected, conf.getLongList("long.list6")); + // list of interpolated values + ListAssert.assertEquals(expected, conf.getLongList("long.list.interpolated")); + // single long values expected = new ArrayList(); expected.add(new Long("1")); @@ -644,6 +697,9 @@ // list of Float objects ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list6"), 0); + // list of interpolated values + ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list.interpolated"), 0); + // single float values ArrayAssert.assertEquals(new float[] { 1 }, conf.getFloatArray("float.string"), 0); ArrayAssert.assertEquals(new float[] { 1 }, conf.getFloatArray("float.object"), 0); @@ -679,6 +735,9 @@ // list of Float objects ListAssert.assertEquals(expected, conf.getFloatList("float.list6")); + // list of interpolated values + ListAssert.assertEquals(expected, conf.getFloatList("float.list.interpolated")); + // single float values expected = new ArrayList(); expected.add(new Float("1")); @@ -715,6 +774,9 @@ // list of Double objects ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list6"), 0); + // list of interpolated values + ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list.interpolated"), 0); + // single double values ArrayAssert.assertEquals(new double[] { 1 }, conf.getDoubleArray("double.string"), 0); ArrayAssert.assertEquals(new double[] { 1 }, conf.getDoubleArray("double.object"), 0); @@ -750,6 +812,9 @@ // list of Double objects ListAssert.assertEquals(expected, conf.getDoubleList("double.list6")); + // list of interpolated values + ListAssert.assertEquals(expected, conf.getDoubleList("double.list.interpolated")); + // single double values expected = new ArrayList(); expected.add(new Double("1")); @@ -783,6 +848,9 @@ // list of BigInteger objects ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list6")); + // list of interpolated values + ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list.interpolated")); + // single BigInteger values ArrayAssert.assertEquals(new BigInteger[] { new BigInteger("1") }, conf.getBigIntegerArray("biginteger.string")); ArrayAssert.assertEquals(new BigInteger[] { new BigInteger("1") }, conf.getBigIntegerArray("biginteger.object")); @@ -815,6 +883,9 @@ // list of BigInteger objects ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list6")); + // list of interpolated values + ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list.interpolated")); + // single BigInteger values expected = new ArrayList(); expected.add(new BigInteger("1")); @@ -848,6 +919,9 @@ // list of BigDecimal objects ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list6")); + // list of interpolated values + ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list.interpolated")); + // single BigDecimal values ArrayAssert.assertEquals(new BigDecimal[] { new BigDecimal("1") }, conf.getBigDecimalArray("bigdecimal.string")); ArrayAssert.assertEquals(new BigDecimal[] { new BigDecimal("1") }, conf.getBigDecimalArray("bigdecimal.object")); @@ -880,6 +954,9 @@ // list of BigDecimal objects ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list6")); + // list of interpolated values + ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list.interpolated")); + // single BigDecimal values expected = new ArrayList(); expected.add(new BigDecimal("1")); @@ -903,6 +980,9 @@ // URL object assertEquals(expected, conf.getURL("url.object")); + + // interpolated value + assertEquals(expected, conf.getURL("url.string.interpolated")); } public void testGetURLArray() throws Exception @@ -928,6 +1008,9 @@ // list of URL objects ArrayAssert.assertEquals(expected, conf.getURLArray("url.list6")); + // list of interpolated values + ArrayAssert.assertEquals(expected, conf.getURLArray("url.list.interpolated")); + // single URL values ArrayAssert.assertEquals(new URL[] { new URL("http://jakarta.apache.org") }, conf.getURLArray("url.string")); ArrayAssert.assertEquals(new URL[] { new URL("http://jakarta.apache.org") }, conf.getURLArray("url.object")); @@ -960,6 +1043,9 @@ // list of URL objects ListAssert.assertEquals(expected, conf.getURLList("url.list6")); + // list of interpolated values + ListAssert.assertEquals(expected, conf.getURLList("url.list.interpolated")); + // single URL values expected = new ArrayList(); expected.add(new URL("http://www.apache.org")); @@ -1000,6 +1086,9 @@ conf.setProperty("locale", "fr"); assertEquals("Existing key with default value", Locale.FRENCH, conf.getLocale("locale", Locale.GERMAN)); assertEquals("Missing key with default value", Locale.GERMAN, conf.getLocale("localeNotInConfig", Locale.GERMAN)); + + // interpolated value + assertEquals(Locale.FRENCH, conf.getLocale("locale.string.interpolated")); } public void testGetLocaleArray() throws Exception @@ -1025,6 +1114,9 @@ // list of Locale objects ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list6")); + // list of interpolated values + ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list.interpolated")); + // single Locale values ArrayAssert.assertEquals(new Locale[] { Locale.FRENCH }, conf.getLocaleArray("locale.string")); ArrayAssert.assertEquals(new Locale[] { Locale.FRENCH }, conf.getLocaleArray("locale.object")); @@ -1057,6 +1149,9 @@ // list of Locale objects ListAssert.assertEquals(expected, conf.getLocaleList("locale.list6")); + // list of interpolated values + ListAssert.assertEquals(expected, conf.getLocaleList("locale.list.interpolated")); + // single Locale values expected = new ArrayList(); expected.add(Locale.FRENCH); @@ -1085,6 +1180,9 @@ assertEquals("green", 3, color.getGreen()); assertEquals("blue", 5, color.getBlue()); assertEquals("alpha", 7, color.getAlpha()); + + // interpolated value + assertEquals(Color.red, conf.getColor("color.string.interpolated")); } public void testGetColorArray() throws Exception @@ -1110,6 +1208,9 @@ // list of Color objects ArrayAssert.assertEquals(expected, conf.getColorArray("color.list6")); + // list of interpolated values + ArrayAssert.assertEquals(expected, conf.getColorArray("color.list.interpolated")); + // single Color values ArrayAssert.assertEquals(new Color[] { Color.red }, conf.getColorArray("color.string")); ArrayAssert.assertEquals(new Color[] { Color.red }, conf.getColorArray("color.object")); @@ -1142,6 +1243,9 @@ // list of Color objects ListAssert.assertEquals(expected, conf.getColorList("color.list6")); + // list of interpolated values + ListAssert.assertEquals(expected, conf.getColorList("color.list.interpolated")); + // single Color values expected = new ArrayList(); expected.add(Color.red); @@ -1170,6 +1274,9 @@ // Calendar object assertEquals(expected, conf.getDate("calendar.object")); + + // interpolated value + assertEquals(expected, conf.getDate("date.string.interpolated")); } public void testGetDateArray() throws Exception @@ -1202,6 +1309,9 @@ // list of Date objects ArrayAssert.assertEquals(expected, conf.getDateArray("date.list6")); + // list of interpolated values + ArrayAssert.assertEquals(expected, conf.getDateArray("date.list.interpolated")); + // single Date values ArrayAssert.assertEquals(new Date[] { date1 }, conf.getDateArray("date.string")); ArrayAssert.assertEquals(new Date[] { date1 }, conf.getDateArray("date.object")); @@ -1241,6 +1351,9 @@ // list of Date objects ListAssert.assertEquals(expected, conf.getDateList("date.list6")); + // list of interpolated values + ListAssert.assertEquals(expected, conf.getDateList("date.list.interpolated")); + // single Date values expected = new ArrayList(); expected.add(date1); @@ -1271,6 +1384,9 @@ // Date object assertEquals(expected, conf.getCalendar("date.object")); + + // interpolated value + assertEquals(expected, conf.getCalendar("calendar.string.interpolated")); } @@ -1308,6 +1424,9 @@ // list of Calendar objects ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list6")); + // list of interpolated values + ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list.interpolated")); + // single Calendar values ArrayAssert.assertEquals(new Calendar[] { calendar1 }, conf.getCalendarArray("calendar.string")); ArrayAssert.assertEquals(new Calendar[] { calendar1 }, conf.getCalendarArray("calendar.object")); @@ -1350,6 +1469,9 @@ // list of Calendar objects ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list6")); + + // list of interpolated values + ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list.interpolated")); // single Calendar values expected = new ArrayList(); Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?rev=291931&r1=291930&r2=291931&view=diff ============================================================================== --- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original) +++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Tue Sep 27 06:06:23 2005 @@ -23,13 +23,14 @@ <body> <release version="1.2-dev" date="in SVN"> - <action dev="ebourg" type="update" issue="36784 "> + <action dev="ebourg" type="update" issue="36784"> ConfigurationConverter.getProperties() now uses the delimiter of the specified configuration to convert the list properties into strings. </action> - <action dev="ebourg" type="update" issue="36784 "> - getList() now returns a list of interpolated values. As a side effect - the Properties returned by ConfigurationConverter.getProperties() + <action dev="ebourg" type="update" issue="36784"> + The interpolation of variables (${foo}) is now performed in all property + getters of AbstractConfiguration and DataConfiguration. As a side effect + the Properties object returned by ConfigurationConverter.getProperties() contains only interpolated values. </action> <action dev="ebourg" type="update" issue="36699"> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]