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;
12 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
13 import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;
14 import org.opendaylight.controller.netconf.util.xml.XmlElement;
15 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18 import org.w3c.dom.Document;
20 public final class NetconfUtil {
22 private static final Logger logger = LoggerFactory.getLogger(NetconfUtil.class);
24 private NetconfUtil() {}
26 public static Document checkIsMessageOk(Document response) throws NetconfDocumentedException {
27 XmlElement element = XmlElement.fromDomDocument(response);
28 Preconditions.checkState(element.getName().equals(XmlNetconfConstants.RPC_REPLY_KEY));
29 element = element.getOnlyChildElement();
30 if (element.getName().equals(XmlNetconfConstants.OK)) {
33 logger.warn("Can not load last configuration. Operation failed.");
34 throw new IllegalStateException("Can not load last configuration. Operation failed: "
35 + XmlUtil.toString(response));