Source Code Cross Referenced for Proxy.java in  » Apache-Harmony-Java-SE » java-package » java » net » 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 » Apache Harmony Java SE » java package » java.net 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Licensed to the Apache Software Foundation (ASF) under one or more
002:         * contributor license agreements.  See the NOTICE file distributed with
003:         * this work for additional information regarding copyright ownership.
004:         * The ASF licenses this file to You under the Apache License, Version 2.0
005:         * (the "License"); you may not use this file except in compliance with
006:         * the License.  You may obtain a copy of the License at
007:         * 
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package java.net;
017:
018:        import org.apache.harmony.luni.util.Msg;
019:
020:        /**
021:         * This class is about proxy setting. A proxy contains <code>type</code>,
022:         * proxy host address information. There are three types of <code>Proxy</code>:
023:         * <li>Direct type proxy</li>
024:         * <li>HTTP type proxy</li>
025:         * <li>SOCKS type proxy</li>
026:         * 
027:         * A <code>Proxy</code> instance is immutable.
028:         * 
029:         */
030:        public class Proxy {
031:
032:            /**
033:             * Represents <code>Proxy.Type.DIRECT</code> type proxy setting. It tells
034:             * protocol handlers not to use any proxy.
035:             */
036:            public static final Proxy NO_PROXY = new Proxy();
037:
038:            private Proxy.Type type;
039:
040:            private SocketAddress address;
041:
042:            /**
043:             * New a <code>Proxy</code> instance. SocketAddress must NOT be null when
044:             * <code>type</code> is either <code>Proxy.Type.HTTP</code> or
045:             * <code>Proxy.Type.SOCKS</code>. For <code>Proxy.Type.DIRECT</code>
046:             * type proxy, use <code>Proxy.NO_PROXY</code> directly instead of
047:             * constructing it.
048:             * 
049:             * @param type
050:             *            proxy type
051:             * @param sa
052:             *            proxy address
053:             * @throws IllegalArgumentException
054:             *             when <code>type</code> is <code>Proxy.Type.DIRECT</code>
055:             *             or SocketAddress is null.
056:             */
057:            public Proxy(Proxy.Type type, SocketAddress sa) {
058:                /*
059:                 * Don't use DIRECT type to construct a proxy instance directly.
060:                 * SocketAddress must NOT be null.
061:                 */
062:                if (type == Type.DIRECT || null == sa) {
063:                    // KA022=Illegal Proxy.Type or SocketAddress argument
064:                    throw new IllegalArgumentException(Msg.getString("KA022")); //$NON-NLS-1$
065:                }
066:                this .type = type;
067:                address = sa;
068:            }
069:
070:            /*
071:             * Constructs a Proxy instance, which is Proxy.DIRECT type with null
072:             * SocketAddress. This constructor is used for NO_PROXY.
073:             */
074:            private Proxy() {
075:                type = Type.DIRECT;
076:                address = null;
077:            }
078:
079:            /**
080:             * Gets the proxy type.
081:             * 
082:             * @return the proxy type.
083:             */
084:            public Proxy.Type type() {
085:                return type;
086:            }
087:
088:            /**
089:             * Gets the proxy address.
090:             * 
091:             * @return the proxy address for <code>HTTP</code> and <code>SOCKS</code>
092:             *         type proxy. Returns null for <code>DIRECT</code> type proxy.
093:             */
094:            public SocketAddress address() {
095:                return address;
096:            }
097:
098:            /**
099:             * <p>
100:             * Representing string of the proxy. The string consists of
101:             * <code>type.toString()</code> and <code>address.toString()</code> if
102:             * <code>type</code> and <code>address</code> are not null.
103:             * </p>
104:             * 
105:             * @see java.lang.Object#equals(java.lang.Object)
106:             * @return representing string of the proxy.
107:             */
108:            @Override
109:            public String toString() {
110:                String proxyString = String.valueOf(type);
111:                if (null != address) {
112:                    proxyString += "/" + address.toString(); //$NON-NLS-1$
113:                }
114:                return proxyString;
115:            }
116:
117:            /**
118:             * <p>
119:             * Compare <code>obj</code> with current proxy. Returns false if the
120:             * <code>obj</code> is not a <code>Proxy</code> object. Returns true if
121:             * and only if the <code>obj</code> has the same <code>address</code>
122:             * and <code>type</code> value as current proxy.
123:             * </p>
124:             * 
125:             * @see java.lang.Object#equals(java.lang.Object)
126:             * @return true if <code>obj</code> represents the same proxy. Otherwise,
127:             *         returns false.
128:             */
129:            @Override
130:            public final boolean equals(Object obj) {
131:                if (this  == obj) {
132:                    return true;
133:                }
134:                if (!(obj instanceof  Proxy)) {
135:                    return false;
136:                }
137:                Proxy another = (Proxy) obj;
138:                // address is null when and only when it's NO_PROXY.
139:                return (type == another.type)
140:                        && address.equals(another.address);
141:            }
142:
143:            /**
144:             * gets the hash code of <code>Proxy</code>.
145:             * 
146:             * @see java.lang.Object#hashCode()
147:             * @return the hash code of <code>Proxy</code>.
148:             */
149:            @Override
150:            public final int hashCode() {
151:                int ret = 0;
152:                ret += type.hashCode();
153:                if (null != address) {
154:                    ret += address.hashCode();
155:                }
156:                return ret;
157:            }
158:
159:            /**
160:             * The proxy type, includes <code>DIRECT</code>, <code>HTTP</code> and
161:             * <code>SOCKS</code>.
162:             */
163:            public enum Type {
164:                /**
165:                 * Direct connection. Connect without any proxy.
166:                 */
167:                DIRECT,
168:
169:                /**
170:                 * HTTP type proxy. It's often used by protocol handlers such as HTTP,
171:                 * HTTPS and FTP.
172:                 */
173:                HTTP,
174:
175:                /**
176:                 * SOCKS type proxy.
177:                 */
178:                SOCKS
179:            }
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.