Source Code Cross Referenced for CallIdentifier.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:         * Portions Copyright  2000-2007 Sun Microsystems, Inc. All Rights
003:         * Reserved.  Use is subject to license terms.
004:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005:         * 
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License version
008:         * 2 only, as published by the Free Software Foundation.
009:         * 
010:         * This program is distributed in the hope that it will be useful, but
011:         * WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * General Public License version 2 for more details (a copy is
014:         * included at /legal/license.txt).
015:         * 
016:         * You should have received a copy of the GNU General Public License
017:         * version 2 along with this work; if not, write to the Free Software
018:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019:         * 02110-1301 USA
020:         * 
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022:         * Clara, CA 95054 or visit www.sun.com if you need additional
023:         * information or have any questions.
024:         */
025:        /*
026:         */
027:        package gov.nist.siplite.header;
028:
029:        import gov.nist.core.*;
030:        import gov.nist.siplite.parser.Lexer;
031:
032:        /**
033:         * The call identifer that goes into a callID header and a in-reply-to header.
034:         * @see CallIdHeader
035:         */
036:        public final class CallIdentifier extends GenericObject {
037:
038:            /**
039:             * localId field
040:             */
041:            protected String localId;
042:
043:            /**
044:             * host field
045:             */
046:            protected String host;
047:
048:            /**
049:             * Default constructor
050:             */
051:            public CallIdentifier() {
052:            }
053:
054:            /**
055:             * Constructor
056:             * @param localId is the local id.
057:             * @param host is the host.
058:             */
059:            public CallIdentifier(String localId, String host) {
060:                this .localId = localId;
061:                this .host = host;
062:            }
063:
064:            /**
065:             * constructor
066:             * @param cid String to set
067:             * @throws IllegalArgumentException if cid is null or is not a token,
068:             * or token@token
069:             */
070:            public CallIdentifier(String cid) throws IllegalArgumentException {
071:                setCallIdHeader(cid);
072:            }
073:
074:            /**
075:             * Get the encoded version of this id.
076:             * @return String to set
077:             */
078:            public String encode() {
079:                if (host != null) {
080:                    return localId + Separators.AT + host;
081:                } else {
082:                    return localId;
083:                }
084:            }
085:
086:            /**
087:             * Compare two call identifiers for equality.
088:             * @param other Object to set
089:             * @return true if the two call identifiers are equals, false
090:             * otherwise
091:             */
092:            public boolean equals(Object other) {
093:                if (!other.getClass().equals(this .getClass())) {
094:                    return false;
095:                }
096:                CallIdentifier that = (CallIdentifier) other;
097:                if (this .localId.compareTo(that.localId) != 0) {
098:                    return false;
099:                }
100:                if (this .host == that.host)
101:                    return true;
102:                if ((this .host == null && that.host != null)
103:                        || (this .host != null && that.host == null))
104:                    return false;
105:                if (Utils.compareToIgnoreCase(host, that.host) != 0) {
106:                    return false;
107:                }
108:                return true;
109:            }
110:
111:            /**
112:             * get the LocalId field
113:             * @return String
114:             */
115:            public String getLocalId() {
116:                return localId;
117:            }
118:
119:            /**
120:             * get the host field
121:             * @return host member String
122:             */
123:            public String getHost() {
124:                return host;
125:            }
126:
127:            /**
128:             * Set the localId member
129:             * @param localId String to set
130:             */
131:            public void setLocalId(String localId) {
132:                this .localId = localId;
133:            }
134:
135:            /**
136:             * set the callId field
137:             * @param cid Strimg to set
138:             * @throws IllegalArgumentException if cid is null or is not a token or
139:             * token@token
140:             */
141:            public void setCallIdHeader(String cid)
142:                    throws IllegalArgumentException {
143:                if (cid == null)
144:                    throw new IllegalArgumentException("NULL!");
145:                int index = cid.indexOf('@');
146:                if (index == -1) {
147:                    checkValue(cid);
148:                    localId = cid;
149:                    host = null;
150:                } else {
151:                    if (index == 0 || index == cid.length() - 1) {
152:                        throw new IllegalArgumentException(
153:                                "CallIdHeader must be token@token or token");
154:                    }
155:                    String temp1 = cid.substring(0, index);
156:                    String temp2 = cid.substring(index + 1, cid.length());
157:                    checkValue(temp1);
158:                    checkValue(temp2);
159:                    localId = temp1;
160:                    host = temp2;
161:                }
162:            }
163:
164:            /**
165:             * Checks Call-Id value validity
166:             * 
167:             * @param cid string to be checked
168:             * 
169:             * @throws IllegalArgumentException in case of illegal symbol use
170:             */
171:            private void checkValue(String cid) throws IllegalArgumentException {
172:                // RFC 3261 p.228
173:                // Call-ID  =  ( "Call-ID" / "i" ) HCOLON callid
174:                // callid   =  word [ "@" word ]
175:                // word        =  1*(alphanum / "-" / "." / "!" / "%" / "*" /
176:                //                "_" / "+" / "`" / "'" / "~" /
177:                //                "(" / ")" / "<" / ">" /
178:                //                ":" / "\" / DQUOTE /
179:                //                "/" / "[" / "]" / "?" /
180:                //                "{" / "}" )
181:                // The word construct is used in
182:                // Call-ID to allow most separators to be used.
183:                String word = "-.!%*_+`'~()<>:\\\"/[]?{}";
184:                char c;
185:                for (int i = 0; i < cid.length(); i++) {
186:                    c = cid.charAt(i);
187:                    if (Lexer.isAlpha(c) || Lexer.isHexDigit(c)
188:                            || word.indexOf(c) != -1) {
189:                        continue;
190:                    }
191:                    throw new IllegalArgumentException("Wrong Call-Id value:"
192:                            + "illegal use of symbol '" + c + "' at '" + cid
193:                            + "'");
194:                }
195:            }
196:
197:            /**
198:             * Set the host member
199:             * @param host String to set
200:             */
201:            public void setHost(String host) {
202:                this .host = host;
203:            }
204:
205:            /**
206:             * Clone - do a deep copy.
207:             * @return Object CallIdentifier
208:             */
209:            public Object clone() {
210:                CallIdentifier retval = new CallIdentifier();
211:
212:                if (this .localId != null)
213:                    retval.localId = new String(this .localId);
214:                if (this .host != null)
215:                    retval.host = new String(this .host);
216:                return retval;
217:            }
218:
219:            /**
220:             * Encodes the object. Calls encode().
221:             * @return String canonical encoded version of this CallIdentifier.
222:             */
223:            public String toString() {
224:                return encode();
225:            }
226:
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.