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>();
53 // LISTENER MANAGEMENT
57 * Adds the given listener to the list of registered listeners.
62 public void addCoreListener(CoreListener coreListener) {
63 coreListeners.add(coreListener);
67 * Removes the given listener from the list of registered listeners.
70 * The listener to remove
72 public void removeCoreListener(CoreListener coreListener) {
73 coreListeners.remove(coreListener);
77 * Notifies all core listeners that loading the projects from the given
78 * directory has failed.
81 * The directory the projects were tried to load from
83 private void fireLoadingProjectsFailed(String directory) {
84 for (CoreListener coreListener: coreListeners) {
85 coreListener.loadingProjectsFailed(directory);
90 * Notifies all core listeners that the core has loaded and is ready to run.
92 private void fireCoreLoaded() {
93 for (CoreListener coreListener: coreListeners) {
94 coreListener.coreLoaded();
103 * Returns the project manager.
105 * @return The project manager
107 public ProjectManager getProjectManager() {
108 return projectManager;
112 * Sets the project manager to use.
114 * @param projectManager
115 * The project manager to use
117 public void setProjectManager(ProjectManager projectManager) {
118 this.projectManager = projectManager;
122 * Returns the list of all configured nodes.
124 * @return All configured nodes
126 public List<Node> getNodes() {
127 return configuredNodes;
131 * Returns whether the core is currently connected to the given node.
135 * @return <code>true</code> if the core is currently connected to the
136 * node, <code>false</code> otherwise
138 public boolean isNodeConnected(Node node) {
139 return connectedNodes.contains(node);
149 public void start() {
151 projectManager.load();
152 } catch (IOException ioe1) {
153 fireLoadingProjectsFailed(projectManager.getDirectory());
159 * Connects to the given node.
162 * The node to connect to
164 public void connectToNode(Node node) {