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 static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.collect.ImmutableSet;
14 import java.util.Collection;
15 import org.opendaylight.yangtools.yang.common.AbstractQName;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.AxisStep;
18 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.AxisStepWithPredicates;
19 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.NodeTypeStep;
20 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.NodeTypeStepWithPredicates;
21 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.ProcessingInstructionStep;
22 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.ProcessingInstructionStepWithPredicates;
23 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.ResolvedQNameStep;
24 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.UnresolvedQNameStep;
27 * XPath evaluation axis, as defined in <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#axes">XPath 1.0</a>.
29 * @author Robert Varga
32 public enum YangXPathAxis {
34 * The {@code child} axis.
38 * The {@code descendant} axis.
40 DESCENDANT("descendant"),
42 * The {@code parent} axis.
46 * The {@code ancestor} axis.
50 * The {@code following-sibling} axis.
52 FOLLOWING_SIBLING("following-sibling"),
54 * The {@code preceding-sibling} axis.
56 PRECEDING_SIBLING("preceding-sibling"),
58 * The {@code following} axis.
60 FOLLOWING("following"),
62 * The {@code preceding} axis.
64 PRECEDING("preceding"),
66 * The {@code attribute} axis.
68 ATTRIBUTE("attribute"),
70 * The {@code namespace} axis.
72 NAMESPACE("namespace"),
74 * The {@code self} axis.
78 * The {@code descendant-or-self} axis.
80 DESCENDANT_OR_SELF("descendant-or-self"),
82 * The {@code ancestor-or-self} axis.
84 ANCESTOR_OR_SELF("ancestor-or-self");
86 private final AxisStep step = new AxisStep(this);
87 private final String str;
89 YangXPathAxis(final String str) {
90 this.str = requireNonNull(str);
94 * Return the name-independent {@link AxisStep} along this axis. XPath defines following axis {@code AxisStep}s:
96 * <li>{@link #SELF} axis this equals to the "." step</li>
97 * <li>{@link #PARENT} axis this equals to the ".." step</li>
98 * <li>{@link #DESCENDANT_OR_SELF} axis this equals to the "//" separator</li>
100 * other axes have these defined as a courtesy.
102 * @return Name-independent AnyNameStep.
104 public final AxisStep asStep() {
108 public final AxisStep asStep(final Collection<YangExpr> predicates) {
109 return predicates.isEmpty() ? step : new AxisStepWithPredicates(this, ImmutableSet.copyOf(predicates));
112 public final ResolvedQNameStep asStep(final QName qname) {
113 return new ResolvedQNameStep(this, qname);
116 public final ResolvedQNameStep asStep(final QName qname, final Collection<YangExpr> predicates) {
117 return ResolvedQNameStep.of(this, qname, predicates);
120 public final UnresolvedQNameStep asStep(final AbstractQName qname) {
121 return new UnresolvedQNameStep(this, qname);
124 public final UnresolvedQNameStep asStep(final AbstractQName qname, final Collection<YangExpr> predicates) {
125 return UnresolvedQNameStep.of(this, qname, predicates);
128 public final NodeTypeStep asStep(final YangXPathNodeType type) {
129 return new NodeTypeStep(this, type);
132 public final NodeTypeStep asStep(final YangXPathNodeType type, final Collection<YangExpr> predicates) {
133 return predicates.isEmpty() ? asStep(type) : new NodeTypeStepWithPredicates(this, type,
134 ImmutableSet.copyOf(predicates));
137 public final ProcessingInstructionStep asStep(final String name) {
138 return new ProcessingInstructionStep(this, name);
141 public final ProcessingInstructionStep asStep(final String name, final Collection<YangExpr> predicates) {
142 return predicates.isEmpty() ? asStep(name) : new ProcessingInstructionStepWithPredicates(this, name,
143 ImmutableSet.copyOf(predicates));
147 public String toString() {