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.
23 public interface XPathExpression {
25 * Evaluate this expression at the specified path in a document. If evaluation succeeds, it will return an
26 * {@link XPathResult}. If it fails to match anything, it will return {@link Optional#empty()}. Implementations
27 * of this method are expected to perform complete evaluation such that accessing data via the resulting
28 * {@link XPathResult} will not incur large overhead.
30 * @param document {@link XPathDocument} on which evaluation should take place
31 * @param path Path to the node on which to evaluate the expression
32 * @return An optional {@link XPathResult}
33 * @throws NullPointerException if any of the arguments are null
34 * @throws XPathExpressionException if the expression cannot be evaluated
35 * @throws IllegalArgumentException if the path does not match the path at which this expression was compiled
37 Optional<? extends XPathResult<?>> evaluate(@NonNull XPathDocument document, @NonNull YangInstanceIdentifier path)
38 throws XPathExpressionException;
41 * Return the evaluation context SchemaPath of this expression. This is corresponds to the SchemaPath at which this
42 * expression was compiled at, or relocated to via {@link RelocatableXPathExpression#relocateExpression()}.
44 * @return The evaluation {@link SchemaPath}
46 @NonNull SchemaPath getEvaluationPath();
49 * Return the SchemaPath of the topmost node which affects the result of evaluation of this expression. This
50 * information is useful for large evolving documents (such as
51 * {@link org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree} implementations) to minimize the frequency
52 * of evaluation. The apex can be either logically higher or lower in the SchemaPath tree than
53 * {@link #getEvaluationPath()}.
55 * @return The apex node evaluation of this expression can reference, or {@link SchemaPath#ROOT} if it cannot
56 * cannot be conclusively determined.
58 @NonNull SchemaPath getApexPath();