String envFilePath = config.getProperty("KEY_ROOM_XML_PATH");
File envFile = new File(Info.PATH_WORKDIR + "/data/furn/" + envFilePath);
File folder = envFile.getParentFile();
if (!folder.exists()) {
throw new FreedomoticException(
"Folder " + folder + " do not exists. Cannot load default "
+ "environment from " + envFile.getAbsolutePath().toString());
} else if (!folder.isDirectory()) {
throw new FreedomoticException(
"Environment folder " + folder.getAbsolutePath()
+ " is supposed to be a directory");
}
try {
//EnvironmentPersistence.loadEnvironmentsFromDir(folder, false);
EnvironmentDAO loader = environmentDaoFactory.create(folder);
Collection<Environment> loaded = loader.load();
if (loaded == null) {
throw new IllegalStateException("Object data cannot be null at this stage");
}
for (Environment env : loaded) {
EnvironmentLogic logic = INJECTOR.getInstance(EnvironmentLogic.class);
logic.setPojo(env);
logic.setSource(new File(folder + "/" + env.getUUID() + ".xenv"));
EnvironmentPersistence.add(logic, false);
}
//now load related objects
EnvObjectPersistence.loadObjects(new File(folder + "/data/obj"), false);
} catch (DaoLayerException e) {
throw new FreedomoticException(e.getMessage(), e);
}
}