01: /*
02: * This file is part of DrFTPD, Distributed FTP Daemon.
03: *
04: * DrFTPD is free software; you can redistribute it and/or modify it under the
05: * terms of the GNU General Public License as published by the Free Software
06: * Foundation; either version 2 of the License, or (at your option) any later
07: * version.
08: *
09: * DrFTPD is distributed in the hope that it will be useful, but WITHOUT ANY
10: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11: * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12: *
13: * You should have received a copy of the GNU General Public License along with
14: * DrFTPD; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
15: * Suite 330, Boston, MA 02111-1307 USA
16: */
17: package org.drftpd.plugins;
18:
19: import java.io.File;
20: import java.net.URL;
21: import java.net.URLClassLoader;
22: import java.util.ArrayList;
23:
24: import net.sf.drftpd.event.Event;
25: import net.sf.drftpd.event.FtpListener;
26:
27: import org.apache.log4j.Logger;
28: import org.drftpd.GlobalContext;
29:
30: /**
31: * @author mog
32: * @version $Id$
33: */
34: public class DelegatingArchive extends FtpListener {
35: private static final Logger logger = Logger
36: .getLogger(DelegatingArchive.class);
37: private URLClassLoader _cl;
38: private ArrayList<FtpListener> _delegates;
39:
40: public DelegatingArchive() {
41: }
42:
43: public void actionPerformed(Event event) {
44: if (event.getCommand().equals("RELOAD")) {
45: unload();
46: init(getGlobalContext());
47: return;
48: }
49: for (FtpListener delegate : _delegates) {
50: try {
51: delegate.actionPerformed(event);
52: } catch (Throwable t) {
53: logger.error("Throwable from event handler", t);
54: }
55: }
56: }
57:
58: public void init(GlobalContext gctx) {
59: super .init(gctx);
60: init2(gctx);
61: }
62:
63: public void init2(GlobalContext gctx) {
64: _delegates = new ArrayList<FtpListener>();
65: try {
66: _cl = new URLClassLoader(new URL[] { new File(
67: "classes-archive").toURL() });
68: _delegates.add((FtpListener) _cl.loadClass(
69: "org.drftpd.plugins.Archive").newInstance());
70: _delegates.add((FtpListener) _cl.loadClass(
71: "org.drftpd.plugins.Mirror").newInstance());
72: } catch (Exception e) {
73: throw new RuntimeException(e);
74: }
75: for (FtpListener delegate : _delegates) {
76: try {
77: delegate.init(gctx);
78: } catch (Throwable t) {
79: logger.error("Throwable from init", t);
80: }
81: }
82: }
83:
84: public void unload() {
85: for (FtpListener delegate : _delegates) {
86: delegate.unload();
87: }
88: }
89: }
|