Source Code Cross Referenced for CommandManagerFactory.java in  » Net » DrFTPD » net » sf » drftpd » master » command » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » DrFTPD » net.sf.drftpd.master.command 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of DrFTPD, Distributed FTP Daemon.
003:         *
004:         * DrFTPD is free software; you can redistribute it and/or modify
005:         * it under the terms of the GNU General Public License as published by
006:         * the Free Software Foundation; either version 2 of the License, or
007:         * (at your option) any later version.
008:         *
009:         * DrFTPD is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         * GNU General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU General Public License
015:         * along with DrFTPD; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:        package net.sf.drftpd.master.command;
019:
020:        import net.sf.drftpd.FatalException;
021:        import net.sf.drftpd.FileExistsException;
022:        import net.sf.drftpd.ObjectNotFoundException;
023:        import net.sf.drftpd.master.BaseFtpConnection;
024:
025:        import org.drftpd.commands.CommandHandler;
026:        import org.drftpd.commands.CommandHandlerFactory;
027:        import org.drftpd.master.ConnectionManager;
028:
029:        import java.io.FileInputStream;
030:        import java.io.IOException;
031:
032:        import java.util.Hashtable;
033:        import java.util.Iterator;
034:        import java.util.Map;
035:        import java.util.Properties;
036:
037:        /**
038:         * @author mog
039:         *
040:         * Istantiates the CommandManager instances that holds per-connection CommandHandlers.
041:         * @version $Id: CommandManagerFactory.java 1562 2007-01-05 12:37:07Z zubov $
042:         */
043:        public class CommandManagerFactory {
044:            private ConnectionManager _connMgr;
045:
046:            /**
047:             * Class => CommandHandlerFactory
048:             */
049:            private Hashtable _hnds;
050:
051:            /**
052:             * String=> Class
053:             */
054:            private Hashtable _cmds;
055:
056:            public CommandManagerFactory(ConnectionManager connMgr) {
057:                _connMgr = connMgr;
058:
059:                //		Login login = new Login();
060:                //		handlers = new Hashtable();
061:                //		handlers.put("USER", login);
062:                //		handlers.put("PASS", login);
063:                //		handlers = new ArrayList();
064:                //		handlers.add(new Login());
065:                //		handlers.add(new Dir());
066:                //		handlers.add(new List());
067:                //		handlers.add(new DataConnectionHandler());
068:                //		handlers.add(new Search());
069:                //		handlers.add(new UserManagement());
070:                //_conn = conn;
071:                //login.init(conn);
072:                //Hashtable handlers = new Hashtable();
073:                load();
074:            }
075:
076:            public void reload() {
077:                unload();
078:                load();
079:            }
080:
081:            private void unload() {
082:                for (Iterator iter = _hnds.values().iterator(); iter.hasNext();) {
083:                    Object o = iter.next();
084:
085:                    try {
086:                        CommandHandlerFactory c = ((CommandHandlerFactory) o);
087:                        c.unload();
088:                    } catch (ClassCastException e) {
089:                        throw e;
090:                    }
091:                }
092:            }
093:
094:            private void load() {
095:                Hashtable cmds = new Hashtable();
096:                Hashtable hnds = new Hashtable();
097:                Properties props = new Properties();
098:                FileInputStream stream = null;
099:                try {
100:                    stream = new FileInputStream("conf/commandhandlers.conf");
101:                    props.load(stream);
102:
103:                    //		URLClassLoader classLoader;
104:                    //		try {
105:                    //			classLoader =
106:                    //				URLClassLoader.newInstance(
107:                    //					new URL[] {
108:                    //						new URL("file:classes/"),
109:                    //						new URL("file:lib/log4j-1.2.8.jar")});
110:                    //		} catch (MalformedURLException e1) {
111:                    //			throw new RuntimeException(e1);
112:                    //		}
113:                    for (Iterator iter = props.entrySet().iterator(); iter
114:                            .hasNext();) {
115:                        try {
116:                            Map.Entry entry = (Map.Entry) iter.next();
117:
118:                            Class hndclass = Class.forName((String) entry
119:                                    .getValue());
120:
121:                            //				Class hndclass =
122:                            //					Class.forName(
123:                            //						(String) entry.getValue(),
124:                            //						false,
125:                            //						classLoader);
126:                            CommandHandlerFactory hndinstance = (CommandHandlerFactory) hnds
127:                                    .get(hndclass);
128:
129:                            if (hndinstance == null) {
130:                                hndinstance = (CommandHandlerFactory) hndclass
131:                                        .newInstance();
132:                                hndinstance.load(this );
133:                                hnds.put(hndclass, hndinstance);
134:                            }
135:
136:                            String cmd = (String) entry.getKey();
137:
138:                            if (cmds.containsKey(cmd)) {
139:                                throw new FileExistsException(cmd
140:                                        + " is already mapped");
141:                            }
142:
143:                            cmds.put(cmd, hndclass);
144:                        } catch (Exception e) {
145:                            throw new FatalException("", e);
146:                        }
147:                    }
148:
149:                    _cmds = cmds;
150:                    _hnds = hnds;
151:                } catch (IOException e) {
152:                    throw new FatalException(
153:                            "Error loading commandhandlers.conf", e);
154:                } finally {
155:                    if (stream != null) {
156:                        try {
157:                            stream.close();
158:                        } catch (IOException e) {
159:                        }
160:                    }
161:                }
162:            }
163:
164:            public CommandManager initialize(BaseFtpConnection conn) {
165:                CommandManager mgr = new CommandManager(conn, this );
166:
167:                return mgr;
168:            }
169:
170:            /**
171:             * Class => CommandHandler
172:             */
173:            public Hashtable getHandlersMap() {
174:                return _hnds;
175:            }
176:
177:            /**
178:             * String=> Class
179:             */
180:            public Hashtable getCommandsMap() {
181:                return _cmds;
182:            }
183:
184:            public CommandHandler getHandler(Class clazz)
185:                    throws ObjectNotFoundException {
186:                CommandHandler ret = (CommandHandler) _hnds.get(clazz);
187:
188:                if (ret == null) {
189:                    throw new ObjectNotFoundException();
190:                }
191:
192:                return ret;
193:
194:                //		for (Iterator iter = hnds.iterator(); iter.hasNext();) {
195:                //			CommandHandler handler = (CommandHandler) iter.next();
196:                //			if (handler.getClass().equals(clazz))
197:                //				return handler;
198:                //		}
199:                //		throw new ObjectNotFoundException();
200:            }
201:
202:            /**
203:             *
204:             */
205:            public ConnectionManager getConnectionManager() {
206:                return _connMgr;
207:            }
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.