X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fcore%2FCore.java;h=7c37808a3705400c93c617127cef30b773d68331;hb=c7561c631f4bbb94ee0ac9047e953ce56f1df8bb;hp=f617717868dd04faaf36b71b70e11c9f9fe4ac21;hpb=4cc40da06ea68d5e90b2bf340cd04220bc6a06cb;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/core/Core.java b/src/net/pterodactylus/jsite/core/Core.java index f617717..7c37808 100644 --- a/src/net/pterodactylus/jsite/core/Core.java +++ b/src/net/pterodactylus/jsite/core/Core.java @@ -25,7 +25,7 @@ import java.util.List; /** * The core of jSite. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> * @version $Id$ */ @@ -43,19 +43,13 @@ public class Core { /** List of currently connected nodes. */ private List connectedNodes = new ArrayList(); - /** - * Creates a new core. - */ - public Core() { - } - // // LISTENER MANAGEMENT // /** * Adds the given listener to the list of registered listeners. - * + * * @param coreListener * The listener to add */ @@ -65,7 +59,7 @@ public class Core { /** * Removes the given listener from the list of registered listeners. - * + * * @param coreListener * The listener to remove */ @@ -76,13 +70,41 @@ public class Core { /** * 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 fireLoadingProjectsFailed(String directory) { + private void fireSavingProjectsDone(String directory) { for (CoreListener coreListener: coreListeners) { - coreListener.loadingProjectsFailed(directory); + 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); } } @@ -95,13 +117,22 @@ public class Core { } } + /** + * 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() { @@ -110,7 +141,7 @@ public class Core { /** * Sets the project manager to use. - * + * * @param projectManager * The project manager to use */ @@ -120,7 +151,7 @@ public class Core { /** * Returns the list of all configured nodes. - * + * * @return All configured nodes */ public List getNodes() { @@ -129,7 +160,7 @@ public class Core { /** * Returns whether the core is currently connected to the given node. - * + * * @param node * The node to check * @return true if the core is currently connected to the @@ -150,18 +181,52 @@ public class Core { try { projectManager.load(); } catch (IOException ioe1) { - fireLoadingProjectsFailed(projectManager.getDirectory()); + 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 */ } }