org.apache.openejb.client
Class Options
java.lang.Object
org.apache.openejb.client.Options
public class Options
- extends java.lang.Object
The purpose of this class is to provide a more strongly typed version of a
java.util.Properties object. So far it is a read only view of the properties
and does not set data into the underlying Properties instance.
Similar to java.util.Properties it will delegate to a "parent" instance when
a property is not found. If a property is found but its value cannot be parsed
as the desired data type, the parent's value is used.
By default this object will log nothing, but if a Log implementation is set the
Options class will log three kinds of statements:
- When a property is not found: the property name and default value in use along
with all possible values (enums only). Debug level.
- When a property is found: the property name and value. Info level.
- When a property value cannot be parsed: the property name and invalid value. Warn level.
Logging the user supplied values onto INFO is really nice as it shows up in the standard
log output and allows us to easily see which values the user has changed from the default.
It's rather impossible to diagnose issues without this information.
ENUM SETS:
Properties that accept a Set of enum values automatically accept ALL and NONE in
addition to the explicitly created enum items.
Using ALL. This allows users to have an easy way to imply "all" without having to
hardcode an the entire list of enum items and protects against the case where that
list may grow in the future.
Using NONE. This allows users an alternative to using an empty string when explicitly
specifying that none of the options should be used.
In the internal code, this allows us to have these concepts in all enum options
without us having to add NONE or ALL enum items explicitly which leads to strange code.
Additionally TRUE is an alias for ALL and FALSE an alias for NONE. This allows options
that used to support only true/false values to be further defined in the future without
breaking compatibility.
- Version:
- $Rev: 1021955 $ $Date: 2010-10-13 01:57:57 +0200 (Mi, 13. Okt 2010) $
Constructor Summary |
Options(java.util.Properties properties)
|
Options(java.util.Properties properties,
Options parent)
|
Method Summary |
boolean |
get(java.lang.String property,
boolean defaultValue)
|
java.lang.Class |
get(java.lang.String property,
java.lang.Class defaultValue)
|
int |
get(java.lang.String property,
int defaultValue)
|
long |
get(java.lang.String property,
long defaultValue)
|
java.lang.String |
get(java.lang.String property,
java.lang.String defaultValue)
|
|
get(java.lang.String property,
T defaultValue)
|
<T extends java.lang.Enum<T>>
T |
|
get(java.lang.String property,
T defaultValue)
|
<T extends java.lang.Enum<T>>
java.util.Set<T> |
|
getAll(java.lang.String property,
java.lang.Class<T> enumType)
|
<T extends java.lang.Enum<T>>
java.util.Set<T> |
|
getAll(java.lang.String property,
java.util.Set<T> defaultValue)
|
protected
<T extends java.lang.Enum<T>>
java.util.Set<T> |
|
getAll(java.lang.String property,
java.util.Set<T> defaultValue,
java.lang.Class<T> enumType)
|
<T extends java.lang.Enum<T>>
java.util.Set<T> |
|
getAll(java.lang.String property,
T... defaultValue)
|
Options.Log |
getLogger()
|
java.util.Properties |
getProperties()
|
boolean |
has(java.lang.String property)
|
static java.lang.String |
join(java.lang.String delimiter,
java.lang.Object... collection)
|
<T extends java.lang.Enum<T>>
java.util.Set<T> |
|
logAll(java.lang.String property,
java.util.Set<T> value)
|
protected static
<T extends java.lang.Enum<T>>
java.lang.String[] |
|
lowercase(java.util.Collection<T> items)
|
protected static
<T extends java.lang.Enum<T>>
java.lang.String[] |
|
lowercase(T... items)
|
protected static java.lang.String |
possibleValues(java.lang.Class<? extends java.lang.Enum> enumType)
|
protected static
<V extends java.lang.Enum<V>>
java.lang.String |
|
possibleValues(V v)
|
void |
setLogger(Options.Log logger)
|
static
<T extends java.lang.Enum<T>>
T |
|
valueOf(java.lang.Class<T> enumType,
java.lang.String name)
Use this instead of Enum.valueOf() when you want to ensure that the
the enum values are case insensitive. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Options
public Options(java.util.Properties properties)
Options
public Options(java.util.Properties properties,
Options parent)
getProperties
public java.util.Properties getProperties()
setLogger
public void setLogger(Options.Log logger)
getLogger
public Options.Log getLogger()
has
public boolean has(java.lang.String property)
get
public java.lang.String get(java.lang.String property,
java.lang.String defaultValue)
get
public <T> T get(java.lang.String property,
T defaultValue)
get
public int get(java.lang.String property,
int defaultValue)
get
public long get(java.lang.String property,
long defaultValue)
get
public boolean get(java.lang.String property,
boolean defaultValue)
get
public java.lang.Class get(java.lang.String property,
java.lang.Class defaultValue)
get
public <T extends java.lang.Enum<T>> T get(java.lang.String property,
T defaultValue)
getAll
public <T extends java.lang.Enum<T>> java.util.Set<T> getAll(java.lang.String property,
T... defaultValue)
getAll
public <T extends java.lang.Enum<T>> java.util.Set<T> getAll(java.lang.String property,
java.util.Set<T> defaultValue)
getAll
public <T extends java.lang.Enum<T>> java.util.Set<T> getAll(java.lang.String property,
java.lang.Class<T> enumType)
getAll
protected <T extends java.lang.Enum<T>> java.util.Set<T> getAll(java.lang.String property,
java.util.Set<T> defaultValue,
java.lang.Class<T> enumType)
valueOf
public static <T extends java.lang.Enum<T>> T valueOf(java.lang.Class<T> enumType,
java.lang.String name)
- Use this instead of Enum.valueOf() when you want to ensure that the
the enum values are case insensitive.
- Type Parameters:
T
- - Parameters:
enumType
- name
-
- Returns:
logAll
public <T extends java.lang.Enum<T>> java.util.Set<T> logAll(java.lang.String property,
java.util.Set<T> value)
lowercase
protected static <T extends java.lang.Enum<T>> java.lang.String[] lowercase(T... items)
lowercase
protected static <T extends java.lang.Enum<T>> java.lang.String[] lowercase(java.util.Collection<T> items)
possibleValues
protected static <V extends java.lang.Enum<V>> java.lang.String possibleValues(V v)
possibleValues
protected static java.lang.String possibleValues(java.lang.Class<? extends java.lang.Enum> enumType)
join
public static java.lang.String join(java.lang.String delimiter,
java.lang.Object... collection)
Copyright © 1999-2011 The Apache OpenEJB development community. All Rights Reserved.