org.pf.textx
Class GlobalLocalVariables

java.lang.Object
  extended by org.pf.textx.GlobalLocalVariables
All Implemented Interfaces:
VariableContainer, VariableResolver
Direct Known Subclasses:
GlobalLocalPlaceholderReplacement

public class GlobalLocalVariables
extends java.lang.Object
implements VariableContainer

Contains global and local variable settings. It insures that local variables are used before global variables if they have the same name.

Version:
1.4
Author:
Manfred Duchrow

Constructor Summary
GlobalLocalVariables()
          Initialize the new instance with default values.
 
Method Summary
 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 newGlobalContext(VariableContainer varContainer)
          Initialize the global variable container with an new container.
 void newLocalContext(VariableContainer varContainer)
          Initialize the local variable container with an new container.
 void removeVariable(java.lang.String varName)
          Remove the variable with the specified name.
 void set(java.lang.String varName, java.lang.String value, boolean global)
          Set the variable with the given name to the specified value.
 void setGlobal(java.lang.String varName, java.lang.String value)
          Set the global variable with the given name to the specified value.
 void setGlobalFrom(java.util.Properties vars)
          Adds all given name/value pairs from the given properties to the global variables.
 void setGlobalObject(java.lang.String varName, java.lang.Object value)
          Set the global variable with the given name to the specified value.
 void setLocal(java.lang.String varName, java.lang.String value)
          Set the local variable with the given name to the specified value.
 void setLocalFrom(java.util.Properties vars)
          Adds all given name/value pairs from the given properties to the local variables.
 void setLocalObject(java.lang.String varName, java.lang.Object value)
          Set the local variable with the given name to the specified value.
 void setValue(java.lang.String varName, java.lang.String value)
          Set the value of the specified variable.
 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

GlobalLocalVariables

public GlobalLocalVariables()
Initialize the new instance with default values.

Method Detail

newLocalContext

public void newLocalContext(VariableContainer varContainer)
Initialize the local variable container with an new container.

Parameters:
varContainer - The new container (must not be null)

newGlobalContext

public void newGlobalContext(VariableContainer varContainer)
Initialize the global variable container with an new container.

Parameters:
varContainer - The new container (must not be null)

set

public void set(java.lang.String varName,
                java.lang.String value,
                boolean global)
Set the variable with the given name to the specified value.
The programmer must take care that there are no name conflicts between global and local variables. If the variable already exists, the value will be changed, otherwise the variable will be created.

Parameters:
varName - The name of the variable
value - The value to be assigned to the variable
global - Defines whether or not the variable is global

setLocal

public void setLocal(java.lang.String varName,
                     java.lang.String value)
Set the local variable with the given name to the specified value.
The programmer must take care that there are no name conflicts between global and local variables. If the local variable already exists, the value will be changed, otherwise the variable will be created.

Parameters:
varName - The name of a local variable
value - The value to be assigned to the variable

setLocalObject

public void setLocalObject(java.lang.String varName,
                           java.lang.Object value)
Set the local variable with the given name to the specified value.
If the local variable already exists, the value will be changed, otherwise the variable will be created.

Parameters:
varName - The name of a local variable
value - The value to be assigned to the variable

setGlobal

public void setGlobal(java.lang.String varName,
                      java.lang.String value)
Set the global variable with the given name to the specified value.
The programmer must take care that there are no name conflicts between global and local variables. If the global variable already exists, the value will be changed, otherwise the variable will be created.

Parameters:
varName - The name of a local variable
value - The value to be assigned to the variable

setGlobalObject

public void setGlobalObject(java.lang.String varName,
                            java.lang.Object value)
Set the global variable with the given name to the specified value.
If the global variable already exists, the value will be changed, otherwise the variable will be created.

Parameters:
varName - The name of a local variable
value - The value to be assigned to the variable

setGlobalFrom

public void setGlobalFrom(java.util.Properties vars)
Adds all given name/value pairs from the given properties to the global variables.


setLocalFrom

public void setLocalFrom(java.util.Properties vars)
Adds all given name/value pairs from the given properties to the local variables.


setValue

public void setValue(java.lang.String varName,
                     java.lang.String value)
Set the value of the specified variable. Here it will always set a local variable !

Specified by:
setValue in interface VariableContainer
Parameters:
varName - The name under which the value has to be stored
value - The value to store

setValueFor

public void setValueFor(java.lang.String varName,
                        java.lang.Object value)
Sets the value of the variable with the given name. Here it will always set a local variable !

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 !

removeVariable

public void removeVariable(java.lang.String varName)
Remove the variable with the specified name. Will be removed from global and local variables if existing there.

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

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.