Initial code drop of netconf protocol implementation
[controller.git] / opendaylight / netconf / netconf-util / src / main / java / org / opendaylight / controller / netconf / util / messages / NetconfMessageUtil.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.messages;
10
11 import org.opendaylight.controller.netconf.api.NetconfMessage;
12 import org.opendaylight.controller.netconf.util.xml.XmlElement;
13 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
14 import org.w3c.dom.Document;
15
16 public class NetconfMessageUtil {
17
18     public static boolean isOKMessage(NetconfMessage message) {
19         return isOKMessage(message.getDocument());
20     }
21
22     public static boolean isOKMessage(Document document) {
23         return isOKMessage(XmlElement.fromDomDocument(document));
24     }
25
26     public static boolean isOKMessage(XmlElement xmlElement) {
27         return xmlElement.getOnlyChildElement().getName().equals(XmlNetconfConstants.OK);
28     }
29
30     public static boolean isErrorMEssage(NetconfMessage message) {
31         return isErrorMessage(message.getDocument());
32     }
33
34     public static boolean isErrorMessage(Document document) {
35         return isErrorMessage(XmlElement.fromDomDocument(document));
36     }
37
38     public static boolean isErrorMessage(XmlElement xmlElement) {
39         return xmlElement.getOnlyChildElement().getName().equals(XmlNetconfConstants.RPC_ERROR);
40
41     }
42 }