Cleanup use of Guava library
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / xpath / XPathExpression.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  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.data.api.schema.xpath;
9
10 import com.google.common.annotations.Beta;
11 import java.util.Optional;
12 import javax.annotation.Nonnull;
13 import javax.xml.xpath.XPathExpressionException;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16
17 /**
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.
20  */
21 @Beta
22 public interface XPathExpression {
23     /**
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.
28      *
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
35      */
36     Optional<? extends XPathResult<?>> evaluate(@Nonnull XPathDocument document, @Nonnull YangInstanceIdentifier path)
37             throws XPathExpressionException;
38
39     /**
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()}.
42      *
43      * @return The evaluation {@link SchemaPath}
44      */
45     @Nonnull SchemaPath getEvaluationPath();
46
47     /**
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()}.
53      *
54      * @return The apex node evaluation of this expression can reference, or {@link SchemaPath#ROOT} if it cannot
55      *         cannot be conclusively determined.
56      */
57     @Nonnull SchemaPath getApexPath();
58 }