org.pf.textx
Class VariableResolverPool

java.lang.Object
  extended by org.pf.textx.VariableResolverPool
All Implemented Interfaces:
VariableResolver

public class VariableResolverPool
extends java.lang.Object
implements VariableResolver

Instances of this class can pool several VariableResolver. It provides a single entry point to them by implementing the interface VariableResolver itself and redirecting it to one of the pooled variable resolver.

Version:
1.0
Author:
Manfred Duchrow

Constructor Summary
VariableResolverPool()
          Initialize the new instance with default values.
VariableResolverPool(java.util.Map aMap)
          Initialize the new instance with the given map to hold the pooled objects.
 
Method Summary
 void add(java.lang.String resolverName, VariableResolver resolver)
          Add the given resolver under the given name to the pool.
 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 remove(java.lang.String resolverName)
          Remove the resolver with the given name from the pool.
 void replace(java.lang.String resolverName, VariableResolver resolver)
          Replace the resolver under the given name to the pool.
 VariableResolver resolverNamed(java.lang.String resolverName)
          Return the resolver that was registered under the specified name in this pool.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariableResolverPool

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


VariableResolverPool

public VariableResolverPool(java.util.Map aMap)
Initialize the new instance with the given map to hold the pooled objects.

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

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.

knownVariableNames

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

Specified by:
knownVariableNames in interface VariableResolver

add

public void add(java.lang.String resolverName,
                VariableResolver resolver)
Add the given resolver under the given name to the pool.

Parameters:
resolverName - The unique name of the resolver in the pool.
resolver - The variable resolver to add.

replace

public void replace(java.lang.String resolverName,
                    VariableResolver resolver)
Replace the resolver under the given name to the pool.

Parameters:
resolverName - The unique name of the resolver in the pool.
resolver - The replacing variable resolver.

remove

public void remove(java.lang.String resolverName)
Remove the resolver with the given name from the pool.
If there's no entry with such a name, the call is ignored.

Parameters:
resolverName - The unique name of the resolver in the pool.

resolverNamed

public VariableResolver resolverNamed(java.lang.String resolverName)
Return the resolver that was registered under the specified name in this pool.

Parameters:
resolverName - The unique name of the resolver in the pool.