FileDocCategorySizeDatePackage
CookieSpecRegistry.javaAPI DocAndroid 1.5 API5867Wed May 06 22:41:10 BST 2009org.apache.http.cookie

CookieSpecRegistry

public final class CookieSpecRegistry extends Object
Cookie specification registry that can be used to obtain the corresponding cookie specification implementation for a given type of type or version of cookie.
author
Oleg Kalnichevski
author
Mike Bowler
since
4.0

Fields Summary
private final Map
registeredSpecs
Constructors Summary
public CookieSpecRegistry()

        super();
        this.registeredSpecs = new LinkedHashMap<String,CookieSpecFactory>();
    
Methods Summary
public synchronized org.apache.http.cookie.CookieSpecgetCookieSpec(java.lang.String name, org.apache.http.params.HttpParams params)
Gets the {@link CookieSpec cookie specification} with the given ID.

param
name the {@link CookieSpec cookie specification} identifier
param
params the {@link HttpParams HTTP parameters} for the cookie specification.
return
{@link CookieSpec cookie specification}
throws
IllegalStateException if a policy with the given name cannot be found


        if (name == null) {
            throw new IllegalArgumentException("Name may not be null");
        }
        CookieSpecFactory factory = registeredSpecs.get(name.toLowerCase(Locale.ENGLISH));
        if (factory != null) {
            return factory.newInstance(params);
        } else {
            throw new IllegalStateException("Unsupported cookie spec: " + name);
        }
    
public synchronized org.apache.http.cookie.CookieSpecgetCookieSpec(java.lang.String name)
Gets the {@link CookieSpec cookie specification} with the given name.

param
name the {@link CookieSpec cookie specification} identifier
return
{@link CookieSpec cookie specification}
throws
IllegalStateException if a policy with the given name cannot be found

        return getCookieSpec(name, null);
    
public synchronized java.util.ListgetSpecNames()
Obtains a list containing names of all registered {@link CookieSpec cookie specs} in their default order. Note that the DEFAULT policy (if present) is likely to be the same as one of the other policies, but does not have to be.

return
list of registered cookie spec names

        return new ArrayList<String>(registeredSpecs.keySet()); 
    
public synchronized voidregister(java.lang.String name, org.apache.http.cookie.CookieSpecFactory factory)
Registers a {@link CookieSpecFactory} with the given identifier. If a specification with the given name already exists it will be overridden. This nameis the same one used to retrieve the {@link CookieSpecFactory} from {@link #getCookieSpec(String)}.

param
name the identifier for this specification
param
factory the {@link CookieSpecFactory} class to register
see
#getCookieSpec(String)

         if (name == null) {
             throw new IllegalArgumentException("Name may not be null");
         }
        if (factory == null) {
            throw new IllegalArgumentException("Cookie spec factory may not be null");
        }
        registeredSpecs.put(name.toLowerCase(Locale.ENGLISH), factory);
    
public synchronized voidsetItems(java.util.Map map)
Populates the internal collection of registered {@link CookieSpec cookie specs} with the content of the map passed as a parameter.

param
map cookie specs

        if (map == null) {
            return;
        }
        registeredSpecs.clear();
        registeredSpecs.putAll(map);
    
public synchronized voidunregister(java.lang.String id)
Unregisters the {@link CookieSpecFactory} with the given ID.

param
id the identifier of the {@link CookieSpec cookie specification} to unregister

         if (id == null) {
             throw new IllegalArgumentException("Id may not be null");
         }
         registeredSpecs.remove(id.toLowerCase(Locale.ENGLISH));