fef07e744dc8efede4cf45a38d2e5005855fdbbb
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / PathExpression.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.api;
9
10 import com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNullByDefault;
12 import org.opendaylight.yangtools.concepts.Immutable;
13 import org.opendaylight.yangtools.yang.xpath.api.YangBinaryOperator;
14 import org.opendaylight.yangtools.yang.xpath.api.YangFunction;
15 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath;
16 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.QNameStep;
17 import org.opendaylight.yangtools.yang.xpath.api.YangXPathAxis;
18 import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression;
19
20 /**
21  * An expression as defined in <a href="https://tools.ietf.org/html/rfc7950#section-9.9.2">RFC7950 Section 9.9.2</a>,
22  * i.e. the argument of a {@code path} statement.
23  *
24  * <p>
25  * Semantically a {@link PathExpression} is similar to a {@link YangXPathExpression} with guarantees around what
26  * subexpressions it can contain:
27  * <ul>
28  * <li>the root expression must be a {@link YangLocationPath}</li>
29  * <li>it can contain steps only along {@link YangXPathAxis#CHILD} and {@link YangXPathAxis#PARENT} axis</li>
30  * <li>all steps along {@link YangXPathAxis#CHILD} axis are {@link QNameStep}</li>
31  * <li>the only function invocation is {@link YangFunction#CURRENT}</li>
32  * <li>only {@link YangBinaryOperator#EQUALS} is allowed</li>
33  * <li>no literals nor numbers are allowed</li>
34  * <li>all qualified node identifiers must me resolved</li>
35  * </ul>
36  *
37  * @author Robert Varga
38  */
39 @Beta
40 @NonNullByDefault
41 public interface PathExpression extends Immutable {
42     /**
43      * Returns the path expression formatted string as is defined in model. For example:
44      * {@code /prefix:container/prefix:container::cond[when()=foo]/prefix:leaf}
45      *
46      * @return the path expression formatted string as is defined in model.
47      */
48     String getOriginalString();
49
50     /**
51      * Return the {@link YangLocationPath} of this expression.
52      *
53      * @return The location path
54      * @throws UnsupportedOperationException if the implementation has not parsed the string. Implementations are
55      *         strongly encouraged to perform proper parsing.
56      */
57     YangLocationPath getLocation();
58
59     /**
60      * Returns <code>true</code> if the XPapth starts in root of YANG model, otherwise returns <code>false</code>.
61      *
62      * @return <code>true</code> if the XPapth starts in root of YANG model, otherwise returns <code>false</code>
63      */
64     default boolean isAbsolute() {
65         return getLocation().isAbsolute();
66     }
67 }