1
/* ========================================================================
2
* JCommon : a free general purpose class library for the Java(tm) platform
3
* ========================================================================
5
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
7
* Project Info: http://www.jfree.org/jcommon/index.html
9
* This library is free software; you can redistribute it and/or modify it
10
* under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2.1 of the License, or
12
* (at your option) any later version.
14
* This library is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
* License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25
* in the United States and other countries.]
27
* ---------------------------------
28
* ExtendedConfigurationWrapper.java
29
* ---------------------------------
30
* (C)opyright 2002-2005, by Thomas Morgner and Contributors.
32
* Original Author: Thomas Morgner;
33
* Contributor(s): David Gilbert (for Object Refinery Limited);
35
* $Id: ExtendedConfigurationWrapper.java,v 1.5 2005/11/03 09:55:27 mungady Exp $
39
* 20-May-2005 : Initial version.
42
package org.jfree.util;
44
import java.util.Iterator;
45
import java.util.Enumeration;
48
* A wrapper for the extended configuration interface around a plain configuration.
50
* @author Thomas Morgner
52
public class ExtendedConfigurationWrapper
53
implements ExtendedConfiguration
55
/** The base configuration. */
56
private Configuration parent;
59
* Creates a wrapper around the given configuration.
61
* @param parent the wrapped up configuration.
62
* @throws NullPointerException if the parent is null.
64
public ExtendedConfigurationWrapper (final Configuration parent)
68
throw new NullPointerException("Parent given must not be null");
74
* Returns the boolean value of a given configuration property. The boolean value true
75
* is returned, if the contained string is equal to 'true'.
77
* @param name the name of the property
78
* @return the boolean value of the property.
80
public boolean getBoolProperty (final String name)
82
return getBoolProperty(name, false);
86
* Returns the boolean value of a given configuration property. The boolean value true
87
* is returned, if the contained string is equal to 'true'. If the property is not set,
88
* the default value is returned.
90
* @param name the name of the property
91
* @param defaultValue the default value to be returned if the property is not set
92
* @return the boolean value of the property.
94
public boolean getBoolProperty (final String name,
95
final boolean defaultValue)
97
return "true".equals(parent.getConfigProperty(name, String.valueOf(defaultValue)));
101
* Returns a given property as int value. Zero is returned if the
102
* property value is no number or the property is not set.
104
* @param name the name of the property
105
* @return the parsed number value or zero
107
public int getIntProperty (final String name)
109
return getIntProperty(name, 0);
113
* Returns a given property as int value. The specified default value is returned if the
114
* property value is no number or the property is not set.
116
* @param name the name of the property
117
* @param defaultValue the value to be returned if the property is no integer value
118
* @return the parsed number value or the specified default value
120
public int getIntProperty (final String name,
121
final int defaultValue)
123
final String retval = parent.getConfigProperty(name);
130
return Integer.parseInt(retval);
139
* Checks, whether a given property is defined.
141
* @param name the name of the property
142
* @return true, if the property is defined, false otherwise.
144
public boolean isPropertySet (final String name)
146
return parent.getConfigProperty(name) != null;
150
* Returns all keys with the given prefix.
152
* @param prefix the prefix
153
* @return the iterator containing all keys with that prefix
155
public Iterator findPropertyKeys (final String prefix)
157
return parent.findPropertyKeys(prefix);
161
* Returns the configuration property with the specified key.
163
* @param key the property key.
164
* @return the property value.
166
public String getConfigProperty (final String key)
168
return parent.getConfigProperty(key);
172
* Returns the configuration property with the specified key (or the specified default
173
* value if there is no such property).
175
* If the property is not defined in this configuration, the code will lookup the
176
* property in the parent configuration.
178
* @param key the property key.
179
* @param defaultValue the default value.
180
* @return the property value.
182
public String getConfigProperty (final String key, final String defaultValue)
184
return parent.getConfigProperty(key, defaultValue);
187
public Enumeration getConfigProperties()
189
return parent.getConfigProperties();