91db1a25b0d93ac13b6cc522e94c936ef9c3b841
[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 com.google.common.base.Converter;
11 import com.google.common.base.Preconditions;
12 import javax.annotation.Nonnull;
13 import javax.xml.xpath.XPathExpressionException;
14 import org.jaxen.JaxenException;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.xpath.XPathDocument;
18 import org.opendaylight.yangtools.yang.data.api.schema.xpath.XPathExpression;
19 import org.opendaylight.yangtools.yang.data.api.schema.xpath.XPathSchemaContext;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
22
23 final class JaxenSchemaContext implements XPathSchemaContext {
24     // Will be needed for compileExpression()
25     @SuppressWarnings("unused")
26     private final SchemaContext context;
27
28     JaxenSchemaContext(final SchemaContext context) {
29         this.context = Preconditions.checkNotNull(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) throws XPathExpressionException {
36         try {
37             return JaxenXPath.create(prefixes, schemaPath, xpath);
38         } catch (JaxenException e) {
39             throw new XPathExpressionException(e);
40         }
41     }
42
43     @Nonnull
44     @Override
45     public XPathDocument createDocument(@Nonnull final NormalizedNode<?, ?> documentRoot) {
46         return new JaxenDocument(this, documentRoot);
47     }
48 }