KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > drftpd > master > queues > NukeLog


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * DrFTPD is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with DrFTPD; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package net.sf.drftpd.master.queues;
19
20 import java.io.FileOutputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26 import net.sf.drftpd.ObjectNotFoundException;
27 import net.sf.drftpd.event.NukeEvent;
28
29 import org.jdom.Element;
30 import org.jdom.output.XMLOutputter;
31
32 /**
33  * @author mog
34  *
35  * @version $Id: NukeLog.java,v 1.11 2004/05/12 00:45:09 mog Exp $
36  */

37 public class NukeLog {
38     ArrayList JavaDoc nukes = new ArrayList JavaDoc();
39     public NukeLog() {
40     }
41     
42     public NukeEvent get(String JavaDoc path) throws ObjectNotFoundException {
43         for (Iterator JavaDoc iter = nukes.iterator(); iter.hasNext();) {
44             NukeEvent nuke= (NukeEvent) iter.next();
45             if(nuke.getPath().equals(path)) return nuke;
46         }
47         throw new ObjectNotFoundException("No nukelog for: "+path);
48     }
49     
50     public void remove(String JavaDoc path) throws ObjectNotFoundException {
51         for (Iterator JavaDoc iter = nukes.iterator(); iter.hasNext();) {
52             NukeEvent nuke= (NukeEvent) iter.next();
53             if(nuke.getPath().equals(path)) {
54                 iter.remove();
55                 return;
56             }
57         }
58         throw new ObjectNotFoundException("No nukelog for: "+path);
59     }
60     
61     public void add(NukeEvent nuke) {
62         nukes.add(nuke);
63 // try {
64
// ObjOut out = new ObjOut(new FileWriter("nukelog.xml"));
65
// out.writeObject(this);
66
// } catch (IOException e) {
67
// logger.warn("", e);
68
// }
69
XMLOutputter outputter = new XMLOutputter(" ", true);
70         try {
71             outputter.output(this.toXML(), new FileOutputStream JavaDoc("nukelog.xml"));
72         } catch (IOException JavaDoc e) {
73             e.printStackTrace();
74         }
75     }
76     public List JavaDoc getAll() {
77         return nukes;
78     }
79     public Element toXML() {
80         Element element = new Element("nukes");
81         for (Iterator JavaDoc iter = getAll().iterator(); iter.hasNext();) {
82             NukeEvent nuke = (NukeEvent) iter.next();
83             element.addContent(nuke.toJDOM());
84         }
85         return element;
86     }
87 }
88
Popular Tags