2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.xpath.api;
10 import com.google.common.annotations.Beta;
11 import javax.xml.xpath.XPathExpressionException;
12 import org.opendaylight.yangtools.concepts.Immutable;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.common.UnresolvedQName.Qualified;
15 import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
16 import org.opendaylight.yangtools.yang.common.YangVersion;
19 * An XPath expression. This interface defines a parsed representation of an XPath defined in a YANG context, as
20 * specified in <a href="https://tools.ietf.org/html/rfc7950#section-6.4">RFC7950, Section 6.4</a>.
23 * The specification along with rules for {@code path} statement evaluation rules end up defining four incremental
24 * levels to which an XPath expression can be bound:
26 * <li>Unbound Expressions, which is a essentially a parse tree. No namespace binding has been performed, i.e. all
27 * node identifiers are in {@link Qualified} or {@link Unqualified} form. This level is typically not used when
28 * dealing with YANG models directly, but can be useful for validating a String conforms to XPath syntax.
30 * <li>Qualified-bound Expressions, where all {@link Qualified}s are resolved and bound to {@link QName}s, but
31 * {@link Unqualified}s are still present. This level corresponds to how far a YANG parser can interpret XPath
32 * expressions defined in {@code typedef} statements and statements which are not fully instantiated, i.e. are
33 * descendants of a {@code grouping} statement.
35 * <li>Namespace-bound Expressions, where all node identifier references are resolved to {@link QName}s. This level
36 * corresponds to how far a YANG parser can interpret XPath expressions at their place of instantiation, either in
37 * the data tree or an {@code action}/@{code rpc}/{@code notification} or similar context.
39 * <li>Context-bound Expressions, where the expression is bound to a {code context node}, i.e. {@code current()}
40 * function result is know. This API does not handle this state, as it is inherently bound to a particular data
45 * @author Robert Varga
48 public interface YangXPathExpression extends Immutable {
50 * A Qualified-bound expression. All {@link Qualified}s are eliminated and replaced with {@link QName}s.
52 interface QualifiedBound extends YangXPathExpression {
57 * An Unqualified-bound expression. All {@link Unqualified}s are eliminated and replaced with {@link QName}s.
59 interface UnqualifiedBound extends QualifiedBound {
61 YangQNameExpr.Resolved interpretAsQName(YangLiteralExpr expr) throws XPathExpressionException;
65 * Return the root {@link YangExpr}.
67 * @return Root expression.
69 YangExpr getRootExpr();
72 * Return the {@link YangXPathMathMode} used in this expression. All {@link YangNumberExpr} objects used by this
73 * expression are expected to be handled by this mode's {@link YangXPathMathSupport}.
75 * @return YangXPathMathMode
77 YangXPathMathMode getMathMode();
80 * Return the minimum YangVersion runtime required to interpret this expression.
82 * @return YangVersion runtime version compatibility level required to accurately interpret this expression.
84 YangVersion getYangVersion();
87 * Attempt to interpret a {@link YangLiteralExpr} referenced by this expression as a {@link QName}. This method
88 * is required to perform late value binding of the expression when the literal needs to be interpreted as
89 * a reference to an {@code identity}.
92 * The syntax of expr is required to conform to
93 * <a href="https://www.w3.org/TR/REC-xml-names/#NT-QName">XML QName format</a>, as further restricted by
94 * <a href="https://tools.ietf.org/html/rfc7950#section-9.10.3">YANG {@code identityref} Lexical Representation</a>.
97 * Unfortunately we do not know when a literal will need to be interpreted in this way, as that can only be known
100 * @param expr Literal to be reinterpreted
101 * @return YangQNameExpr result of interpretation
102 * @throws XPathExpressionException when the literal cannot be interpreted as a QName
104 YangQNameExpr interpretAsQName(YangLiteralExpr expr) throws XPathExpressionException;
106 // FIXME: this really should be YangInstanceIdentifier without AugmentationIdentifier. Implementations are
107 // strongly encouraged to validate it as such.
108 YangLocationPath interpretAsInstanceIdentifier(YangLiteralExpr expr) throws XPathExpressionException;