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 java.lang.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/dt/dev/farrago/src/org/eigenbase/util/property/Property.java#8 $
Author:
jhyde

Field Summary
protected  java.util.Properties properties
           
 
Constructor Summary
protected Property(java.util.Properties properties, java.lang.String path, java.lang.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.
 java.lang.String getDefaultValue()
          Returns the default value of this property.
protected  java.lang.String getInternal(java.lang.String defaultValue, boolean required)
          Retrieves the value of a property, using a given default value, and optionally failing if there is no value.
 java.lang.String getPath()
           
 java.lang.String getString()
          Returns the value of this property as a string.
 boolean isSet()
          Returns whether this property has a value assigned.
 void onChange(java.lang.String oldValue, java.lang.String value)
          Called when a property's value has just changed.
 void removeTrigger(Trigger trigger)
          Removes a trigger from this property.
 java.lang.Object setString(java.lang.String value)
          Sets a property directly as a string.
 java.lang.String stringValue()
          Returns the value of the property as a string.
protected static boolean toBoolean(java.lang.String value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

properties

protected final java.util.Properties properties
Constructor Detail

Property

protected Property(java.util.Properties properties,
                   java.lang.String path,
                   java.lang.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 java.lang.String getPath()
Returns:
this property's name (typically a dotted path)

getDefaultValue

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


getInternal

protected java.lang.String getInternal(java.lang.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(java.lang.String oldValue,
                     java.lang.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 java.lang.Object setString(java.lang.String value)
Sets a property directly as a string.


isSet

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


getString

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


booleanValue

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


toBoolean

protected static boolean toBoolean(java.lang.String value)

stringValue

public java.lang.String stringValue()
Returns the value of the property as a string.