/**
* The core of jSite.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
/** List of currently connected nodes. */
private List<Node> connectedNodes = new ArrayList<Node>();
- /**
- * Creates a new core.
- */
- public Core() {
- }
-
//
// 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 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);
}
}
}
}
+ /**
+ * 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() {
/**
* Sets the project manager to use.
- *
+ *
* @param projectManager
* The project manager to use
*/
/**
* Returns the list of all configured nodes.
- *
+ *
* @return All configured nodes
*/
public List<Node> getNodes() {
/**
* 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
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 */
}
}