Switch initial config files format to xml and add autodetect adapter for config persi...
[controller.git] / opendaylight / config / config-persister-directory-xml-adapter / src / main / java / org / opendaylight / controller / config / persist / storage / directory / xml / XmlDirectoryPersister.java
index f6f6de9fd5d8370a11a29233c74dca1a20c4ba2e..0ca47edf0e5540cef5db8c2bcbb8f0d8f9dde611 100644 (file)
@@ -63,17 +63,21 @@ public class XmlDirectoryPersister implements Persister {
 
     private ConfigSnapshotHolder fromXmlSnapshot(File file) {
         try {
-            JAXBContext jaxbContext = JAXBContext.newInstance(ConfigSnapshot.class);
-            Unmarshaller um = jaxbContext.createUnmarshaller();
-
-            return asHolder((ConfigSnapshot) um.unmarshal(file));
+            return loadLastConfig(file);
         } catch (JAXBException e) {
             logger.warn("Unable to restore configuration snapshot from {}", file, e);
             throw new IllegalStateException("Unable to restore configuration snapshot from " + file, e);
         }
     }
 
-    private ConfigSnapshotHolder asHolder(final ConfigSnapshot unmarshalled) {
+    public static ConfigSnapshotHolder loadLastConfig(File file) throws JAXBException {
+        JAXBContext jaxbContext = JAXBContext.newInstance(ConfigSnapshot.class);
+        Unmarshaller um = jaxbContext.createUnmarshaller();
+
+        return asHolder((ConfigSnapshot) um.unmarshal(file));
+    }
+
+    private static ConfigSnapshotHolder asHolder(final ConfigSnapshot unmarshalled) {
         return new ConfigSnapshotHolder() {
             @Override
             public String getConfigSnapshot() {