Initial code drop of netconf protocol implementation
[controller.git] / opendaylight / netconf / netconf-util / src / main / java / org / opendaylight / controller / netconf / util / xml / XMLNetconfUtil.java
1 /*
2  * Copyright (c) 2013 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
9 package org.opendaylight.controller.netconf.util.xml;
10
11 import javax.xml.xpath.XPath;
12 import javax.xml.xpath.XPathExpression;
13 import javax.xml.xpath.XPathExpressionException;
14 import javax.xml.xpath.XPathFactory;
15
16 public class XMLNetconfUtil {
17
18     public static XPathExpression compileXPath(String xPath) {
19         final XPathFactory xPathfactory = XPathFactory.newInstance();
20         final XPath xpath = xPathfactory.newXPath();
21         xpath.setNamespaceContext(new HardcodedNamespaceResolver("netconf",
22                 XmlNetconfConstants.RFC4741_TARGET_NAMESPACE));
23         try {
24             return xpath.compile(xPath);
25         } catch (final XPathExpressionException e) {
26             throw new IllegalStateException("Error while compiling xpath expression " + xPath, e);
27         }
28     }
29
30 }