add TestDDAResponse
[jSite2.git] / src / net / pterodactylus / jsite / core / Core.java
index 3f00678..f617717 100644 (file)
@@ -19,6 +19,7 @@
 
 package net.pterodactylus.jsite.core;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -33,8 +34,14 @@ public class Core {
        /** 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>();
+
+       /** List of currently connected nodes. */
+       private List<Node> connectedNodes = new ArrayList<Node>();
 
        /**
         * Creates a new core.
@@ -67,6 +74,19 @@ 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
+        */
+       private void fireLoadingProjectsFailed(String directory) {
+               for (CoreListener coreListener: coreListeners) {
+                       coreListener.loadingProjectsFailed(directory);
+               }
+       }
+
+       /**
         * Notifies all core listeners that the core has loaded and is ready to run.
         */
        private void fireCoreLoaded() {
@@ -80,12 +100,43 @@ public class Core {
        //
 
        /**
+        * 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);
        }
 
        //
@@ -96,6 +147,11 @@ public class Core {
         * Starts the core.
         */
        public void start() {
+               try {
+                       projectManager.load();
+               } catch (IOException ioe1) {
+                       fireLoadingProjectsFailed(projectManager.getDirectory());
+               }
                fireCoreLoaded();
        }