FileDocCategorySizeDatePackage
Scheme.javaAPI DocAndroid 1.5 API6928Wed May 06 22:41:10 BST 2009org.apache.http.conn.scheme

Scheme

public final class Scheme extends Object
Encapsulates specifics of a protocol scheme such as "http" or "https". Schemes are identified by lowercase names. Supported schemes are typically collected in a {@link SchemeRegistry SchemeRegistry}.

For example, to configure support for "https://" URLs, you could write code like the following:

Scheme https = new Scheme("https", new MySecureSocketFactory(), 443);
SchemeRegistry.DEFAULT.register(https);
author
Roland Weber
author
Michael Becke
author
Jeff Dever
author
Mike Bowler

Fields Summary
private final String
name
The name of this scheme, in lowercase. (e.g. http, https)
private final SocketFactory
socketFactory
The socket factory for this scheme
private final int
defaultPort
The default port for this scheme
private final boolean
layered
Indicates whether this scheme allows for layered connections
private String
stringRep
A string representation, for {@link #toString toString}.
Constructors Summary
public Scheme(String name, SocketFactory factory, int port)
Creates a new scheme. Whether the created scheme allows for layered connections depends on the class of factory.

param
name the scheme name, for example "http". The name will be converted to lowercase.
param
factory the factory for creating sockets for communication with this scheme
param
port the default port for this scheme


        if (name == null) {
            throw new IllegalArgumentException
                ("Scheme name may not be null");
        }
        if (factory == null) {
            throw new IllegalArgumentException
                ("Socket factory may not be null");
        }
        if ((port <= 0) || (port > 0xffff)) {
            throw new IllegalArgumentException
                ("Port is invalid: " + port);
        }

        this.name = name.toLowerCase(Locale.ENGLISH);
        this.socketFactory = factory;
        this.defaultPort = port;
        this.layered = (factory instanceof LayeredSocketFactory);
    
Methods Summary
public final booleanequals(java.lang.Object obj)
Compares this scheme to an object.

param
obj the object to compare with
return
true iff the argument is equal to this scheme

        if (obj == null) return false;
        if (this == obj) return true;
        if (!(obj instanceof Scheme)) return false;

        Scheme s = (Scheme) obj;
        return (name.equals(s.name) &&
                defaultPort == s.defaultPort &&
                layered == s.layered &&
                socketFactory.equals(s.socketFactory)
                );
    
public final intgetDefaultPort()
Obtains the default port.

return
the default port for this scheme

        return defaultPort;
    
public final java.lang.StringgetName()
Obtains the scheme name.

return
the name of this scheme, in lowercase

        return name;
    
public final org.apache.http.conn.scheme.SocketFactorygetSocketFactory()
Obtains the socket factory. If this scheme is {@link #isLayered layered}, the factory implements {@link LayeredSocketFactory LayeredSocketFactory}.

return
the socket factory for this scheme

        return socketFactory;
    
public inthashCode()
Obtains a hash code for this scheme.

return
the hash code

        int hash = LangUtils.HASH_SEED;
        hash = LangUtils.hashCode(hash, this.defaultPort);
        hash = LangUtils.hashCode(hash, this.name);
        hash = LangUtils.hashCode(hash, this.layered);
        hash = LangUtils.hashCode(hash, this.socketFactory);
        return hash;
    
public final booleanisLayered()
Indicates whether this scheme allows for layered connections.

return
true if layered connections are possible, false otherwise

        return layered;
    
public final intresolvePort(int port)
Resolves the correct port for this scheme. Returns the given port if it is valid, the default port otherwise.

param
port the port to be resolved, a negative number to obtain the default port
return
the given port or the defaultPort

        return ((port <= 0) || (port > 0xffff)) ? defaultPort : port;
    
public final java.lang.StringtoString()
Return a string representation of this object.

return
a human-readable string description of this scheme

        if (stringRep == null) {
            StringBuilder buffer = new StringBuilder();
            buffer.append(this.name);
            buffer.append(':");
            buffer.append(Integer.toString(this.defaultPort));
            stringRep = buffer.toString();
        }
        return stringRep;