org.eigenbase.util.property
Class Property

java.lang.Object
  extended by org.eigenbase.util.property.Property
Direct Known Subclasses:
BooleanProperty, DoubleProperty, IntegerProperty, StringProperty

public abstract class Property
extends Object

Definition and accessor for a property.

For example:

 class MyProperties extends Properties {
     public final IntegerProperty DebugLevel =
         new IntegerProperty(this, "com.acme.debugLevel", 10);
 }

 MyProperties props = new MyProperties();
 System.out.println(props.DebugLevel.get()); // prints "10", the default
 props.DebugLevel.set(20);
 System.out.println(props.DebugLevel.get()); // prints "20"
 

Since:
May 4, 2004
Version:
$Id: //open/dev/farrago/src/org/eigenbase/util/property/Property.java#17 $
Author:
jhyde

Nested Class Summary
private static class Property.TriggerList
          A trigger list a list of triggers associated with a given property.
 
Field Summary
private  String defaultValue
           
private  String path
           
protected  Properties properties
           
private  Property.TriggerList triggerList
          List of triggers on this property.
 
Constructor Summary
protected Property(Properties properties, String path, String defaultValue)
          Creates a Property and associates it with an underlying properties object.
 
Method Summary
 void addTrigger(Trigger trigger)
          Adds a trigger to this property.
 boolean booleanValue()
          Returns the boolean value of this property.
 String getDefaultValue()
          Returns the default value of this property.
protected  String getInternal(String defaultValue, boolean required)
          Retrieves the value of a property, using a given default value, and optionally failing if there is no value.
 String getPath()
          Returns the name of this property.
 String getString()
          Returns the value of this property as a string.
 boolean isSet()
          Returns whether this property has a value assigned.
 void onChange(String oldValue, String value)
          Called when a property's value has just changed.
 void removeTrigger(Trigger trigger)
          Removes a trigger from this property.
 String setString(String value)
          Sets a property directly as a string.
 String stringValue()
          Returns the value of the property as a string, or null if the property is not set.
static boolean toBoolean(String value)
          Converts a string to a boolean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

properties

protected final Properties properties

path

private final String path

defaultValue

private final String defaultValue

triggerList

private final Property.TriggerList triggerList
List of triggers on this property. Access must be synchronized on this Property object.

Constructor Detail

Property

protected Property(Properties properties,
                   String path,
                   String defaultValue)
Creates a Property and associates it with an underlying properties object.

Parameters:
properties - Properties object which holds values for this property.
path - Name by which this property is serialized to a properties file, for example "com.acme.trace.Verbosity".
defaultValue - Default value, null if there is no default.
Method Detail

getPath

public String getPath()
Returns the name of this property. Typically a dotted path such as "com.acme.foo.Bar".

Returns:
this property's name (typically a dotted path)

getDefaultValue

public String getDefaultValue()
Returns the default value of this property. Derived classes (for example those with special rules) can override.


getInternal

protected String getInternal(String defaultValue,
                             boolean required)
Retrieves the value of a property, using a given default value, and optionally failing if there is no value.


addTrigger

public void addTrigger(Trigger trigger)
Adds a trigger to this property.


removeTrigger

public void removeTrigger(Trigger trigger)
Removes a trigger from this property.


onChange

public void onChange(String oldValue,
                     String value)
Called when a property's value has just changed.

If one of the triggers on the property throws a Trigger.VetoRT exception, this method passes it on.

Parameters:
oldValue - Previous value of the property
value - New value of the property
Throws:
Trigger.VetoRT - if one of the triggers threw a VetoRT

setString

public String setString(String value)
Sets a property directly as a string.

Returns:
the previous value

isSet

public boolean isSet()
Returns whether this property has a value assigned.


getString

public String getString()
Returns the value of this property as a string.


booleanValue

public boolean booleanValue()
Returns the boolean value of this property.


toBoolean

public static boolean toBoolean(String value)
Converts a string to a boolean.

Note that Boolean.parseBoolean(String) is similar, but only exists from JDK 1.5 onwards, and only accepts 'true'.

Returns:
true if the string is "1" or "true" or "yes", ignoring case and any leading or trailing spaces

stringValue

public String stringValue()
Returns the value of the property as a string, or null if the property is not set.