org.apache.http
Class Scheme

java.lang.Object
  extended by org.apache.http.Scheme

public class Scheme
extends java.lang.Object

A class to encapsulate the specifics of a protocol scheme. This class also provides the ability to customize the set and characteristics of the schemes used.

One use case for modifying the default set of protocols would be to set a custom SSL socket factory. This would look something like the following:

 
 Scheme myHTTPS = new Scheme( "https", new MySSLSocketFactory(), 443 );
 
 Scheme.registerScheme( "https", myHTTPS );
 

Since:
2.0
Author:
Michael Becke, Jeff Dever, Mike Bowler

Constructor Summary
Scheme(java.lang.String name, SocketFactory factory, int defaultPort)
          Constructs a new Protocol.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Return true if the specified object equals this object.
 int getDefaultPort()
          Returns the defaultPort.
 java.lang.String getName()
          Returns the scheme.
static Scheme getScheme(java.lang.String id)
          Gets the scheme with the given ID.
 SocketFactory getSocketFactory()
          Returns the socketFactory.
 int hashCode()
          Return a hash code for this object
 boolean isSecure()
          Returns true if this scheme is secure
static void registerScheme(java.lang.String id, Scheme scheme)
          Registers a new scheme with the given identifier.
 int resolvePort(int port)
          Resolves the correct port for this scheme.
 java.lang.String toString()
          Return a string representation of this object.
static void unregisterScheme(java.lang.String id)
          Unregisters the scheme with the given ID.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Scheme

public Scheme(java.lang.String name,
              SocketFactory factory,
              int defaultPort)
Constructs a new Protocol. Whether the created scheme is secure depends on the class of factory.

Parameters:
name - the scheme name (e.g. http, https)
factory - the factory for creating sockets for communication using this scheme
defaultPort - the port this scheme defaults to
Method Detail

registerScheme

public static void registerScheme(java.lang.String id,
                                  Scheme scheme)
Registers a new scheme with the given identifier. If a scheme with the given ID already exists it will be overridden. This ID is the same one used to retrieve the scheme from getScheme(String).

Parameters:
id - the identifier for this scheme
scheme - the scheme to register
See Also:
getScheme(String)

unregisterScheme

public static void unregisterScheme(java.lang.String id)
Unregisters the scheme with the given ID.

Parameters:
id - the ID of the scheme to remove

getScheme

public static Scheme getScheme(java.lang.String id)
                        throws java.lang.IllegalStateException
Gets the scheme with the given ID.

Parameters:
id - the scheme ID
Returns:
Scheme a scheme
Throws:
java.lang.IllegalStateException - if a scheme with the ID cannot be found

getDefaultPort

public int getDefaultPort()
Returns the defaultPort.

Returns:
int

getSocketFactory

public SocketFactory getSocketFactory()
Returns the socketFactory. If secure the factory is a SecureSocketFactory.

Returns:
SocketFactory

getName

public java.lang.String getName()
Returns the scheme.

Returns:
The scheme

isSecure

public boolean isSecure()
Returns true if this scheme is secure

Returns:
true if this scheme is secure

resolvePort

public int resolvePort(int port)
Resolves the correct port for this scheme. Returns the given port if valid or the default port otherwise.

Parameters:
port - the port to be resolved
Returns:
the given port or the defaultPort

toString

public java.lang.String toString()
Return a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this object.

equals

public boolean equals(java.lang.Object obj)
Return true if the specified object equals this object.

Overrides:
equals in class java.lang.Object
Parameters:
obj - The object to compare against.
Returns:
true if the objects are equal.

hashCode

public int hashCode()
Return a hash code for this object

Overrides:
hashCode in class java.lang.Object
Returns:
The hash code.


Copyright 2005-2005-2006 Apache Software Foundation. All Rights Reserved.