BUG-3876: Add XPath interfaces
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / xpath / XPathSchemaContext.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 javax.annotation.Nonnull;
12 import javax.xml.xpath.XPathExpressionException;
13 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
14 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
15
16 /**
17  * A schema-informed XPath context. It supports creation of {@link XPathDocument}s, which are bound to
18  * a particular root node.
19  */
20 @Beta
21 public interface XPathSchemaContext {
22     /**
23      * Compile an XPath expression for execution on {@link XPathDocument}s produced by this context.
24      *
25      * @param xpath XPath expression to compile
26      * @param schemaPath Schema path of the node at which this expression is expected to be evaluated
27      * @return A compiled XPath expression
28      * @throws XPathExpressionException if the provided expression is invalid, either syntactically or by referencing
29      *         namespaces unknown to this schema context.
30      */
31     @Nonnull XPathExpression compileExpression(@Nonnull String xpath, @Nonnull SchemaPath schemaPath)
32             throws XPathExpressionException;
33
34     /**
35      * Create a new document context.
36      *
37      * @param documentRoot Root node of the document
38      * @return A new {@link XPathDocument} on which queries may be executed.
39      * @throws IllegalArgumentException if the document root is not known to this schema context.
40      */
41     @Nonnull XPathDocument createDocument(@Nonnull NormalizedNode<?, ?> documentRoot);
42 }