public final class XPathValue extends SimpleValue<String>
XACML 3.0 Core spec, §A.3.15: "An XPath expression evaluates to a node-set, which is a set of XML nodes that match the expression. A node or node-set is not in the formal data-type system of XACML. All comparison or other operations on node-sets are performed in isolation of the particular [XPATH-based] function specified. The context nodes and namespace mappings of the XPath expressions are defined by the XPath data-type, see section B.3."
In short, the xpathExpression is evaluated in the context of calling XPath-based functions on a given evaluation context only. These functions typically use evaluate(EvaluationContext)
to
get the matching node-set.
WARNING: this class is not optimized for request-time evaluation but for policy initialization-time. Therefore, its use is not recommended for evaluating xpathExpressions in XACML Request. We consider it not useful in the latter case, as the Requester (PEP) could evaluate the xpathExpressions in the first place, and does not need the PDP to do it.
NB (considerations for developers): the standard datatype 'xpathExpression' may seem like a special case because xpathExpression evaluation depends on the context; therefore it might seem like a
good idea to have 'xpathExpression' be implemented as a subclass of Expression
instead. However, we prefer to avoid that for simplicity. Indeed,
if we need to evaluate a 'xpathExpression', in standard XACML, xpathExpressions are used only as parameters of XPath-based functions (A.3.15), and such functions just need to cast input values to
this XPathValue
class and call evaluate(EvaluationContext)
for evaluation. Outside the context of XPath-based functions, we may consider xpathExpressions as simple literal
constants like other AttributeValues.
SimpleValue.BaseFactory<AV extends AttributeValue>
Modifier and Type | Field and Description |
---|---|
static String |
XPATH_CATEGORY_ATTRIBUTE_LOCALNAME
XML attribute local name that indicate the XACML attribute category of the Content to which the xpathExpression is applied: "XPathCategory" .
|
static QName |
XPATH_CATEGORY_ATTRIBUTE_QNAME
QName of XPathCategory attribute in xpathExpression, using "XPathCategory" as local name.
|
value
Constructor and Description |
---|
XPathValue(String xpath,
Map<QName,String> otherXmlAttributes,
net.sf.saxon.s9api.XPathCompiler xPathCompiler)
Instantiates from XPath expression.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
net.sf.saxon.s9api.XdmValue |
evaluate(EvaluationContext context)
Convenient method to get the XML nodes ("node-set") matching the XPath expression from the Content node of the XACML Attributes element with category XPathCategory in this
context . |
Map<QName,String> |
getXmlAttributes()
Get the attributes attached to the value as specified by
XmlAnyAttribute , or any kind of attributes/metadata defined by some markup language that this value
type is designed to be (de)serialized (from) to. |
int |
hashCode() |
String |
printXML()
Converts the internal value (accessible via
SimpleValue.getUnderlyingValue() to a valid lexical representation for XML marshalling. |
getContent, getUnderlyingValue, toString
public static final String XPATH_CATEGORY_ATTRIBUTE_LOCALNAME
public static final QName XPATH_CATEGORY_ATTRIBUTE_QNAME
<xs:anyAttribute namespace="##any" processContents="lax"/>
... therefore namespace returned by JAXB is empty "". More info: https://jaxb.java.net/tutorial/section_6_2_7_5 -Collecting-Unspecified-Attributes-XmlAnyAttribute
.html#Collecting%20Unspecified%20Attributes:%20XmlAnyAttributepublic XPathValue(String xpath, Map<QName,String> otherXmlAttributes, net.sf.saxon.s9api.XPathCompiler xPathCompiler) throws IllegalArgumentException
xpath
- XPathotherXmlAttributes
- other XML attributes on the xpathExpression AttributeValue node, one of which is expected to be the attribute "XPathCategory"xPathCompiler
- XPath compiler for compiling/evaluating xpath
IllegalArgumentException
- if value
is not a valid string representation for this value datatype or {code otherXmlAttributes == null} or {code otherXmlAttributes} does not contain any
"XPathCategory" attributepublic net.sf.saxon.s9api.XdmValue evaluate(EvaluationContext context) throws IndeterminateEvaluationException
context
. XPathCategory is extracted from the attribute of the same name in otherXmlAttributes
argument passed to XPathValue(String, Map, XPathCompiler)
when
creating this instance. To be used by XPath-based functions defined in section A.3.15 of XACML 3.0 Core specification.context
- current evaluation contextIndeterminateEvaluationException
- error evaluating the XPath expressionpublic int hashCode()
hashCode
in class SimpleValue<String>
public boolean equals(Object obj)
equals
in class SimpleValue<String>
public String printXML()
SimpleValue.getUnderlyingValue()
to a valid lexical representation for XML marshalling. Equivalent to the 'printMethod' in JAXB 'javaType' binding
customizations. Implementations of this typically call DatatypeConverter
. This method is called by SimpleValue.getContent()
and its result cached by the same method for later use.
Therefore, no need to cache the result in the implementation.printXML
in class SimpleValue<String>
public Map<QName,String> getXmlAttributes()
AttributeValue
XmlAnyAttribute
, or any kind of attributes/metadata defined by some markup language that this value
type is designed to be (de)serialized (from) to. The primary use of this is (de)serialization of XML attributes. Each key is an attribute's QName and the associated value is the attribute's
string value. One example of such XML attribute in XACML standard is the xpathExpression value which has an XPathCategory attribute.Copyright © 2012–2020. All rights reserved.