Source Code Cross Referenced for HttpHost.java in  » Net » Apache-common-HttpClient » org » apache » commons » httpclient » 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 » Apache common HttpClient » org.apache.commons.httpclient 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/HttpHost.java,v 1.3 2005/01/14 21:16:40 olegk Exp $
003:         * $Revision: 510587 $
004:         * $Date: 2007-02-22 17:56:08 +0100 (Thu, 22 Feb 2007) $
005:         *
006:         * ====================================================================
007:         *
008:         *  Licensed to the Apache Software Foundation (ASF) under one or more
009:         *  contributor license agreements.  See the NOTICE file distributed with
010:         *  this work for additional information regarding copyright ownership.
011:         *  The ASF licenses this file to You under the Apache License, Version 2.0
012:         *  (the "License"); you may not use this file except in compliance with
013:         *  the License.  You may obtain a copy of the License at
014:         *
015:         *      http://www.apache.org/licenses/LICENSE-2.0
016:         *
017:         *  Unless required by applicable law or agreed to in writing, software
018:         *  distributed under the License is distributed on an "AS IS" BASIS,
019:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
020:         *  See the License for the specific language governing permissions and
021:         *  limitations under the License.
022:         * ====================================================================
023:         *
024:         * This software consists of voluntary contributions made by many
025:         * individuals on behalf of the Apache Software Foundation.  For more
026:         * information on the Apache Software Foundation, please see
027:         * <http://www.apache.org/>.
028:         *
029:         */
030:
031:        package org.apache.commons.httpclient;
032:
033:        import org.apache.commons.httpclient.protocol.Protocol;
034:        import org.apache.commons.httpclient.util.LangUtils;
035:
036:        /**
037:         * Holds all of the variables needed to describe an HTTP connection to a host. This includes 
038:         * remote host, port and protocol.
039:         * 
040:         * @author <a href="mailto:becke@u.washington.edu">Michael Becke</a>
041:         * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
042:         * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
043:         * @author Laura Werner
044:         * 
045:         * @since 3.0 
046:         */
047:        public class HttpHost implements  Cloneable {
048:
049:            /** The host to use. */
050:            private String hostname = null;
051:
052:            /** The port to use. */
053:            private int port = -1;
054:
055:            /** The protocol */
056:            private Protocol protocol = null;
057:
058:            /**
059:             * Constructor for HttpHost.
060:             *   
061:             * @param hostname the hostname (IP or DNS name). Can be <code>null</code>.
062:             * @param port the port. Value <code>-1</code> can be used to set default protocol port
063:             * @param protocol the protocol. Value <code>null</code> can be used to set default protocol
064:             */
065:            public HttpHost(final String hostname, int port,
066:                    final Protocol protocol) {
067:                super ();
068:                if (hostname == null) {
069:                    throw new IllegalArgumentException(
070:                            "Host name may not be null");
071:                }
072:                if (protocol == null) {
073:                    throw new IllegalArgumentException(
074:                            "Protocol may not be null");
075:                }
076:                this .hostname = hostname;
077:                this .protocol = protocol;
078:                if (port >= 0) {
079:                    this .port = port;
080:                } else {
081:                    this .port = this .protocol.getDefaultPort();
082:                }
083:            }
084:
085:            /**
086:             * Constructor for HttpHost.
087:             *   
088:             * @param hostname the hostname (IP or DNS name). Can be <code>null</code>.
089:             * @param port the port. Value <code>-1</code> can be used to set default protocol port
090:             */
091:            public HttpHost(final String hostname, int port) {
092:                this (hostname, port, Protocol.getProtocol("http"));
093:            }
094:
095:            /**
096:             * Constructor for HttpHost.
097:             *   
098:             * @param hostname the hostname (IP or DNS name). Can be <code>null</code>.
099:             */
100:            public HttpHost(final String hostname) {
101:                this (hostname, -1, Protocol.getProtocol("http"));
102:            }
103:
104:            /**
105:             * URI constructor for HttpHost.
106:             *   
107:             * @param uri the URI.
108:             */
109:            public HttpHost(final URI uri) throws URIException {
110:                this (uri.getHost(), uri.getPort(), Protocol.getProtocol(uri
111:                        .getScheme()));
112:            }
113:
114:            /**
115:             * Copy constructor for HttpHost
116:             * 
117:             * @param httphost the HTTP host to copy details from
118:             */
119:            public HttpHost(final HttpHost httphost) {
120:                super ();
121:                init(httphost);
122:            }
123:
124:            private void init(final HttpHost httphost) {
125:                this .hostname = httphost.hostname;
126:                this .port = httphost.port;
127:                this .protocol = httphost.protocol;
128:            }
129:
130:            /**
131:             * @throws CloneNotSupportedException 
132:             * @see java.lang.Object#clone()
133:             */
134:            public Object clone() throws CloneNotSupportedException {
135:                HttpHost copy = (HttpHost) super .clone();
136:                copy.init(this );
137:                return copy;
138:            }
139:
140:            /**
141:             * Returns the host name (IP or DNS name).
142:             * 
143:             * @return the host name (IP or DNS name), or <code>null</code> if not set
144:             */
145:            public String getHostName() {
146:                return this .hostname;
147:            }
148:
149:            /**
150:             * Returns the port.
151:             * 
152:             * @return the host port, or <code>-1</code> if not set
153:             */
154:            public int getPort() {
155:                return this .port;
156:            }
157:
158:            /**
159:             * Returns the protocol.
160:             * @return The protocol.
161:             */
162:            public Protocol getProtocol() {
163:                return this .protocol;
164:            }
165:
166:            /**
167:             * Return the host uri.
168:             * 
169:             * @return The host uri.
170:             */
171:            public String toURI() {
172:                StringBuffer buffer = new StringBuffer(50);
173:                buffer.append(this .protocol.getScheme());
174:                buffer.append("://");
175:                buffer.append(this .hostname);
176:                if (this .port != this .protocol.getDefaultPort()) {
177:                    buffer.append(':');
178:                    buffer.append(this .port);
179:                }
180:                return buffer.toString();
181:            }
182:
183:            /**
184:             * @see java.lang.Object#toString()
185:             */
186:            public String toString() {
187:                StringBuffer buffer = new StringBuffer(50);
188:                buffer.append(toURI());
189:                return buffer.toString();
190:            }
191:
192:            /**
193:             * @see java.lang.Object#equals(java.lang.Object)
194:             */
195:            public boolean equals(final Object o) {
196:
197:                if (o instanceof  HttpHost) {
198:                    // shortcut if we're comparing with ourselves
199:                    if (o == this ) {
200:                        return true;
201:                    }
202:                    HttpHost that = (HttpHost) o;
203:                    if (!this .hostname.equalsIgnoreCase(that.hostname)) {
204:                        return false;
205:                    }
206:                    if (this .port != that.port) {
207:                        return false;
208:                    }
209:                    if (!this .protocol.equals(that.protocol)) {
210:                        return false;
211:                    }
212:                    // everything matches
213:                    return true;
214:                } else {
215:                    return false;
216:                }
217:            }
218:
219:            /**
220:             * @see java.lang.Object#hashCode()
221:             */
222:            public int hashCode() {
223:                int hash = LangUtils.HASH_SEED;
224:                hash = LangUtils.hashCode(hash, this.hostname);
225:                hash = LangUtils.hashCode(hash, this.port);
226:                hash = LangUtils.hashCode(hash, this.protocol);
227:                return hash;
228:            }
229:
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.