KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > drftpd > tests > DummyBaseFtpConnection


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 org.drftpd.tests;
19
20 import java.io.FileInputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.PrintWriter JavaDoc;
23 import java.io.StringWriter JavaDoc;
24 import java.net.InetAddress JavaDoc;
25 import java.net.Socket JavaDoc;
26 import java.util.Collections JavaDoc;
27 import java.util.Properties JavaDoc;
28
29 import javax.net.ServerSocketFactory;
30 import javax.net.SocketFactory;
31
32 import net.sf.drftpd.Bytes;
33 import net.sf.drftpd.event.Event;
34 import net.sf.drftpd.master.BaseFtpConnection;
35 import net.sf.drftpd.master.ConnectionManager;
36 import net.sf.drftpd.master.FtpRequest;
37 import net.sf.drftpd.master.SlaveManagerImpl;
38 import net.sf.drftpd.master.command.CommandManager;
39 import net.sf.drftpd.master.command.plugins.DataConnectionHandler;
40 import net.sf.drftpd.master.config.FtpConfig;
41 import net.sf.drftpd.master.usermanager.NoSuchUserException;
42 import net.sf.drftpd.master.usermanager.User;
43 import net.sf.drftpd.master.usermanager.UserManager;
44 import net.sf.drftpd.remotefile.LinkedRemoteFile;
45 import net.sf.drftpd.remotefile.StaticRemoteFile;
46
47 /**
48  * @author mog
49  * @version $Id: DummyBaseFtpConnection.java,v 1.4 2004/05/31 02:47:21 mog Exp $
50  */

