add project manager
[jSite2.git] / src / net / pterodactylus / jsite / core / Core.java
index c2072cb..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,6 +34,9 @@ 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> configuredNodes = new ArrayList<Node>();
 
@@ -70,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() {
@@ -83,6 +100,25 @@ 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
@@ -111,6 +147,11 @@ public class Core {
         * Starts the core.
         */
        public void start() {
+               try {
+                       projectManager.load();
+               } catch (IOException ioe1) {
+                       fireLoadingProjectsFailed(projectManager.getDirectory());
+               }
                fireCoreLoaded();
        }