edu.rice.cs.drjava.config
Class DrJavaProperty

java.lang.Object
  extended by edu.rice.cs.drjava.config.DrJavaProperty
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
DrJavaActionProperty, EagerProperty, FileListProperty, FileProperty

public abstract class DrJavaProperty
extends Object
implements Cloneable

Class representing values that can be inserted as variables in external processes.

Version:
$Id$

Nested Class Summary
static class DrJavaProperty.InfiniteLoopException
          Exception thrown if an infinite loop of invalidation listening is detected.
 
Field Summary
protected  HashMap<String,String> _attributes
          Map of attributes.
protected  String _help
          Help page for this property.
protected  boolean _isCurrent
          Is the value current?
protected  Set<DrJavaProperty> _listening
          Set of other properties that are listening to this property, i.e.
protected  String _name
          Name of the property.
protected  String _value
          Value of the property.
 boolean DEACTIVATED_DUE_TO_ERROR
          Whether the invalidation listening mechanism has been deactivated due to an error.
 
Constructor Summary
DrJavaProperty(String name, String help)
          Create a property.
DrJavaProperty(String name, String value, String help)
          Create a property.
 
Method Summary
protected  void _invalidate()
          Just invalidate.
 boolean equals(Object other)
           
 String getAttribute(String key)
          Return an attribute's value.
 String getCurrent(PropertyMaps pm)
          Return the value of the property.
 String getHelp()
          Return the value, which might be stale.
 String getLazy(PropertyMaps pm)
          Return the value of the property lazily.
 String getName()
          Return the name of the property.
 int hashCode()
           
 void invalidate()
          Mark the value as stale and invalidate other properties that are listening.
protected  void invalidateOthers(Set<DrJavaProperty> alreadyVisited)
          Invalidate those properties that are listening to this property.
 boolean isCurrent()
          Return true if the value is current.
 DrJavaProperty listenToInvalidatesOf(DrJavaProperty other)
           
 void resetAttributes()
          Reset attributes to their defaults.
 void setAttribute(String key, String value)
          Set an attribute's value.
 void setAttributes(HashMap<String,String> attrs, Lambda<String,String> replaceLambda)
          Set all attribute values.
 String toString()
          Return the value, which might be stale or null.
abstract  void update(PropertyMaps pm)
          Update the property so the value is current.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEACTIVATED_DUE_TO_ERROR

public volatile boolean DEACTIVATED_DUE_TO_ERROR
Whether the invalidation listening mechanism has been deactivated due to an error.


_name

protected String _name
Name of the property. Must be unique.


_value

protected String _value
Value of the property.


_isCurrent

protected boolean _isCurrent
Is the value current?


_help

protected String _help
Help page for this property.


_attributes

protected HashMap<String,String> _attributes
Map of attributes.


_listening

protected Set<DrJavaProperty> _listening
Set of other properties that are listening to this property, i.e. when this property is invalidated, the other properties are too.

Constructor Detail

DrJavaProperty

public DrJavaProperty(String name,
                      String help)
Create a property.


DrJavaProperty

public DrJavaProperty(String name,
                      String value,
                      String help)
Create a property.

Method Detail

getName

public String getName()
Return the name of the property.


getCurrent

public String getCurrent(PropertyMaps pm)
Return the value of the property. If it is not current, update first.

Parameters:
pm - PropertyMaps used for substitution when replacing variables

getLazy

public String getLazy(PropertyMaps pm)
Return the value of the property lazily. The value may be stale.

Parameters:
pm - PropertyMaps used for substitution when replacing variables

update

public abstract void update(PropertyMaps pm)
Update the property so the value is current.

Parameters:
pm - PropertyMaps used for substitution when replacing variables

resetAttributes

public void resetAttributes()
Reset attributes to their defaults. Should be overridden by properties that use attributes.


setAttribute

public void setAttribute(String key,
                         String value)
Set an attribute's value. The attribute must already exist in the table.

Parameters:
key - name of the attribute
value - new value of the attribute
Throws:
IllegalArgumentException - if attribute with specified key does not already exist in table

setAttributes

public void setAttributes(HashMap<String,String> attrs,
                          Lambda<String,String> replaceLambda)
Set all attribute values. The attributes must already exist in the table.

Parameters:
attrs - attribute key-value pairs
replaceLambda - lambda that can be used to replace the variables in a value
Throws:
IllegalArgumentException - if an attribute with a specified key does not already exist in table

getAttribute

public String getAttribute(String key)
Return an attribute's value.

Parameters:
key - name of the attribute
Throws:
IllegalArgumentException - if attribute with specified key does not already exist in table

toString

public String toString()
Return the value, which might be stale or null.

Overrides:
toString in class Object

getHelp

public String getHelp()
Return the value, which might be stale.


isCurrent

public boolean isCurrent()
Return true if the value is current.


invalidate

public void invalidate()
Mark the value as stale and invalidate other properties that are listening.


_invalidate

protected void _invalidate()
Just invalidate.


listenToInvalidatesOf

public DrJavaProperty listenToInvalidatesOf(DrJavaProperty other)

equals

public boolean equals(Object other)
Overrides:
equals in class Object
Returns:
true if the specified property is equal to this one.

hashCode

public int hashCode()
Overrides:
hashCode in class Object
Returns:
the hash code. name is never mutated remains constant, so its hash code can be used.

invalidateOthers

protected void invalidateOthers(Set<DrJavaProperty> alreadyVisited)
Invalidate those properties that are listening to this property.

Parameters:
alreadyVisited - set of properties already visited, to avoid cycles.