2 * Copyright (c) 2015 Cisco Systems, Inc. and others. 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.data.api.schema.xpath;
10 import com.google.common.annotations.Beta;
11 import java.util.Optional;
12 import javax.xml.xpath.XPathExpressionException;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
18 * A compiled XPath expression. Each instance is bound to a particular {@link XPathSchemaContext} and may not be
19 * evaluated on {@link XPathDocument}s from other context.
22 public interface XPathExpression {
24 * Evaluate this expression at the specified path in a document. If evaluation succeeds, it will return an
25 * {@link XPathResult}. If it fails to match anything, it will return {@link Optional#empty()}. Implementations
26 * of this method are expected to perform complete evaluation such that accessing data via the resulting
27 * {@link XPathResult} will not incur large overhead.
29 * @param document {@link XPathDocument} on which evaluation should take place
30 * @param path Path to the node on which to evaluate the expression
31 * @return An optional {@link XPathResult}
32 * @throws NullPointerException if any of the arguments are null
33 * @throws XPathExpressionException if the expression cannot be evaluated
34 * @throws IllegalArgumentException if the path does not match the path at which this expression was compiled
36 Optional<? extends XPathResult<?>> evaluate(@NonNull XPathDocument document, @NonNull YangInstanceIdentifier path)
37 throws XPathExpressionException;
40 * Return the evaluation context SchemaPath of this expression. This is corresponds to the SchemaPath at which this
41 * expression was compiled at, or relocated to via {@link RelocatableXPathExpression#relocateExpression()}.
43 * @return The evaluation {@link SchemaPath}
45 @NonNull SchemaPath getEvaluationPath();
48 * Return the SchemaPath of the topmost node which affects the result of evaluation of this expression. This
49 * information is useful for large evolving documents (such as
50 * {@link org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree} implementations) to minimize the frequency
51 * of evaluation. The apex can be either logically higher or lower in the SchemaPath tree than
52 * {@link #getEvaluationPath()}.
54 * @return The apex node evaluation of this expression can reference, or {@link SchemaPath#ROOT} if it cannot
55 * cannot be conclusively determined.
57 @NonNull SchemaPath getApexPath();