Source Code Cross Referenced for UpdateProtocol.java in  » Net » customdns » CustomDNS » 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 » customdns » CustomDNS 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package CustomDNS;
002:
003:        import java.io.Writer;
004:        import java.io.IOException;
005:
006:        /*************************************************************************
007:         *  Constants and utility functions used by our update protocol.
008:         *************************************************************************
009:         *  @see CustomDNS.UpdateServer
010:         *  @see CustomDNS.UpdateClient
011:         */
012:
013:        public class UpdateProtocol {
014:
015:            /** The default port for the update protocol. */
016:            public static final short DEFAULT_PORT = (short) 5768;
017:
018:            /** The command completed successfully. */
019:            public static final int STATUS_OK = 200;
020:            /** The connection to the server was successful. */
021:            public static final int STATUS_WELCOME = 201;
022:            /** The AUTH command was accepted, but the authentication data has
023:             not been checked yet. */
024:            public static final int STATUS_AUTH_ACCEPTED = 202;
025:
026:            /** A syntax error occurred. */
027:            public static final int STATUS_SYNTAX_ERROR = 500;
028:            /** The last command was unknown. */
029:            public static final int STATUS_UNKNOWN_COMMAND = 501;
030:            /** The last command referred to an unknown DNS zone. */
031:            public static final int STATUS_UNKNOWN_ZONE = 502;
032:            /** The last command cannot be handled in this server state. */
033:            public static final int STATUS_WRONG_STATE = 502;
034:            /** The last command included a malformed IP address. */
035:            public static final int STATUS_MALFORMED_ADDRESS = 504;
036:            /** The specified update could not be performed. */
037:            public static final int STATUS_NO_UPDATE = 510;
038:            /** The AUTH command had an unknown authentication type. */
039:            public static final int STATUS_UNKNOWN_AUTH_TYPE = 520;
040:            /** The authentication could not be performed. */
041:            public static final int STATUS_COULD_NOT_AUTH = 521;
042:            /** The specified update could not be performed. */
043:            public static final int STATUS_NOT_ALLOWED = 522;
044:
045:            /*********************************************************************
046:             *  Write a line in network format (CR/LF terminated).
047:             *********************************************************************
048:             *  We flush the writer immediately.
049:             *  @param out The output writer.
050:             *  @param line The string to write.
051:             *  @exception IOException An error occured while writing.
052:             */
053:
054:            public static void writeLine(Writer out, String line)
055:                    throws IOException {
056:                out.write(line + "\r\n");
057:                out.flush();
058:            }
059:
060:            /*********************************************************************
061:             *  An response returned by the update server.
062:             *********************************************************************
063:             *  This class respresents responses of the form:
064:             *  <pre>500 Error message</pre>
065:             *  This class is a subclass of Exception, so you can throw it.
066:             */
067:
068:            static public class ServerResponse extends Exception {
069:
070:                private int code;
071:                private String text;
072:
073:                /*****************************************************************
074:                 *  Create a new server response object.
075:                 *****************************************************************
076:                 *  @param code A three-digit response code.
077:                 *  @param text The explanatory string returned by the server.
078:                 */
079:
080:                public ServerResponse(int code, String text) {
081:                    super (code + " " + text);
082:                    this .code = code;
083:                    this .text = text;
084:                }
085:
086:                /*****************************************************************
087:                 *  Parse a server response string.
088:                 *****************************************************************
089:                 *  @param line The text returned by the server.
090:                 */
091:
092:                static public ServerResponse parse(String line)
093:                        throws IOException {
094:                    try {
095:                        if (line.length() < 5 || line.charAt(3) != ' ')
096:                            throwParseError();
097:                        String digits = line.substring(0, 3);
098:                        String text = line.substring(4);
099:                        int code = Integer.parseInt(digits);
100:                        return new ServerResponse(code, text);
101:                    } catch (NumberFormatException e) {
102:                        throwParseError();
103:                        // We never get here.
104:                        return null;
105:                    }
106:                }
107:
108:                // Give up on parsing and throw an error.
109:                static private void throwParseError() throws IOException {
110:                    throw new IOException(
111:                            "Error parsing response from UpdateServer.");
112:                }
113:
114:                /** Get the server's response code. */
115:                public int getCode() {
116:                    return this .code;
117:                }
118:
119:                /** Get the server's response text. */
120:                public String getText() {
121:                    return this .text;
122:                }
123:
124:                /** Return true if the response represents an error. */
125:                public boolean isError() {
126:                    if (this .code < 200 || this .code > 299)
127:                        return true;
128:                    return false;
129:                }
130:            }
131:
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.