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.QName;
16 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.AxisStep;
17 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.AxisStepWithPredicates;
18 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.NodeTypeStep;
19 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.NodeTypeStepWithPredicates;
20 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.ProcessingInstructionStep;
21 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.ProcessingInstructionStepWithPredicates;
22 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.QNameStep;
23 import org.opendaylight.yangtools.yang.xpath.api.YangLocationPath.QNameStepWithPredicates;
26 * XPath evaluation axis, as defined in <a href="https://www.w3.org/TR/1999/REC-xpath-19991116/#axes">XPath 1.0</a>.
28 * @author Robert Varga
31 public enum YangXPathAxis {
33 * The {@code child} axis.
37 * The {@code descendant} axis.
39 DESCENDANT("descendant"),
41 * The {@code parent} axis.
45 * The {@code ancestor} axis.
49 * The {@code following-sibling} axis.
51 FOLLOWING_SIBLING("following-sibling"),
53 * The {@code preceding-sibling} axis.
55 PRECEDING_SIBLING("preceding-sibling"),
57 * The {@code following} axis.
59 FOLLOWING("following"),
61 * The {@code preceding} axis.
63 PRECEDING("preceding"),
65 * The {@code attribute} axis.
67 ATTRIBUTE("attribute"),
69 * The {@code namespace} axis.
71 NAMESPACE("namespace"),
73 * The {@code self} axis.
77 * The {@code descendant-or-self} axis.
79 DESCENDANT_OR_SELF("descendant-or-self"),
81 * The {@code ancestor-or-self} axis.
83 ANCESTOR_OR_SELF("ancestor-or-self");
85 private final AxisStep step = new AxisStep(this);
86 private final String str;
88 YangXPathAxis(final String str) {
89 this.str = requireNonNull(str);
93 * Return the name-independent {@link AxisStep} along this axis. XPath defines following axis {@code AxisStep}s:
95 * <li>{@link #SELF} axis this equals to the "." step</li>
96 * <li>{@link #PARENT} axis this equals to the ".." step</li>
97 * <li>{@link #DESCENDANT_OR_SELF} axis this equals to the "//" separator</li>
99 * other axes have these defined as a courtesy.
101 * @return Name-independent AnyNameStep.
103 public final AxisStep asStep() {
107 public final AxisStep asStep(final Collection<YangExpr> predicates) {
108 final ImmutableSet<YangExpr> set = ImmutableSet.copyOf(predicates);
109 return set.isEmpty() ? step : new AxisStepWithPredicates(this, set);
112 public final QNameStep asStep(final QName qname, final Collection<YangExpr> predicates) {
113 final ImmutableSet<YangExpr> set = ImmutableSet.copyOf(predicates);
114 return set.isEmpty() ? new QNameStep(this, qname) : new QNameStepWithPredicates(this, qname, set);
117 public final NodeTypeStep asStep(final YangXPathNodeType type, final Collection<YangExpr> predicates) {
118 final ImmutableSet<YangExpr> set = ImmutableSet.copyOf(predicates);
119 return set.isEmpty() ? new NodeTypeStep(this, type) : new NodeTypeStepWithPredicates(this, type, set);
122 public final ProcessingInstructionStep asStep(final String name, final Collection<YangExpr> predicates) {
123 final ImmutableSet<YangExpr> set = ImmutableSet.copyOf(predicates);
124 return set.isEmpty() ? new ProcessingInstructionStep(this, name)
125 : new ProcessingInstructionStepWithPredicates(this, name, set);
129 public String toString() {