public class SimpleVariableContext extends java.lang.Object implements VariableContext, java.io.Serializable
VariableContext
.
This is a simple table-based key-lookup implementation
for VariableContext
which can be programmatically
extended by setting additional variables.
Modifier and Type | Field and Description |
---|---|
private static long |
serialVersionUID |
private java.util.Map |
variables
Table of variable bindings.
|
Constructor and Description |
---|
SimpleVariableContext()
Construct.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
getVariableValue(java.lang.String namespaceURI,
java.lang.String prefix,
java.lang.String localName)
An implementation should return the value of an XPath variable
based on the namespace URI and local name of the variable-reference
expression.
|
void |
setVariableValue(java.lang.String localName,
java.lang.Object value)
Set the value associated with a variable.
|
void |
setVariableValue(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.Object value)
Set the value associated with a variable.
|
private static final long serialVersionUID
private java.util.Map variables
public SimpleVariableContext()
Create a new empty variable context.
public void setVariableValue(java.lang.String namespaceURI, java.lang.String localName, java.lang.Object value)
This method sets a variable that is
associated with a particular namespace.
These variables appear such as $prefix:foo
in an XPath expression. Prefix to URI resolution
is the responsibility of a NamespaceContext
.
Variables within a VariableContext
are
referred to purely based upon their namespace URI,
if any.
namespaceURI
- the namespace URI of the variablelocalName
- the local name of the variablevalue
- The value to be bound to the variablepublic void setVariableValue(java.lang.String localName, java.lang.Object value)
This method sets a variable that is not
associated with any particular namespace.
These variables look like $foo
in an XPath expression.
localName
- the local name of the variablevalue
- the value to be bound to the variablepublic java.lang.Object getVariableValue(java.lang.String namespaceURI, java.lang.String prefix, java.lang.String localName) throws UnresolvableException
VariableContext
It must not use the prefix parameter to select a variable, because a prefix could be bound to any namespace; the prefix parameter could be used in debugging output or other generated information. The prefix may otherwise be ignored.
getVariableValue
in interface VariableContext
namespaceURI
- the namespace URI to which the prefix parameter
is bound in the XPath expression. If the variable
reference expression had no prefix, the namespace
URI is null
.prefix
- the prefix that was used in the variable reference
expression; this value is ignored and has no effectlocalName
- the local name of the variable-reference
expression. If there is no prefix, then this is
the whole name of the variable.null
)UnresolvableException
- when the variable cannot be resolved