Source Code Cross Referenced for AbstractCommand.java in  » Net » ColoradoFTP » com » coldcore » coloradoftp » command » impl » 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 » ColoradoFTP » com.coldcore.coloradoftp.command.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.coldcore.coloradoftp.command.impl;
002:
003:        import com.coldcore.coloradoftp.command.Command;
004:        import com.coldcore.coloradoftp.command.Reply;
005:        import com.coldcore.coloradoftp.connection.ControlConnection;
006:        import com.coldcore.coloradoftp.factory.ObjectFactory;
007:        import com.coldcore.coloradoftp.factory.ObjectName;
008:        import com.coldcore.coloradoftp.session.DataOpenerType;
009:        import com.coldcore.coloradoftp.session.LoginState;
010:        import com.coldcore.coloradoftp.session.Session;
011:        import com.coldcore.coloradoftp.session.SessionAttributeName;
012:
013:        import java.util.regex.Matcher;
014:        import java.util.regex.Pattern;
015:
016:        /**
017:         * @see com.coldcore.coloradoftp.command.Command
018:         *
019:         * Base class with few helper methods.
020:         */
021:        abstract public class AbstractCommand implements  Command {
022:
023:            protected String name;
024:            protected String parameter;
025:            protected ControlConnection controlConnection;
026:            private Reply reply; //Via getter only!
027:
028:            protected Reply getReply() {
029:                if (reply == null) {
030:                    reply = (Reply) ObjectFactory.getObject(ObjectName.REPLY);
031:                    reply.setCommand(this );
032:                }
033:                return reply;
034:            }
035:
036:            /** Test if user is loggen in.
037:             *  If user is not logged in this method fills the internal reply with a default error message.
038:             * @return TRUE if user is logged in, FALSE if user is not logged in
039:             */
040:            protected boolean testLogin() {
041:                Session session = getConnection().getSession();
042:                LoginState loginState = (LoginState) session
043:                        .getAttribute(SessionAttributeName.LOGIN_STATE);
044:                if (loginState != null)
045:                    return true;
046:                Reply reply = getReply();
047:                reply.setCode("530");
048:                reply.setText("Not logged in.");
049:                return false;
050:            }
051:
052:            /** Prepares everything for a new data connection.
053:             * If failed then this method fills the internal reply with a default error message.
054:             * It is recommended to call this method last because it is not easy to reverse changes this
055:             * method applies. 
056:             * @return TRUE if ready for a new data connection, FALSE otherwise
057:             */
058:            protected boolean prepareForDataConnection() {
059:                Session session = getConnection().getSession();
060:                DataOpenerType dtype = (DataOpenerType) session
061:                        .getAttribute(SessionAttributeName.DATA_OPENER_TYPE);
062:                if (dtype == null) {
063:                    Reply reply = getReply();
064:                    reply.setCode("425");
065:                    reply.setText("Can't open data connection.");
066:                    return false;
067:                }
068:
069:                //PASV is active only once as the connection is removed from the listeners set
070:                if (dtype == DataOpenerType.PASV) {
071:                    session
072:                            .removeAttribute(SessionAttributeName.DATA_OPENER_TYPE);
073:                    return true;
074:                }
075:
076:                //PORT must activate data connection initiator in the control connection
077:                if (dtype == DataOpenerType.PORT) {
078:
079:                    //Byte marker before "150" reply for a data connection initiator
080:                    session.setAttribute(
081:                            SessionAttributeName.BYTE_MARKER_150_REPLY,
082:                            controlConnection.getBytesWrote());
083:
084:                    controlConnection.getDataConnectionInitiator().activate();
085:                    return true;
086:                }
087:
088:                throw new RuntimeException(
089:                        "BUG: Unknown data opener type provided");
090:            }
091:
092:            /** Check syntax
093:             *  @param str String to check
094:             *  @param regexp Regular expression that defines syntax rules
095:             */
096:            protected boolean checkRegExp(String str, String regexp) {
097:                Pattern pattern = Pattern.compile(regexp);
098:                Matcher matcher = pattern.matcher(str);
099:                return matcher.matches();
100:            }
101:
102:            public boolean processInInterruptState() {
103:                return false;
104:            }
105:
106:            public boolean canClearInterruptState() {
107:                return false;
108:            }
109:
110:            public String getName() {
111:                if (name == null)
112:                    return null;
113:                return name.trim().toUpperCase(); //Return in uppercase
114:            }
115:
116:            public void setName(String name) {
117:                this .name = name;
118:            }
119:
120:            public String getParameter() {
121:                if (parameter == null)
122:                    return ""; //Do not return NULL
123:                return parameter.trim();
124:            }
125:
126:            public void setParameter(String parameter) {
127:                this .parameter = parameter;
128:            }
129:
130:            public void setConnection(ControlConnection connection) {
131:                controlConnection = connection;
132:            }
133:
134:            public ControlConnection getConnection() {
135:                return controlConnection;
136:            }
137:
138:            public Reply executeOnParent(Command parent) {
139:                return null;
140:            }
141:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.