Source Code Cross Referenced for RAckHeader.java in  » 6.0-JDK-Modules » j2me » gov » nist » siplite » header » 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 » 6.0 JDK Modules » j2me » gov.nist.siplite.header 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *   
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:
027:        package gov.nist.siplite.header;
028:
029:        import gov.nist.core.*;
030:
031:        /**
032:         * RAck Header.
033:         *
034:         *  The RAck header is sent in a PRACK request to support reliability of
035:         *  provisional responses. For details please see RFC 3262, section 7.2
036:         */
037:
038:        public class RAckHeader extends ParameterLessHeader {
039:            /** Class handle. */
040:            public static Class clazz;
041:
042:            /** Sequence header. */
043:            public static final String NAME = Header.RACK;
044:
045:            static {
046:                clazz = new RAckHeader().getClass();
047:            }
048:
049:            /**
050:             * response number - it is actually a value of RSeq header in the reliable
051:             *  provisional response
052:             */
053:            protected Integer responseNum;
054:
055:            /**
056:             * CSeq number : value of CSeq header field
057:             */
058:            protected Integer cseqNum;
059:
060:            /**
061:             * method name
062:             */
063:            protected String method;
064:
065:            /**
066:             * Constructor.
067:             */
068:            public RAckHeader() {
069:                super (RACK);
070:            }
071:
072:            /**
073:             * Constructor given the sequence number and method.
074:             *
075:             * @param responseNumber is the response number to assign.
076:             * @param cseqNumber is the CSeq number to assign.
077:             * @param method is the method string.
078:             */
079:            public RAckHeader(int responseNumber, int cseqNumber, String method) {
080:                this ();
081:                responseNum = new Integer(responseNumber);
082:                cseqNum = new Integer(cseqNumber);
083:                method = method;
084:            }
085:
086:            /**
087:             * Compare two RAck headers for equality. Equality of RAck headers means
088:             * that the class, method, response number and cseq number are same for
089:             * both the headers
090:             * @param other Object to compare against.
091:             * @return true if the two RAck headers are equals, false
092:             * otherwise.
093:             */
094:            public boolean equals(Object other) {
095:                if (!other.getClass().equals(this .getClass())) {
096:                    return false;
097:                }
098:                RAckHeader that = (RAckHeader) other;
099:                if (!this .responseNum.equals(that.responseNum)) {
100:                    return false;
101:                }
102:                if (!this .cseqNum.equals(that.cseqNum)) {
103:                    return false;
104:                }
105:                if (!equalsIgnoreCase(this .method, that.method)) {
106:                    return false;
107:                }
108:                return true;
109:            }
110:
111:            /**
112:             * Return canonical header content. (encoded header except headerName:)
113:             *
114:             * @return encoded string.
115:             */
116:            public String encodeBody() {
117:                return responseNum + Separators.SP + cseqNum + Separators.SP
118:                        + method.toUpperCase();
119:            }
120:
121:            /**
122:             * Get the method.
123:             * @return String the method.
124:             */
125:            public String getMethod() {
126:                return method.toUpperCase();
127:            }
128:
129:            /**
130:             * Sets the response number of this RAckHeaderHeader.
131:             * @param responseNumber is the response number to be set
132:             */
133:            public void setResponseNumber(int responseNumber) {
134:                if (responseNumber < 0)
135:                    throw new IllegalArgumentException(
136:                            "the sequence number parameter is < 0");
137:                responseNum = new Integer(responseNumber);
138:            }
139:
140:            /**
141:             * Sets the sequence number of this RAckHeaderHeader. The sequence number
142:             * MUST be expressible as a 32-bit unsigned integer and MUST be less than
143:             * 2**31.
144:             *
145:             * @param sequenceNumber - the sequence number to set.
146:             * @throws InvalidArgumentException -- if the seq number is <= 0
147:             */
148:            public void setSequenceNumber(int sequenceNumber) {
149:                if (sequenceNumber < 0)
150:                    throw new IllegalArgumentException(
151:                            "the sequence number parameter is < 0");
152:                cseqNum = new Integer(sequenceNumber);
153:            }
154:
155:            /**
156:             * Set the method member
157:             *
158:             * @param newMethod Method to be set
159:             */
160:            public void setMethod(String newMethod) {
161:                if (newMethod == null)
162:                    throw new NullPointerException("parameter is null");
163:                method = newMethod;
164:            }
165:
166:            /**
167:             * Gets the response number of this RAckHeaderHeader.
168:             *
169:             * @return response number of the RAckHeaderHeader
170:             */
171:
172:            public int getResponseNumber() {
173:                if (this .responseNum == null)
174:                    return 0;
175:                else
176:                    return this .responseNum.intValue();
177:            }
178:
179:            /**
180:             * Gets the sequence number of this RAckHeaderHeader.
181:             *
182:             * @return sequence number of the RAckHeaderHeader
183:             */
184:
185:            public int getSequenceNumber() {
186:                if (this .cseqNum == null)
187:                    return 0;
188:                else
189:                    return this .cseqNum.intValue();
190:            }
191:
192:            /**
193:             * Copies the current instance.
194:             * @return copy of current object
195:             */
196:            public Object clone() {
197:                RAckHeader retval = new RAckHeader();
198:
199:                if (this .responseNum != null)
200:                    retval.responseNum = new Integer(this .responseNum
201:                            .intValue());
202:                if (this .cseqNum != null)
203:                    retval.cseqNum = new Integer(this .cseqNum.intValue());
204:                retval.method = this .method;
205:
206:                return retval;
207:            }
208:
209:            /**
210:             * Gets the header value.
211:             * @return the header value
212:             */
213:            public Object getValue() {
214:                return responseNum + Separators.SP + cseqNum + Separators.SP
215:                        + method.toUpperCase();
216:            }
217:
218:            /**
219:             * Sets the header value field.
220:             * @param value is the value field to set.
221:             * @throws IllegalArgumentException if the value is invalid.
222:             */
223:            public void setHeaderValue(String value)
224:                    throws IllegalArgumentException {
225:                int newResponseNo;
226:                int newSeqNo;
227:                String newMethod;
228:                String strCseqMethod;
229:
230:                value = value.trim();
231:
232:                // Check if the sequence number presents
233:                int delimIndex1 = value.indexOf(' ');
234:                if (delimIndex1 == -1) {
235:                    throw new IllegalArgumentException("Invalid value");
236:                }
237:
238:                try {
239:                    String strResponse = value.substring(0, delimIndex1).trim();
240:                    newResponseNo = Integer.parseInt(strResponse);
241:                    setResponseNumber(newResponseNo);
242:                } catch (IllegalArgumentException iae) {
243:                    throw iae;
244:                }
245:
246:                strCseqMethod = value.substring(delimIndex1, value.length())
247:                        .trim();
248:                int delimIndex2 = strCseqMethod.indexOf(' ');
249:                if (delimIndex2 == -1) {
250:                    throw new IllegalArgumentException("Invalid value");
251:                }
252:
253:                try {
254:                    String strCseq = strCseqMethod.substring(0, delimIndex2)
255:                            .trim();
256:                    newSeqNo = Integer.parseInt(strCseq);
257:                    setSequenceNumber(newSeqNo);
258:                } catch (IllegalArgumentException iae) {
259:                    throw iae;
260:                }
261:
262:                newMethod = strCseqMethod.substring(delimIndex2,
263:                        strCseqMethod.length()).trim();
264:                setMethod(newMethod);
265:            }
266:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.