3 * Copyright © 2008 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package net.pterodactylus.jsite.core;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.List;
29 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
34 /** The core listeners. */
35 private final List<CoreListener> coreListeners = new ArrayList<CoreListener>();
37 /** The project manager. */
38 private ProjectManager projectManager;
41 private List<Node> configuredNodes = new ArrayList<Node>();
43 /** List of currently connected nodes. */
44 private List<Node> connectedNodes = new ArrayList<Node>();
47 // LISTENER MANAGEMENT
51 * Adds the given listener to the list of registered listeners.
56 public void addCoreListener(CoreListener coreListener) {
57 coreListeners.add(coreListener);
61 * Removes the given listener from the list of registered listeners.
64 * The listener to remove
66 public void removeCoreListener(CoreListener coreListener) {
67 coreListeners.remove(coreListener);
71 * Notifies all core listeners that loading the projects from the given
72 * directory has failed.
75 * The directory the projects were tried to load from
77 * The exception that occured when loading projects
79 private void fireLoadingProjectsFailed(String directory, Throwable throwable) {
80 for (CoreListener coreListener: coreListeners) {
81 coreListener.loadingProjectsFailed(directory, throwable);
86 * Notifies all listeners that the projects were successfully saved.
89 * The directory the projects were saved to
91 private void fireSavingProjectsDone(String directory) {
92 for (CoreListener coreListener: coreListeners) {
93 coreListener.savingProjectsDone(directory);
98 * Notifies all listeners that the projects could not be saved.
101 * The directory the projects were to be saved to
103 * The exception that occured when saving the projects
105 private void fireSavingProjectsFailed(String directory, Throwable throwable) {
106 for (CoreListener coreListener: coreListeners) {
107 coreListener.savingProjectsFailed(directory, throwable);
112 * Notifies all core listeners that the core has loaded and is ready to run.
114 private void fireCoreLoaded() {
115 for (CoreListener coreListener: coreListeners) {
116 coreListener.coreLoaded();
121 * Notifies all listeners that the core was stopped.
123 private void fireCoreStopped() {
124 for (CoreListener coreListener: coreListeners) {
125 coreListener.coreStopped();
134 * Returns the project manager.
136 * @return The project manager
138 public ProjectManager getProjectManager() {
139 return projectManager;
143 * Sets the project manager to use.
145 * @param projectManager
146 * The project manager to use
148 public void setProjectManager(ProjectManager projectManager) {
149 this.projectManager = projectManager;
153 * Returns the list of all configured nodes.
155 * @return All configured nodes
157 public List<Node> getNodes() {
158 return configuredNodes;
162 * Returns whether the core is currently connected to the given node.
166 * @return <code>true</code> if the core is currently connected to the
167 * node, <code>false</code> otherwise
169 public boolean isNodeConnected(Node node) {
170 return connectedNodes.contains(node);
180 public void start() {
182 projectManager.load();
183 } catch (IOException ioe1) {
184 fireLoadingProjectsFailed(projectManager.getDirectory(), ioe1);
194 projectManager.save();
195 fireSavingProjectsDone(projectManager.getDirectory());
196 } catch (IOException ioe1) {
197 fireSavingProjectsFailed(projectManager.getDirectory(), ioe1);
203 * Connects to the given node.
206 * The node to connect to
208 public void connectToNode(Node node) {
217 * Loads the configuration.
219 @SuppressWarnings("unused")
220 private void loadConfig() {
225 * Saves the configuration.
227 @SuppressWarnings("unused")
228 private void saveConfig() {