2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.netconf.util;
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
12 import org.opendaylight.controller.netconf.util.xml.XmlElement;
13 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
14 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17 import org.w3c.dom.Document;
19 public final class NetconfUtil {
21 private static final Logger logger = LoggerFactory.getLogger(NetconfUtil.class);
23 private NetconfUtil() {}
25 public static Document checkIsMessageOk(Document response) throws NetconfDocumentedException {
26 XmlElement element = XmlElement.fromDomDocument(response);
27 Preconditions.checkState(element.getName().equals(XmlNetconfConstants.RPC_REPLY_KEY));
28 element = element.getOnlyChildElement();
29 if (element.getName().equals(XmlNetconfConstants.OK)) {
32 logger.warn("Can not load last configuration. Operation failed.");
33 throw new IllegalStateException("Can not load last configuration. Operation failed: "
34 + XmlUtil.toString(response));