mobile/android/thirdparty/ch/boye/httpclientandroidlib/conn/params/ConnRouteParams.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/conn/params/ConnRouteParams.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,187 @@
     1.4 +/*
     1.5 + * ====================================================================
     1.6 + *
     1.7 + *  Licensed to the Apache Software Foundation (ASF) under one or more
     1.8 + *  contributor license agreements.  See the NOTICE file distributed with
     1.9 + *  this work for additional information regarding copyright ownership.
    1.10 + *  The ASF licenses this file to You under the Apache License, Version 2.0
    1.11 + *  (the "License"); you may not use this file except in compliance with
    1.12 + *  the License.  You may obtain a copy of the License at
    1.13 + *
    1.14 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.15 + *
    1.16 + *  Unless required by applicable law or agreed to in writing, software
    1.17 + *  distributed under the License is distributed on an "AS IS" BASIS,
    1.18 + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.19 + *  See the License for the specific language governing permissions and
    1.20 + *  limitations under the License.
    1.21 + * ====================================================================
    1.22 + *
    1.23 + * This software consists of voluntary contributions made by many
    1.24 + * individuals on behalf of the Apache Software Foundation.  For more
    1.25 + * information on the Apache Software Foundation, please see
    1.26 + * <http://www.apache.org/>.
    1.27 + *
    1.28 + */
    1.29 +
    1.30 +package ch.boye.httpclientandroidlib.conn.params;
    1.31 +
    1.32 +import java.net.InetAddress;
    1.33 +
    1.34 +import ch.boye.httpclientandroidlib.annotation.Immutable;
    1.35 +
    1.36 +import ch.boye.httpclientandroidlib.HttpHost;
    1.37 +import ch.boye.httpclientandroidlib.params.HttpParams;
    1.38 +import ch.boye.httpclientandroidlib.conn.routing.HttpRoute;
    1.39 +
    1.40 +/**
    1.41 + * An adaptor for manipulating HTTP routing parameters
    1.42 + * in {@link HttpParams}.
    1.43 + *
    1.44 + * @since 4.0
    1.45 + */
    1.46 +@Immutable
    1.47 +public class ConnRouteParams implements ConnRoutePNames {
    1.48 +
    1.49 +    /**
    1.50 +     * A special value indicating "no host".
    1.51 +     * This relies on a nonsense scheme name to avoid conflicts
    1.52 +     * with actual hosts. Note that this is a <i>valid</i> host.
    1.53 +     */
    1.54 +    public static final HttpHost NO_HOST =
    1.55 +        new HttpHost("127.0.0.255", 0, "no-host"); // Immutable
    1.56 +
    1.57 +    /**
    1.58 +     * A special value indicating "no route".
    1.59 +     * This is a route with {@link #NO_HOST} as the target.
    1.60 +     */
    1.61 +    public static final HttpRoute NO_ROUTE = new HttpRoute(NO_HOST); // Immutable
    1.62 +
    1.63 +    /** Disabled default constructor. */
    1.64 +    private ConnRouteParams() {
    1.65 +        // no body
    1.66 +    }
    1.67 +
    1.68 +    /**
    1.69 +     * Obtains the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY}
    1.70 +     * parameter value.
    1.71 +     * {@link #NO_HOST} will be mapped to <code>null</code>,
    1.72 +     * to allow unsetting in a hierarchy.
    1.73 +     *
    1.74 +     * @param params    the parameters in which to look up
    1.75 +     *
    1.76 +     * @return  the default proxy set in the argument parameters, or
    1.77 +     *          <code>null</code> if not set
    1.78 +     */
    1.79 +    public static HttpHost getDefaultProxy(HttpParams params) {
    1.80 +        if (params == null) {
    1.81 +            throw new IllegalArgumentException("Parameters must not be null.");
    1.82 +        }
    1.83 +        HttpHost proxy = (HttpHost)
    1.84 +            params.getParameter(DEFAULT_PROXY);
    1.85 +        if ((proxy != null) && NO_HOST.equals(proxy)) {
    1.86 +            // value is explicitly unset
    1.87 +            proxy = null;
    1.88 +        }
    1.89 +        return proxy;
    1.90 +    }
    1.91 +
    1.92 +    /**
    1.93 +     * Sets the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY}
    1.94 +     * parameter value.
    1.95 +     *
    1.96 +     * @param params    the parameters in which to set the value
    1.97 +     * @param proxy     the value to set, may be <code>null</code>.
    1.98 +     *                  Note that {@link #NO_HOST} will be mapped to
    1.99 +     *                  <code>null</code> by {@link #getDefaultProxy},
   1.100 +     *                  to allow for explicit unsetting in hierarchies.
   1.101 +     */
   1.102 +    public static void setDefaultProxy(HttpParams params,
   1.103 +                                             HttpHost proxy) {
   1.104 +        if (params == null) {
   1.105 +            throw new IllegalArgumentException("Parameters must not be null.");
   1.106 +        }
   1.107 +        params.setParameter(DEFAULT_PROXY, proxy);
   1.108 +    }
   1.109 +
   1.110 +    /**
   1.111 +     * Obtains the {@link ConnRoutePNames#FORCED_ROUTE FORCED_ROUTE}
   1.112 +     * parameter value.
   1.113 +     * {@link #NO_ROUTE} will be mapped to <code>null</code>,
   1.114 +     * to allow unsetting in a hierarchy.
   1.115 +     *
   1.116 +     * @param params    the parameters in which to look up
   1.117 +     *
   1.118 +     * @return  the forced route set in the argument parameters, or
   1.119 +     *          <code>null</code> if not set
   1.120 +     */
   1.121 +    public static HttpRoute getForcedRoute(HttpParams params) {
   1.122 +        if (params == null) {
   1.123 +            throw new IllegalArgumentException("Parameters must not be null.");
   1.124 +        }
   1.125 +        HttpRoute route = (HttpRoute)
   1.126 +            params.getParameter(FORCED_ROUTE);
   1.127 +        if ((route != null) && NO_ROUTE.equals(route)) {
   1.128 +            // value is explicitly unset
   1.129 +            route = null;
   1.130 +        }
   1.131 +        return route;
   1.132 +    }
   1.133 +
   1.134 +    /**
   1.135 +     * Sets the {@link ConnRoutePNames#FORCED_ROUTE FORCED_ROUTE}
   1.136 +     * parameter value.
   1.137 +     *
   1.138 +     * @param params    the parameters in which to set the value
   1.139 +     * @param route     the value to set, may be <code>null</code>.
   1.140 +     *                  Note that {@link #NO_ROUTE} will be mapped to
   1.141 +     *                  <code>null</code> by {@link #getForcedRoute},
   1.142 +     *                  to allow for explicit unsetting in hierarchies.
   1.143 +     */
   1.144 +    public static void setForcedRoute(HttpParams params,
   1.145 +                                            HttpRoute route) {
   1.146 +        if (params == null) {
   1.147 +            throw new IllegalArgumentException("Parameters must not be null.");
   1.148 +        }
   1.149 +        params.setParameter(FORCED_ROUTE, route);
   1.150 +    }
   1.151 +
   1.152 +    /**
   1.153 +     * Obtains the {@link ConnRoutePNames#LOCAL_ADDRESS LOCAL_ADDRESS}
   1.154 +     * parameter value.
   1.155 +     * There is no special value that would automatically be mapped to
   1.156 +     * <code>null</code>. You can use the wildcard address (0.0.0.0 for IPv4,
   1.157 +     * :: for IPv6) to override a specific local address in a hierarchy.
   1.158 +     *
   1.159 +     * @param params    the parameters in which to look up
   1.160 +     *
   1.161 +     * @return  the local address set in the argument parameters, or
   1.162 +     *          <code>null</code> if not set
   1.163 +     */
   1.164 +    public static InetAddress getLocalAddress(HttpParams params) {
   1.165 +        if (params == null) {
   1.166 +            throw new IllegalArgumentException("Parameters must not be null.");
   1.167 +        }
   1.168 +        InetAddress local = (InetAddress)
   1.169 +            params.getParameter(LOCAL_ADDRESS);
   1.170 +        // no explicit unsetting
   1.171 +        return local;
   1.172 +    }
   1.173 +
   1.174 +    /**
   1.175 +     * Sets the {@link ConnRoutePNames#LOCAL_ADDRESS LOCAL_ADDRESS}
   1.176 +     * parameter value.
   1.177 +     *
   1.178 +     * @param params    the parameters in which to set the value
   1.179 +     * @param local     the value to set, may be <code>null</code>
   1.180 +     */
   1.181 +    public static void setLocalAddress(HttpParams params,
   1.182 +                                             InetAddress local) {
   1.183 +        if (params == null) {
   1.184 +            throw new IllegalArgumentException("Parameters must not be null.");
   1.185 +        }
   1.186 +        params.setParameter(LOCAL_ADDRESS, local);
   1.187 +    }
   1.188 +
   1.189 +}
   1.190 +

mercurial