Initial code drop of netconf protocol implementation
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / util / NetconfUtil.java
1 package org.opendaylight.controller.netconf.impl.util;
2
3 import java.io.*;
4
5 import org.opendaylight.controller.netconf.api.NetconfMessage;
6 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9 import org.w3c.dom.Document;
10 import org.xml.sax.SAXException;
11
12 // TODO purge nulls
13 public class NetconfUtil {
14
15     private static final Logger logger = LoggerFactory.getLogger(NetconfUtil.class);
16
17     public static NetconfMessage createMessage(final File f) {
18         try {
19             return createMessage(new FileInputStream(f));
20         } catch (final FileNotFoundException e) {
21             logger.warn("File {} not found.", f, e);
22         }
23         return null;
24     }
25
26     public static NetconfMessage createMessage(final InputStream is) {
27         Document doc = null;
28         try {
29             doc = XmlUtil.readXmlToDocument(is);
30         } catch (final IOException e) {
31             logger.warn("Error ocurred while parsing stream.", e);
32         } catch (final SAXException e) {
33             logger.warn("Error ocurred while final parsing stream.", e);
34         }
35         return (doc == null) ? null : new NetconfMessage(doc);
36     }
37 }