Class XPathValue
- java.lang.Object
-
- org.ow2.authzforce.core.pdp.api.value.SimpleValue<String>
-
- org.ow2.authzforce.core.pdp.api.value.XPathValue
-
- All Implemented Interfaces:
AttributeValue
,PrimitiveValue
,Value
public final class XPathValue extends SimpleValue<String>
Representation of XACML xpathExpression datatype. All objects of this class are immutable and all methods of the class are thread-safe.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 thisXPathValue
class and callevaluate(EvaluationContext)
for evaluation. Outside the context of XPath-based functions, we may consider xpathExpressions as simple literal constants like other AttributeValues.- Version:
- $Id: $
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.ow2.authzforce.core.pdp.api.value.SimpleValue
SimpleValue.BaseFactory<AV extends AttributeValue>
-
-
Field Summary
Fields Modifier and Type Field 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.-
Fields inherited from class org.ow2.authzforce.core.pdp.api.value.SimpleValue
value
-
-
Constructor Summary
Constructors Constructor Description XPathValue(String xpath, Map<QName,String> otherXmlAttributes, net.sf.saxon.s9api.XPathCompiler xPathCompiler)
Instantiates from XPath expression.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 thiscontext
.Map<QName,String>
getXmlAttributes()
Get the attributes attached to the value as specified byXmlAnyAttribute
, 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 viaSimpleValue.getUnderlyingValue()
to a valid lexical representation for XML marshalling.-
Methods inherited from class org.ow2.authzforce.core.pdp.api.value.SimpleValue
getContent, getUnderlyingValue, toString
-
-
-
-
Field Detail
-
XPATH_CATEGORY_ATTRIBUTE_LOCALNAME
public static final 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" .- See Also:
- Constant Field Values
-
XPATH_CATEGORY_ATTRIBUTE_QNAME
public static final QName XPATH_CATEGORY_ATTRIBUTE_QNAME
QName of XPathCategory attribute in xpathExpression, using "XPathCategory" as local name. This is allowed by XACML schema as part of:<xs:anyAttribute namespace="##any" processContents="lax"/>
-
-
Constructor Detail
-
XPathValue
public XPathValue(String xpath, Map<QName,String> otherXmlAttributes, net.sf.saxon.s9api.XPathCompiler xPathCompiler) throws IllegalArgumentException
Instantiates from XPath expression.- Parameters:
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/evaluatingxpath
- Throws:
IllegalArgumentException
- ifvalue
is not a valid string representation for this value datatype or {code otherXmlAttributes == null} or {code otherXmlAttributes} does not contain any "XPathCategory" attribute
-
-
Method Detail
-
evaluate
public net.sf.saxon.s9api.XdmValue evaluate(EvaluationContext context) throws IndeterminateEvaluationException
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 thiscontext
. XPathCategory is extracted from the attribute of the same name inotherXmlAttributes
argument passed toXPathValue(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.- Parameters:
context
- current evaluation context- Returns:
- node-set
- Throws:
IndeterminateEvaluationException
- error evaluating the XPath expression
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classSimpleValue<String>
-
equals
public boolean equals(Object obj)
- Overrides:
equals
in classSimpleValue<String>
-
printXML
public String printXML()
Converts the internal value (accessible viaSimpleValue.getUnderlyingValue()
to a valid lexical representation for XML marshalling. Equivalent to the 'printMethod' in JAXB 'javaType' binding customizations. Implementations of this typically callDatatypeConverter
. This method is called bySimpleValue.getContent()
and its result cached by the same method for later use. Therefore, no need to cache the result in the implementation.- Specified by:
printXML
in classSimpleValue<String>
- Returns:
- XML-valid lexical representation.
-
getXmlAttributes
public Map<QName,String> getXmlAttributes()
Description copied from interface:AttributeValue
Get the attributes attached to the value as specified byXmlAnyAttribute
, 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.- Returns:
- (possibly mixed) content ; not null (must be empty if no attribute)
-
-