public abstract class Configurable<T> extends Object
An element which is configurable without presupposing how the configuration is done.
Does your class need to know or has to assume that the configuration is coming from system properties ??
The response is obviously NO !
Let's compare the following examples:
class Document { private static final Font FONT = Font.decode(System.getProperty("pkg.Document#FONT") != null ? System.getProperty("FONT") : "Arial-BOLD-18"); }
With the following:
class Document { public static final Configurable<Font> FONT = new Configurable<Font>(new Font("Arial", Font.BOLD, 18)) { protected Font parse(String str) { return Font.decode(str); } }; }
Not only the second example is cleaner, but the actual configuration data can come from anywhere, for example from system properties (default value), OSGi Configuration Admin service, another bundle, etc. Low level code does not need to know.
Users can be notified of configuration changes through the OSGi
Configurable.Listener
service.
Modifier and Type | Class and Description |
---|---|
static interface |
Configurable.Listener
Services to be published by any one interested in being informed of
configurable changes.
|
Modifier and Type | Field and Description |
---|---|
static SecurityContext.Permission<Configurable<?>> |
RECONFIGURE_PERMISSION
Holds the general permission to reconfigure configurables values
(action
"reconfigure" ). |
Constructor and Description |
---|
Configurable(T value)
Creates a configurable having the specified value.
|
Modifier and Type | Method and Description |
---|---|
T |
get()
Returns this configurable value.
|
String |
getName()
Returns this configurable name.
|
SecurityContext.Permission<Configurable<T>> |
getReconfigurePermission()
Returns the permission to configure this instance.
|
protected abstract T |
parse(String str)
Parses the specified text to return the corresponding value.
|
void |
reconfigure(T newValue)
Reconfigures this instance with the specified new value if authorized
by the
SecurityContext . |
public static SecurityContext.Permission<Configurable<?>> RECONFIGURE_PERMISSION
"reconfigure"
).
Whether or not that permission is granted depends on the current
SecurityContext
. It is possible that the general permission
to reconfigure a configurable is granted but revoked for a specific
instance. Also, the general permission to reconfigure a configurable
may be revoked but granted only for a specific instance.public Configurable(T value)
name
, the
the parsed
value of the property supersedes the
value specified. For example running the JVM with the option
-Djavolution.context.ConcurrentContext#CONCURRENCY=0
disables concurrency support.protected abstract T parse(String str)
public T get()
public String getName()
UnsupportedOperationException
- if the enclosing class has
multiple configurable static fields.public SecurityContext.Permission<Configurable<T>> getReconfigurePermission()
public void reconfigure(T newValue)
SecurityContext
.newValue
- the new value.SecurityException
- if the permission to reconfigure this
configurable is not granted.Copyright © 2005-2013 Javolution. All Rights Reserved.