001/* 002 * Syncany, www.syncany.org 003 * Copyright (C) 2011-2016 Philipp C. Heckel <philipp.heckel@gmail.com> 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU General Public License as published by 007 * the Free Software Foundation, either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018package org.syncany.config.to; 019 020import java.io.File; 021import java.util.ArrayList; 022 023import org.simpleframework.xml.Element; 024import org.simpleframework.xml.ElementList; 025import org.simpleframework.xml.Root; 026import org.simpleframework.xml.core.Persister; 027import org.syncany.config.ConfigException; 028 029/** 030 * This class is used to configure the daemon, in particular, its web server, 031 * the managed folders and the web server / API users. 032 * 033 * <p>It uses the Simple framework for XML serialization, and its corresponding 034 * annotation-based configuration. 035 * 036 * @see WebServerTO 037 * @see FolderTO 038 * @see PortTO 039 * @see <a href="http://simple.sourceforge.net/">Simple framework</a> 040 * @author Philipp C. Heckel (philipp.heckel@gmail.com) 041 */ 042@Root(name = "daemon", strict = false) 043public class DaemonConfigTO { 044 @Element(name = "webServer", required = false) 045 private WebServerTO webServer = new WebServerTO(); 046 047 @ElementList(name = "folders", entry = "folder", required = true) 048 private ArrayList<FolderTO> folders = new ArrayList<FolderTO>(); 049 050 @ElementList(name = "users", entry = "user", required = false) 051 private ArrayList<UserTO> users = new ArrayList<UserTO>(); 052 053 private PortTO portTO; // This is generated dynamically by the daemon. It should't be in the XML. 054 055 public static DaemonConfigTO load(File file) throws ConfigException { 056 try { 057 return new Persister().read(DaemonConfigTO.class, file); 058 } 059 catch (Exception e) { 060 throw new ConfigException("Config file does not exist or is invalid: " + file, e); 061 } 062 } 063 064 public void save(File file) throws ConfigException { 065 try { 066 new Persister().write(this, file); 067 } 068 catch (Exception e) { 069 throw new ConfigException("Config could not be written: " + file, e); 070 } 071 } 072 073 public ArrayList<FolderTO> getFolders() { 074 return folders; 075 } 076 077 public void setFolders(ArrayList<FolderTO> folders) { 078 this.folders = folders; 079 } 080 081 public ArrayList<UserTO> getUsers() { 082 return users; 083 } 084 085 public void setUsers(ArrayList<UserTO> users) { 086 this.users = users; 087 } 088 089 public WebServerTO getWebServer() { 090 return webServer; 091 } 092 093 public void setWebServer(WebServerTO webServer) { 094 this.webServer = webServer; 095 } 096 097 public PortTO getPortTO() { 098 return portTO; 099 } 100 101 public void setPortTO(PortTO portTO) { 102 this.portTO = portTO; 103 } 104}