*/
package org.opendaylight.netconf.util;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkState;
+
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Iterator;
import org.opendaylight.yangtools.rfc7952.data.api.NormalizedMetadata;
import org.opendaylight.yangtools.rfc7952.data.util.NormalizedMetadataWriter;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.xml.sax.SAXException;
public final class NetconfUtil {
+ private static final Logger LOG = LoggerFactory.getLogger(NetconfUtil.class);
- public static final QName NETCONF_QNAME =
- QName.create("urn:ietf:params:xml:ns:netconf:base:1.0", "2011-06-01", "netconf").intern();
+ // FIXME: document what exactly this QName means, as it is not referring to a tangible node nor the ietf-module.
+ // FIXME: what is this contract saying?
+ // - is it saying all data is going to be interpreted with this root?
+ // - is this saying we are following a specific interface contract (i.e. do we have schema mounts?)
+ // - is it also inferring some abilities w.r.t. RFC8342?
+ public static final QName NETCONF_QNAME = QName.create(QNameModule.create(SchemaContext.NAME.getNamespace(),
+ Revision.of("2011-06-01")), "netconf").intern();
+ // FIXME: is this the device-bound revision?
public static final QName NETCONF_DATA_QNAME = QName.create(NETCONF_QNAME, "data").intern();
public static final XMLOutputFactory XML_FACTORY;
- private static final Logger LOG = LoggerFactory.getLogger(NetconfUtil.class);
-
static {
- XML_FACTORY = XMLOutputFactory.newFactory();
- XML_FACTORY.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false);
+ final XMLOutputFactory f = XMLOutputFactory.newFactory();
+ // FIXME: not repairing namespaces is probably common, this should be availabe as common XML constant.
+ f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false);
+ XML_FACTORY = f;
}
- private NetconfUtil() {}
+ private NetconfUtil() {
+ // No-op
+ }
public static Document checkIsMessageOk(final Document response) throws DocumentedException {
- XmlElement element = XmlElement.fromDomDocument(response);
- Preconditions.checkState(element.getName().equals(XmlNetconfConstants.RPC_REPLY_KEY));
- element = element.getOnlyChildElement();
- if (element.getName().equals(XmlNetconfConstants.OK)) {
+ final XmlElement docElement = XmlElement.fromDomDocument(response);
+ // FIXME: we should throw DocumentedException here
+ checkState(XmlNetconfConstants.RPC_REPLY_KEY.equals(docElement.getName()));
+ final XmlElement element = docElement.getOnlyChildElement();
+ if (XmlNetconfConstants.OK.equals(element.getName())) {
return response;
}
+
LOG.warn("Can not load last configuration. Operation failed.");
+ // FIXME: we should be throwing a DocumentedException here
throw new IllegalStateException("Can not load last configuration. Operation failed: "
+ XmlUtil.toString(response));
}
}
}
+ // FIXME: document this interface contract. Does it support RFC8528/RFC8542? How?
public static NormalizedNodeResult transformDOMSourceToNormalizedNode(final SchemaContext schemaContext,
final DOMSource value) throws XMLStreamException, URISyntaxException, IOException, SAXException {
final NormalizedNodeResult resultHolder = new NormalizedNodeResult();