51 public class DummyBaseFtpConnection extends BaseFtpConnection {
52
53     private InetAddress JavaDoc _clientAddress;
54     private UserManager _userManager;
55     private DummyServerSocketFactory _serverSocketFactory;
56     private DummySocketFactory _socketFactory;
57     private StringWriter JavaDoc _out;
58     private FtpConfig config;
59
60     private DataConnectionHandler _dch;
61
62     public DummyBaseFtpConnection(DataConnectionHandler dch) {
63         _dch = dch;
64         _socketFactory = new DummySocketFactory();
65         _serverSocketFactory = new DummyServerSocketFactory(_socketFactory);
66         
67         currentDirectory = new LinkedRemoteFile(null);
68         currentDirectory.addFile(new StaticRemoteFile(Collections.EMPTY_LIST, "testfile", "drftpd", "drftpd", Bytes.parseBytes("10M"), System.currentTimeMillis()));
69         _out = new StringWriter JavaDoc();
70         out = new PrintWriter JavaDoc(_out);
71     }
72     public void setRequest(FtpRequest request) {
73         this.request = request;
74     }
75     /**
76      * @deprecated
77      */

78     protected void dispatchFtpEvent(Event event) {
79         throw new UnsupportedOperationException JavaDoc();
80     }
81
82     public InetAddress JavaDoc getClientAddress() {
83         if(_clientAddress == null) throw new NullPointerException JavaDoc();
84         return _clientAddress;
85     }
86     public void setClientAddress(InetAddress JavaDoc clientAddress) {
87         _clientAddress = clientAddress;
88     }
89     
90     public CommandManager getCommandManager() {
91         throw new UnsupportedOperationException JavaDoc();
92     }
93
94     public FtpConfig getConfig() {
95         if ( config == null ) {
96             Properties JavaDoc p = new Properties JavaDoc();
97             try {
98                 p.load(new FileInputStream JavaDoc("drftpd.conf"));
99             } catch (Exception JavaDoc e) {
100                 throw new RuntimeException JavaDoc(e);
101             }
102             try {
103                 config = new FtpConfig(p,"drftpd.conf", null);
104             } catch (IOException JavaDoc e) {
105                 throw new RuntimeException JavaDoc(e);
106             }
107         }
108         return config;
109     }
110
111     public ConnectionManager getConnectionManager() {
112         return _cm;
113     }
114
115     public Socket JavaDoc getControlSocket() {
116         return new DummySocket();
117     }
118
119     public DataConnectionHandler getDataConnectionHandler() {
120         return _dch;
121     }
122
123     public char getDirection() {
124         throw new UnsupportedOperationException JavaDoc();
125
126     }
127
128     public long getLastActive() {
129         throw new UnsupportedOperationException JavaDoc();
130
131     }
132
133     public SlaveManagerImpl getSlaveManager() {
134         throw new UnsupportedOperationException JavaDoc();
135
136     }
137
138     public char getTransferDirection() {
139         throw new UnsupportedOperationException JavaDoc();
140     }
141
142     public User getUser() throws NoSuchUserException {
143         throw new UnsupportedOperationException JavaDoc();
144     }
145
146     public void setUserManager(UserManager um) {
147         _userManager = um;
148     }
149
150     /* (non-Javadoc)
151      * @see net.sf.drftpd.master.BaseFtpConnection#getUserNull()
152      */

153     public User getUserNull() {
154         return super.getUserNull();
155     }
156
157     protected boolean hasPermission(FtpRequest request) {
158         throw new UnsupportedOperationException JavaDoc();
159     }
160
161     public boolean isAuthenticated() {
162         throw new UnsupportedOperationException JavaDoc();
163     }
164
165     public boolean isExecuting() {
166         throw new UnsupportedOperationException JavaDoc();
167     }
168
169     /**
170      * @deprecated
171      */

172     public void reset() {
173         throw new UnsupportedOperationException JavaDoc();
174     }
175
176     public void resetState() {
177     }
178
179     /* (non-Javadoc)
180      * @see java.lang.Runnable#run()
181      */

182     public void run() {
183         throw new UnsupportedOperationException JavaDoc();
184     }
185
186     /* (non-Javadoc)
187      * @see net.sf.drftpd.master.BaseFtpConnection#service(net.sf.drftpd.master.FtpRequest, java.io.PrintWriter)
188      */

189     public void service(FtpRequest request, PrintWriter JavaDoc out)
190         throws IOException JavaDoc {
191         throw new UnsupportedOperationException JavaDoc();
192     }
193
194     /* (non-Javadoc)
195      * @see net.sf.drftpd.master.BaseFtpConnection#setControlSocket(java.net.Socket)
196      */

197     public void setControlSocket(Socket JavaDoc socket) {
198         throw new UnsupportedOperationException JavaDoc();
199     }
200
201     /* (non-Javadoc)
202      * @see net.sf.drftpd.master.BaseFtpConnection#setCurrentDirectory(net.sf.drftpd.remotefile.LinkedRemoteFile)
203      */

204     public void setCurrentDirectory(LinkedRemoteFile file) {
205         throw new UnsupportedOperationException JavaDoc();
206     }
207
208     public void setUser(User user) {
209         super.setUser(user);
210     }
211
212     /* (non-Javadoc)
213      * @see net.sf.drftpd.master.BaseFtpConnection#start()
214      */

215     public void start() {
216         throw new UnsupportedOperationException JavaDoc();
217     }
218
219     /* (non-Javadoc)
220      * @see net.sf.drftpd.master.BaseFtpConnection#status()
221      */

222     public String JavaDoc status() {
223         return "dummy status string";
224     }
225
226     /* (non-Javadoc)
227      * @see net.sf.drftpd.master.BaseFtpConnection#stop()
228      */

229     public void stop() {
230         throw new UnsupportedOperationException JavaDoc();
231     }
232
233     /* (non-Javadoc)
234      * @see net.sf.drftpd.master.BaseFtpConnection#stop(java.lang.String)
235      */

236     public void stop(String JavaDoc message) {
237         throw new UnsupportedOperationException JavaDoc();
238     }
239
240     /* (non-Javadoc)
241      * @see java.lang.Object#toString()
242      */

243     public String JavaDoc toString() {
244         throw new UnsupportedOperationException JavaDoc();
245     }
246
247     /* (non-Javadoc)
248      * @see java.lang.Object#hashCode()
249      */

250     public int hashCode() {
251         throw new UnsupportedOperationException JavaDoc();
252     }
253
254     /* (non-Javadoc)
255      * @see java.lang.Object#equals(java.lang.Object)
256      */

257     public boolean equals(Object JavaDoc obj) {
258         throw new UnsupportedOperationException JavaDoc();
259     }
260
261     protected Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
262         throw new UnsupportedOperationException JavaDoc();
263     }
264
265     public ServerSocketFactory getServerSocketFactory() {
266         return _serverSocketFactory;
267     }
268     public DummyServerSocketFactory getDummySSF() {
269         return _serverSocketFactory;
270     }
271
272     public StringWriter JavaDoc getDummyOut() {
273         return _out;
274     }
275
276     public SocketFactory getSocketFactory() {
277         return _socketFactory;
278     }
279
280     public void setConnectionManager(ConnectionManager manager) {
281         _cm = manager;
282     }
283
284 }
285
Popular Tags