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

SchemeRegistry

public final class SchemeRegistry extends Object
A set of supported protocol {@link Scheme schemes}. Schemes are identified by lowercase names.
author
Roland Weber
version
$Revision: 648356 $ $Date: 2008-04-15 10:57:53 -0700 (Tue, 15 Apr 2008) $
since
4.0

Fields Summary
private final Map
registeredSchemes
The available schemes in this registry.
Constructors Summary
public SchemeRegistry()
Creates a new, empty scheme registry.

        super();
        registeredSchemes = new LinkedHashMap<String,Scheme>();
    
Methods Summary
public final synchronized org.apache.http.conn.scheme.Schemeget(java.lang.String name)
Obtains a scheme by name, if registered.

param
name the name of the scheme to look up (in lowercase)
return
the scheme, or null if there is none by this name

        if (name == null)
            throw new IllegalArgumentException("Name must not be null.");

        // leave it to the caller to use the correct name - all lowercase
        //name = name.toLowerCase();
        Scheme found = registeredSchemes.get(name);
        return found;
    
public final synchronized org.apache.http.conn.scheme.SchemegetScheme(java.lang.String name)
Obtains a scheme by name.

param
name the name of the scheme to look up (in lowercase)
return
the scheme, never null
throws
IllegalStateException if the scheme with the given name is not registered

        Scheme found = get(name);
        if (found == null) {
            throw new IllegalStateException
                ("Scheme '"+name+"' not registered.");
        }
        return found;
    
public final synchronized org.apache.http.conn.scheme.SchemegetScheme(org.apache.http.HttpHost host)
Obtains the scheme for a host. Convenience method for getScheme(host.getSchemeName())

param
host the host for which to obtain the scheme
return
the scheme for the given host, never null
throws
IllegalStateException if a scheme with the respective name is not registered

        if (host == null) {
            throw new IllegalArgumentException("Host must not be null.");
        }
        return getScheme(host.getSchemeName());
    
public final synchronized java.util.ListgetSchemeNames()
Obtains the names of the registered schemes in their default order.

return
List containing registered scheme names.

        return new ArrayList<String>(registeredSchemes.keySet());
    
public final synchronized org.apache.http.conn.scheme.Schemeregister(org.apache.http.conn.scheme.Scheme sch)
Registers a scheme. The scheme can later be retrieved by its name using {@link #getScheme(String) getScheme} or {@link #get get}.

param
sch the scheme to register
return
the scheme previously registered with that name, or null if none was registered

        if (sch == null)
            throw new IllegalArgumentException("Scheme must not be null.");

        Scheme old = registeredSchemes.put(sch.getName(), sch);
        return old;
    
public synchronized voidsetItems(java.util.Map map)
Populates the internal collection of registered {@link Scheme protocol schemes} with the content of the map passed as a parameter.

param
map protocol schemes

        if (map == null) {
            return;
        }
        registeredSchemes.clear();
        registeredSchemes.putAll(map);
    
public final synchronized org.apache.http.conn.scheme.Schemeunregister(java.lang.String name)
Unregisters a scheme.

param
name the name of the scheme to unregister (in lowercase)
return
the unregistered scheme, or null if there was none

        if (name == null)
            throw new IllegalArgumentException("Name must not be null.");

        // leave it to the caller to use the correct name - all lowercase
        //name = name.toLowerCase();
        Scheme gone = registeredSchemes.remove(name);
        return gone;