View Javadoc

1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.conn.scheme;
29  
30  import java.io.IOException;
31  import java.net.InetAddress;
32  import java.net.InetSocketAddress;
33  import java.net.Socket;
34  import java.net.UnknownHostException;
35  
36  import org.apache.http.conn.ConnectTimeoutException;
37  import org.apache.http.params.HttpParams;
38  
39  /**
40   * @deprecated (4.1) do not use
41   */
42  @Deprecated
43  class SchemeSocketFactoryAdaptor implements SchemeSocketFactory {
44  
45      private final SocketFactory factory;
46  
47      SchemeSocketFactoryAdaptor(final SocketFactory factory) {
48          super();
49          this.factory = factory;
50      }
51  
52      public Socket connectSocket(
53              final Socket sock,
54              final InetSocketAddress remoteAddress,
55              final InetSocketAddress localAddress,
56              final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
57          final String host = remoteAddress.getHostName();
58          final int port = remoteAddress.getPort();
59          InetAddress local = null;
60          int localPort = 0;
61          if (localAddress != null) {
62              local = localAddress.getAddress();
63              localPort = localAddress.getPort();
64          }
65          return this.factory.connectSocket(sock, host, port, local, localPort, params);
66      }
67  
68      public Socket createSocket(final HttpParams params) throws IOException {
69          return this.factory.createSocket();
70      }
71  
72      public boolean isSecure(final Socket sock) throws IllegalArgumentException {
73          return this.factory.isSecure(sock);
74      }
75  
76      public SocketFactory getFactory() {
77          return this.factory;
78      }
79  
80      @Override
81      public boolean equals(final Object obj) {
82          if (obj == null) {
83              return false;
84          }
85          if (this == obj) {
86              return true;
87          }
88          if (obj instanceof SchemeSocketFactoryAdaptor) {
89              return this.factory.equals(((SchemeSocketFactoryAdaptor)obj).factory);
90          } else {
91              return this.factory.equals(obj);
92          }
93      }
94  
95      @Override
96      public int hashCode() {
97          return this.factory.hashCode();
98      }
99  
100 }