Source Code Cross Referenced for Hop.java in  » 6.0-JDK-Modules » j2me » gov » nist » siplite » address » 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.address 
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:         * Hop.java
027:         *
028:         * Created on July 15, 2001, 2:28 PM
029:         */
030:
031:        package gov.nist.siplite.address;
032:
033:        import gov.nist.core.*;
034:
035:        import com.sun.midp.log.Logging;
036:        import com.sun.midp.log.LogChannels;
037:
038:        /**
039:         * Routing algorithms return a list of hops to which the request is
040:         * routed.
041:         */
042:        public class Hop extends Object {
043:            /** Current host. */
044:            protected String host;
045:            /** Port number. */
046:            protected int port;
047:            /** Connection transport. */
048:            protected String transport;
049:            /** Explicit route from a ROUTE header. */
050:            protected boolean explicitRoute;
051:            /** Default route from the proxy addr. */
052:            protected boolean defaultRoute;
053:            /** URI route from the requestURI. */
054:            protected boolean uriRoute;
055:
056:            /**
057:             * Encodes contents int a string.
058:             * @return encoded string of object contents
059:             */
060:            public String toString() {
061:                return host + ":" + port + "/" + transport;
062:            }
063:
064:            /**
065:             * Compares fro equivalence.
066:             * @param other the object to compare
067:             * @return true if the object matches
068:             */
069:            public boolean equals(Object other) {
070:                if (other.getClass().equals(this .getClass())) {
071:                    Hop otherhop = (Hop) other;
072:                    return (otherhop.host.equals(this .host) && otherhop.port == this .port);
073:                } else
074:                    return false;
075:            }
076:
077:            /**
078:             * Create new hop given host, port and transport.
079:             * @param hostName hostname
080:             * @param portNumber port
081:             * @param trans transport
082:             * @throws IllegalArgument exception if some parameter
083:             * has invalid value.
084:             */
085:            public Hop(String hostName, int portNumber, String trans)
086:                    throws IllegalArgumentException {
087:
088:                if (portNumber < 0) {
089:                    throw new IllegalArgumentException("Invalid port: "
090:                            + portNumber);
091:                }
092:
093:                host = hostName;
094:                port = portNumber;
095:
096:                if (trans == null)
097:                    transport = "UDP";
098:                else if (trans == "")
099:                    transport = "UDP";
100:                else
101:                    transport = trans;
102:            }
103:
104:            /**
105:             * Creates new Hop
106:             * @param hop is a hop string in the form of host:port/Transport
107:             * @throws IllegalArgument exception if string is not properly formatted or
108:             * null.
109:             */
110:            public Hop(String hop) throws IllegalArgumentException {
111:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
112:                    Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
113:                            "create hop for " + hop);
114:                }
115:
116:                if (hop == null)
117:                    throw new IllegalArgumentException("Null arg!");
118:
119:                try {
120:                    StringTokenizer stringTokenizer = new StringTokenizer(hop
121:                            + "/");
122:                    String hostPort = stringTokenizer.getNextToken('/');
123:                    // Skip over the slash.
124:                    stringTokenizer.getNextChar();
125:                    // get the transport string.
126:                    transport = stringTokenizer.getNextToken('/').trim();
127:                    if (transport == null)
128:                        transport = "UDP";
129:                    else if (transport == "")
130:                        transport = "UDP";
131:                    if (Utils.compareToIgnoreCase(transport, "UDP") != 0
132:                            && Utils.compareToIgnoreCase(transport, "TCP") != 0) {
133:                        System.out.println("Bad transport string " + transport);
134:                        throw new IllegalArgumentException(hop);
135:                    }
136:                    stringTokenizer = new StringTokenizer(hostPort + ":");
137:                    host = stringTokenizer.getNextToken(':');
138:                    if (host == null || host.equals(""))
139:                        throw new IllegalArgumentException("no host!");
140:                    stringTokenizer.consume(1);
141:                    String portString = null;
142:                    portString = stringTokenizer.getNextToken(':');
143:
144:                    if (portString == null || portString.equals("")) {
145:                        throw new IllegalArgumentException("no port!");
146:                        // port = 5060;
147:                    } else {
148:                        try {
149:                            port = Integer.parseInt(portString);
150:                        } catch (NumberFormatException ex) {
151:                            throw new IllegalArgumentException("Bad port spec");
152:                        }
153:                    }
154:                    defaultRoute = true;
155:                } catch (ParseException ex) {
156:                    throw new IllegalArgumentException("Bad hop");
157:                }
158:
159:            }
160:
161:            /**
162:             * Retruns the host string.
163:             * @return host String
164:             */
165:            public String getHost() {
166:                return host;
167:            }
168:
169:            /**
170:             * Returns the port.
171:             * @return port integer.
172:             */
173:            public int getPort() {
174:                return port;
175:            }
176:
177:            /**
178:             * Returns the transport string.
179:             * @return the transport string
180:             */
181:            public String getTransport() {
182:                return transport;
183:            }
184:
185:            /**
186:             * Return true if this is an explicit route (extacted from a ROUTE
187:             * Header).
188:             * @return the explicit route
189:             */
190:            public boolean isExplicitRoute() {
191:                return explicitRoute;
192:            }
193:
194:            /**
195:             * Return true if this is a default route (next hop proxy address).
196:             * @return true if this is the default route
197:             */
198:            public boolean isDefaultRoute() {
199:                return defaultRoute;
200:            }
201:
202:            /**
203:             * Return true if this is uriRoute.
204:             * @return true if this is the URI route
205:             */
206:            public boolean isURIRoute() {
207:                return uriRoute;
208:            }
209:
210:            /**
211:             * Set the URIRoute flag.
212:             */
213:            public void setURIRouteFlag() {
214:                uriRoute = true;
215:            }
216:
217:            /**
218:             * Set the defaultRouteFlag.
219:             */
220:            public void setDefaultRouteFlag() {
221:                defaultRoute = true;
222:            }
223:
224:            /**
225:             * Set the explicitRoute flag.
226:             */
227:            public void setExplicitRouteFlag() {
228:                explicitRoute = true;
229:            }
230:
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.