Cleanup use of Guava library
[yangtools.git] / yang / yang-data-jaxen / src / main / java / org / opendaylight / yangtools / yang / data / jaxen / JaxenSchemaContext.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.jaxen;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.Converter;
13 import javax.annotation.Nonnull;
14 import javax.xml.xpath.XPathExpressionException;
15 import org.jaxen.JaxenException;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.xpath.XPathDocument;
19 import org.opendaylight.yangtools.yang.data.api.schema.xpath.XPathExpression;
20 import org.opendaylight.yangtools.yang.data.api.schema.xpath.XPathSchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23
24 final class JaxenSchemaContext implements XPathSchemaContext {
25     // Will be needed for compileExpression()
26     private final SchemaContext context;
27
28     JaxenSchemaContext(final SchemaContext context) {
29         this.context = requireNonNull(context);
30     }
31
32     @Nonnull
33     @Override
34     public XPathExpression compileExpression(@Nonnull final SchemaPath schemaPath,
35             final Converter<String, QNameModule> prefixes, @Nonnull final String xpath)
36             throws XPathExpressionException {
37         try {
38             return JaxenXPath.create(prefixes, schemaPath, xpath);
39         } catch (JaxenException e) {
40             throw new XPathExpressionException(e);
41         }
42     }
43
44     @Nonnull
45     @Override
46     public XPathDocument createDocument(@Nonnull final NormalizedNode<?, ?> documentRoot) {
47         return new JaxenDocument(this, documentRoot);
48     }
49
50     @Nonnull
51     SchemaContext getSchemaContext() {
52         return context;
53     }
54 }