public class ExprContextImpl extends OutermostExprContext
An ExprContextImpl can be reused as long as the documents explored using XPath expressions/patterns are not modified (because the IDs of these documents are cached).
It is also possible to reuse a context after invoking reset()
.
Modifier and Type | Field and Description |
---|---|
protected DocumentManager |
documentManager |
protected static HashMap<String,IdEntry> |
EMPTY_ID_MAP |
protected IdentityLinearHashtable<Name,Variant> |
globalVariables |
protected static String |
ID_MAP_PROP |
protected IdentityLinearHashtable<Document,Map<String,IdEntry>> |
idMaps |
Constructor and Description |
---|
ExprContextImpl()
Constructs an ExprContext using the global document cache as its
document manager.
|
ExprContextImpl(DocumentManager docManager)
Constructs an ExprContext using specified document manager.
|
Modifier and Type | Method and Description |
---|---|
protected Map<String,IdEntry> |
doGetIdMap(Document doc) |
XNode |
findElementWithId(XNode node,
String id)
Returns
null because this basic implementation
is not schema-aware. |
protected XNode |
findNodeByFragment(Document doc,
String fragment) |
NodeIterator |
getDocument(String uriRef,
URL baseURL)
Returns
NullNodeIterator.INSTANCE because this basic
implementation does not know how to load documents. |
DocumentManager |
getDocumentManager()
Returns the document manager used by this ExprContext.
|
Variant |
getGlobalVariable(Name name,
XNode node)
Returns the value of specified global variable if any;
null otherwise. |
protected Map<String,IdEntry> |
getIdMap(XNode node) |
Variant |
getVariableValue(Name name,
XNode node)
Returns
null because this basic implementation
does not handle variable references. |
boolean |
isElementWithId(XNode node,
String id)
Returns
false because this basic implementation
is not schema aware. |
void |
reset()
Invoke this method before reusing this context:
it clears global variables and cached data (element IDs).
|
protected URL |
resolveDocumentURL(String uriRef,
URL baseURL) |
void |
setDocumentManager(DocumentManager docManager)
Specifies the document manager used by this ExprContext.
|
Variant |
setGlobalVariable(Name name,
Variant value)
Set specified global (that is, top level) variable to specified value.
|
getCurrent, getKeyedNodes, getLastPosition, getPosition
protected final IdentityLinearHashtable<Name,Variant> globalVariables
protected DocumentManager documentManager
protected IdentityLinearHashtable<Document,Map<String,IdEntry>> idMaps
protected static final String ID_MAP_PROP
public ExprContextImpl()
DocumentCache.getCache()
public ExprContextImpl(DocumentManager docManager)
docManager
- the document manager used by
this ExprContext. May be null
.
Note that without a proper document manager, the document() function always returns an empty node-set.
public void setDocumentManager(DocumentManager docManager)
docManager
- the document manager used by
this ExprContext. May be null
.
Note that without a proper DocumentManager, the document() function always returns an empty node-set.
public DocumentManager getDocumentManager()
null
if this context has no document manager.public Variant setGlobalVariable(Name name, Variant value)
name
- name of the variablevalue
- new value of the variable. Specify null
to unset the variable.null
otherwise.getGlobalVariable(com.xmlmind.xml.name.Name, com.xmlmind.xml.doc.XNode)
,
getVariableValue(com.xmlmind.xml.name.Name, com.xmlmind.xml.doc.XNode)
public Variant getGlobalVariable(Name name, XNode node) throws EvalException
null
otherwise.name
- name of the variablenull
otherwise.EvalException
setGlobalVariable(com.xmlmind.xml.name.Name, com.xmlmind.xml.xpath.Variant)
,
getVariableValue(com.xmlmind.xml.name.Name, com.xmlmind.xml.doc.XNode)
public Variant getVariableValue(Name name, XNode node) throws EvalException
null
because this basic implementation
does not handle variable references.
Default implementation invokes getGlobalVariable(com.xmlmind.xml.name.Name, com.xmlmind.xml.doc.XNode)
.
getVariableValue
in interface ExprContext
getVariableValue
in class OutermostExprContext
node
- the context node. Generally not useful.EvalException
setGlobalVariable(com.xmlmind.xml.name.Name, com.xmlmind.xml.xpath.Variant)
public void reset()
Note that this method has no effect on the document manager, if any.
public XNode findElementWithId(XNode node, String id) throws EvalException
OutermostExprContext
null
because this basic implementation
is not schema-aware.findElementWithId
in interface ExprContext
findElementWithId
in class OutermostExprContext
node
- used to specify the documentid
- searched ID valuenull
otherwiseEvalException
- if a problem occurs during the searchpublic boolean isElementWithId(XNode node, String id) throws EvalException
OutermostExprContext
false
because this basic implementation
is not schema aware.isElementWithId
in interface ExprContext
isElementWithId
in class OutermostExprContext
node
- node possibly having an ID attributeid
- ID value to be matched against the possible ID attribute of nodetrue
if specified node has an ID attribute
having specified value; false
otherwiseEvalException
- if a problem occurs during the matchpublic NodeIterator getDocument(String uriRef, URL baseURL) throws EvalException
OutermostExprContext
NullNodeIterator.INSTANCE
because this basic
implementation does not know how to load documents.getDocument
in interface ExprContext
getDocument
in class OutermostExprContext
uriRef
- specifies nodes (using a fragment) in a documentbaseURL
- URL possibly used to resolve relative URL in uriRef;
may be null
EvalException
- if a problem occurs during the operationNullNodeIterator
protected URL resolveDocumentURL(String uriRef, URL baseURL) throws EvalException
EvalException
protected XNode findNodeByFragment(Document doc, String fragment) throws EvalException
EvalException