Don’t check node in project, always use given node.
[jSite2.git] / src / net / pterodactylus / jsite / core / InsertManager.java
1 /*
2  * jSite2 - InsertManager.java - Copyright © 2008 David Roden
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18
19 package net.pterodactylus.jsite.core;
20
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25
26 import net.pterodactylus.util.logging.Logging;
27
28 /**
29  * Manages all currently running and past inserts.
30  *
31  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
32  */
33 public class InsertManager {
34
35         /** Logger. */
36         private static final Logger logger = Logging.getLogger(InsertManager.class.getName());
37
38         /** The insert listener support. */
39         private final InsertListenerSupport insertListenerSupport = new InsertListenerSupport();
40
41         /** Mapping from insert IDs to inserts. */
42         private final Map<String, Insert> inserts = new HashMap<String, Insert>();
43
44         //
45         // EVENT MANAGEMENT
46         //
47
48         /**
49          * Adds an insert listener to the list of insert listeners.
50          *
51          * @param insertListener
52          *            The insert listener to add
53          */
54         public void addInsertListener(InsertListener insertListener) {
55                 logger.log(Level.FINEST, "addInsertListener(insertListener=" + insertListener + ")");
56                 insertListenerSupport.addListener(insertListener);
57         }
58
59         /**
60          * Removes an insert listener from the list of insert listeners.
61          *
62          * @param insertListener
63          *            The insert listener to remove
64          */
65         public void removeInsertListener(InsertListener insertListener) {
66                 logger.log(Level.FINEST, "removeInsertListener(insertListener=" + insertListener + ")");
67                 insertListenerSupport.removeListener(insertListener);
68         }
69
70         //
71         // ACTIONS
72         //
73
74         /**
75          * Starts to insert the given project. The insert will be made to the node
76          * stored in the project, and if no node is specified in the project, the
77          * given node will be used.
78          *
79          * @param project
80          *            The project to insert
81          * @param node
82          *            The node to insert the project to if the project does not
83          *            specify a node
84          */
85         public void insertProject(Project project, Node node) {
86                 logger.log(Level.FINEST, "insertProject(project=" + project + ",node=" + node + ")");
87                 String insertId = "insert-" + project.getId();
88                 Insert newInsert = new Insert(project, node, insertId);
89                 inserts.put(insertId, newInsert);
90                 saveConfiguration();
91                 insertListenerSupport.fireInsertAdded(newInsert);
92                 /* TODO - start insert */
93         }
94
95         /**
96          * Starts the insert manager.
97          */
98         public void start() {
99                 logger.log(Level.FINEST, "start()");
100                 loadConfiguration();
101         }
102
103         //
104         // PRIVATE METHODS
105         //
106
107         /**
108          * Loads the configuration.
109          */
110         private void loadConfiguration() {
111                 logger.log(Level.FINEST, "loadConfiguration()");
112         }
113
114         /**
115          * Saves the configuration.
116          */
117         private void saveConfiguration() {
118                 logger.log(Level.FINEST, "saveConfiguration()");
119         }
120
121 }