org.pf.textx
Class BasicVariableContainer

java.lang.Object
  extended by org.pf.textx.BasicVariableContainer
All Implemented Interfaces:
VariableContainer, VariableResolver

public class BasicVariableContainer
extends java.lang.Object
implements VariableContainer

This is a basic implementation of the interface VariableResolver. It provides a container for a simple mapping of variable name to their corresponding values.

Version:
1.2
Author:
Manfred Duchrow

Constructor Summary
BasicVariableContainer()
          Initialize the new instance with default values.
BasicVariableContainer(java.util.Map mapping)
          Initialize the new instance with the given mapping.
 
Method Summary
 void addFrom(java.util.Map vars)
          Adds all key value pairs from the given map to the variables, if the key is a String.
 java.lang.Object getValue(java.lang.String varName)
          Returns the value for the variable with the given name.
 boolean isKnownVariable(java.lang.String varName)
          Returns if the variable with the given name can be resolved by the receiver.
 java.util.Set knownVariableNames()
          Returns all variable name the resolver currently knows
 void removeVariable(java.lang.String varName)
          Remove the variable with the specified name.
 void setValue(java.lang.String varName, java.lang.String value)
          Sets the value of the variable with the given name.
 void setValueFor(java.lang.String varName, boolean value)
          Sets the boolean value of the variable with the given name.
 void setValueFor(java.lang.String varName, java.lang.Object value)
          Sets the value of the variable with the given name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicVariableContainer

public BasicVariableContainer()
Initialize the new instance with default values.
Subclasses that override this constructor must call super() first, before doing anything else.


BasicVariableContainer

public BasicVariableContainer(java.util.Map mapping)
Initialize the new instance with the given mapping.

Parameters:
mapping - The instance of a Map interface compliant class.
Method Detail

knownVariableNames

public java.util.Set knownVariableNames()
Returns all variable name the resolver currently knows

Specified by:
knownVariableNames in interface VariableResolver

getValue

public java.lang.Object getValue(java.lang.String varName)
                          throws UnknownVariableException
Returns the value for the variable with the given name.

Specified by:
getValue in interface VariableResolver
Parameters:
varName - The case sensitive name of the variable.
Returns:
The value associated to the given variable (even null is a valid value)
Throws:
UnknownVariableException - The receiver is not knowing the variable.

isKnownVariable

public boolean isKnownVariable(java.lang.String varName)
Returns if the variable with the given name can be resolved by the receiver.

Specified by:
isKnownVariable in interface VariableResolver
Parameters:
varName - The case sensitive name of the variable.
Returns:
Whether the variable with the given name is known or not.

setValueFor

public void setValueFor(java.lang.String varName,
                        java.lang.Object value)
Sets the value of the variable with the given name.

Specified by:
setValueFor in interface VariableContainer
Parameters:
varName - The case sensitive name of the variable. Must not be null !
value - The new value of the variable. Must not be null !

setValueFor

public void setValueFor(java.lang.String varName,
                        boolean value)
Sets the boolean value of the variable with the given name.

Parameters:
varName - The case sensitive name of the variable. Must not be null !
value - The boolean value

setValue

public void setValue(java.lang.String varName,
                     java.lang.String value)
Sets the value of the variable with the given name.

Specified by:
setValue in interface VariableContainer
Parameters:
varName - The case sensitive name of the variable. Must not be null !
value - The new value of the variable. Must not be null !

removeVariable

public void removeVariable(java.lang.String varName)
Remove the variable with the specified name.

Specified by:
removeVariable in interface VariableContainer
Parameters:
varName - The name of the variable to be removed

addFrom

public void addFrom(java.util.Map vars)
Adds all key value pairs from the given map to the variables, if the key is a String.