package net.pterodactylus.jsite.core;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* The core of jSite.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
/** The core listeners. */
private final List<CoreListener> coreListeners = new ArrayList<CoreListener>();
+ /** The project manager. */
+ private ProjectManager projectManager;
+
/** The node list. */
- private List<Node> nodeList = new ArrayList<Node>();
+ private List<Node> configuredNodes = new ArrayList<Node>();
- /**
- * Creates a new core.
- */
- public Core() {
- }
+ /** List of currently connected nodes. */
+ private List<Node> connectedNodes = new ArrayList<Node>();
//
// LISTENER MANAGEMENT
/**
* Adds the given listener to the list of registered listeners.
- *
+ *
* @param coreListener
* The listener to add
*/
/**
* Removes the given listener from the list of registered listeners.
- *
+ *
* @param coreListener
* The listener to remove
*/
}
/**
+ * Notifies all core listeners that loading the projects from the given
+ * directory has failed.
+ *
+ * @param directory
+ * The directory the projects were tried to load from
+ * @param throwable
+ * The exception that occured when loading projects
+ */
+ private void fireLoadingProjectsFailed(String directory, Throwable throwable) {
+ for (CoreListener coreListener: coreListeners) {
+ coreListener.loadingProjectsFailed(directory, throwable);
+ }
+ }
+
+ /**
+ * Notifies all listeners that the projects were successfully saved.
+ *
+ * @param directory
+ * The directory the projects were saved to
+ */
+ private void fireSavingProjectsDone(String directory) {
+ for (CoreListener coreListener: coreListeners) {
+ coreListener.savingProjectsDone(directory);
+ }
+ }
+
+ /**
+ * Notifies all listeners that the projects could not be saved.
+ *
+ * @param directory
+ * The directory the projects were to be saved to
+ * @param throwable
+ * The exception that occured when saving the projects
+ */
+ private void fireSavingProjectsFailed(String directory, Throwable throwable) {
+ for (CoreListener coreListener: coreListeners) {
+ coreListener.savingProjectsFailed(directory, throwable);
+ }
+ }
+
+ /**
* Notifies all core listeners that the core has loaded and is ready to run.
*/
private void fireCoreLoaded() {
}
}
+ /**
+ * Notifies all listeners that the core was stopped.
+ */
+ private void fireCoreStopped() {
+ for (CoreListener coreListener: coreListeners) {
+ coreListener.coreStopped();
+ }
+ }
+
//
// ACCESSORS
//
/**
+ * Returns the project manager.
+ *
+ * @return The project manager
+ */
+ public ProjectManager getProjectManager() {
+ return projectManager;
+ }
+
+ /**
+ * Sets the project manager to use.
+ *
+ * @param projectManager
+ * The project manager to use
+ */
+ public void setProjectManager(ProjectManager projectManager) {
+ this.projectManager = projectManager;
+ }
+
+ /**
* Returns the list of all configured nodes.
- *
+ *
* @return All configured nodes
*/
- public List<Node> getNodeList() {
- return nodeList;
+ public List<Node> getNodes() {
+ return configuredNodes;
+ }
+
+ /**
+ * Returns whether the core is currently connected to the given node.
+ *
+ * @param node
+ * The node to check
+ * @return <code>true</code> if the core is currently connected to the
+ * node, <code>false</code> otherwise
+ */
+ public boolean isNodeConnected(Node node) {
+ return connectedNodes.contains(node);
}
//
* Starts the core.
*/
public void start() {
+ try {
+ projectManager.load();
+ } catch (IOException ioe1) {
+ fireLoadingProjectsFailed(projectManager.getDirectory(), ioe1);
+ }
fireCoreLoaded();
}
/**
+ * Stops the core.
+ */
+ public void stop() {
+ try {
+ projectManager.save();
+ fireSavingProjectsDone(projectManager.getDirectory());
+ } catch (IOException ioe1) {
+ fireSavingProjectsFailed(projectManager.getDirectory(), ioe1);
+ }
+ fireCoreStopped();
+ }
+
+ /**
* Connects to the given node.
- *
+ *
* @param node
* The node to connect to
*/
public void connectToNode(Node node) {
+ /* TODO */
+ }
+
+ //
+ // PRIVATE METHODS
+ //
+
+ /**
+ * Loads the configuration.
+ */
+ @SuppressWarnings("unused")
+ private void loadConfig() {
+ /* TODO */
+ }
+
+ /**
+ * Saves the configuration.
+ */
+ @SuppressWarnings("unused")
+ private void saveConfig() {
+ /* TODO */
}
}