Remove netconf from commons/opendaylight pom
[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.namespace.NamespaceContext;
12 import javax.xml.xpath.XPath;
13 import javax.xml.xpath.XPathExpression;
14 import javax.xml.xpath.XPathExpressionException;
15 import javax.xml.xpath.XPathFactory;
16 import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;
17
18 public final class XMLNetconfUtil {
19     private static final XPathFactory FACTORY = XPathFactory.newInstance();
20     private static final NamespaceContext NS_CONTEXT = new HardcodedNamespaceResolver("netconf",
21         XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
22
23     private XMLNetconfUtil() {
24         throw new UnsupportedOperationException("Utility class");
25     }
26
27     public static XPathExpression compileXPath(final String xPath) {
28         final XPath xpath = FACTORY.newXPath();
29         xpath.setNamespaceContext(NS_CONTEXT);
30         try {
31             return xpath.compile(xPath);
32         } catch (final XPathExpressionException e) {
33             throw new IllegalStateException("Error while compiling xpath expression " + xPath, e);
34         }
35     }
36
37 }