FileDocCategorySizeDatePackage
BasicHttpProcessor.javaAPI DocAndroid 1.5 API11419Wed May 06 22:41:10 BST 2009org.apache.http.protocol

BasicHttpProcessor

public final class BasicHttpProcessor extends Object implements HttpResponseInterceptorList, HttpRequestInterceptorList, HttpProcessor, Cloneable
Keeps lists of interceptors for processing requests and responses.
author
Oleg Kalnichevski
author
Andrea Selva
version
$Revision: 613298 $
since
4.0

Fields Summary
protected List
requestInterceptors
protected List
responseInterceptors
Constructors Summary
Methods Summary
public final voidaddInterceptor(org.apache.http.HttpResponseInterceptor interceptor)
Same as {@link #addResponseInterceptor(HttpResponseInterceptor) addResponseInterceptor}.

param
interceptor the interceptor to add

        addResponseInterceptor(interceptor);
    
public final voidaddInterceptor(org.apache.http.HttpResponseInterceptor interceptor, int index)

        addResponseInterceptor(interceptor, index);
    
public final voidaddInterceptor(org.apache.http.HttpRequestInterceptor interceptor)
Same as {@link #addRequestInterceptor(HttpRequestInterceptor) addRequestInterceptor}.

param
interceptor the interceptor to add

        addRequestInterceptor(interceptor);
    
public final voidaddInterceptor(org.apache.http.HttpRequestInterceptor interceptor, int index)

        addRequestInterceptor(interceptor, index);
    
public voidaddRequestInterceptor(org.apache.http.HttpRequestInterceptor itcp)



    // non-Javadoc, see interface HttpRequestInterceptorList
         

        if (itcp == null) {
            return;
        }
        if (this.requestInterceptors == null) {
            this.requestInterceptors = new ArrayList();
        }
        this.requestInterceptors.add(itcp);
    
public voidaddRequestInterceptor(org.apache.http.HttpRequestInterceptor itcp, int index)

        if (index < 0) {
            throw new IndexOutOfBoundsException(String.valueOf(index));
        }
        if (itcp == null) {
            return;
        }

        if (this.requestInterceptors == null) {
            if (index > 0) {
                throw new IndexOutOfBoundsException(String.valueOf(index));
            }
            this.requestInterceptors = new ArrayList();
        }
        this.requestInterceptors.add(index, itcp);
    
public voidaddResponseInterceptor(org.apache.http.HttpResponseInterceptor itcp)

        if (itcp == null) {
            return;
        }
        if (this.responseInterceptors == null) {
            this.responseInterceptors = new ArrayList();
        }
        this.responseInterceptors.add(itcp);
    
public voidaddResponseInterceptor(org.apache.http.HttpResponseInterceptor itcp, int index)

        if (index < 0) {
            throw new IndexOutOfBoundsException(String.valueOf(index));
        }
        if (itcp == null) {
            return;
        }

        if (this.responseInterceptors == null) {
            if (index > 0) {
                throw new IndexOutOfBoundsException(String.valueOf(index));
            }
            this.responseInterceptors = new ArrayList();
        }
        this.responseInterceptors.add(index, itcp);
    
public voidclearInterceptors()
Clears both interceptor lists maintained by this processor.

        clearRequestInterceptors();
        clearResponseInterceptors();
    
public voidclearRequestInterceptors()

        this.requestInterceptors = null;
    
public voidclearResponseInterceptors()

        this.responseInterceptors = null;
    
public java.lang.Objectclone()

        BasicHttpProcessor clone = (BasicHttpProcessor) super.clone();
        copyInterceptors(clone);
        return clone;
    
public org.apache.http.protocol.BasicHttpProcessorcopy()
Creates a copy of this instance

return
new instance of the BasicHttpProcessor

        BasicHttpProcessor clone = new BasicHttpProcessor();
        copyInterceptors(clone);
        return clone;
    
protected voidcopyInterceptors(org.apache.http.protocol.BasicHttpProcessor target)

        if (this.requestInterceptors != null) {
            target.requestInterceptors =
                new ArrayList(this.requestInterceptors);
        }
        if (this.responseInterceptors != null) {
            target.responseInterceptors =
                new ArrayList(this.responseInterceptors);
        }
    
public org.apache.http.HttpRequestInterceptorgetRequestInterceptor(int index)

        
        if ((this.requestInterceptors == null) ||
                (index < 0) || (index >= this.requestInterceptors.size()))
            return null;
        
        return (HttpRequestInterceptor) this.requestInterceptors.get(index);
    
public intgetRequestInterceptorCount()

        return (this.requestInterceptors == null) ?
            0 : this.requestInterceptors.size();
    
public org.apache.http.HttpResponseInterceptorgetResponseInterceptor(int index)

        
        if ((this.responseInterceptors == null) ||
                (index < 0) || (index >= this.responseInterceptors.size()))
            return null;
        
        return (HttpResponseInterceptor) this.responseInterceptors.get(index);
    
public intgetResponseInterceptorCount()

        return (this.responseInterceptors == null) ?
            0 : this.responseInterceptors.size();
    
public voidprocess(org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context)

        if (this.requestInterceptors != null) {
            for (int i = 0; i < this.requestInterceptors.size(); i++) {
                HttpRequestInterceptor interceptor =
                    (HttpRequestInterceptor) this.requestInterceptors.get(i);
                interceptor.process(request, context);
            }
        }
    
public voidprocess(org.apache.http.HttpResponse response, org.apache.http.protocol.HttpContext context)

        if (this.responseInterceptors != null) {
            for (int i = 0; i < this.responseInterceptors.size(); i++) {
                HttpResponseInterceptor interceptor =
                    (HttpResponseInterceptor) this.responseInterceptors.get(i);
                interceptor.process(response, context);
            }
        }
    
public voidremoveRequestInterceptorByClass(java.lang.Class clazz)

        if (this.requestInterceptors == null) {
            return;
        }
        for (Iterator it = this.requestInterceptors.iterator();
             it.hasNext(); ) {
            Object request = it.next();
            if (request.getClass().equals(clazz)) {
                it.remove();
            }
        }
    
public voidremoveResponseInterceptorByClass(java.lang.Class clazz)

        if (this.responseInterceptors == null) {
            return;
        }
        for (Iterator it = this.responseInterceptors.iterator();
             it.hasNext(); ) {
            Object request = it.next();
            if (request.getClass().equals(clazz)) {
                it.remove();
            }
        }
    
public voidsetInterceptors(java.util.List list)
Sets the interceptor lists. First, both interceptor lists maintained by this processor will be cleared. Subsequently, elements of the argument list that are request interceptors will be added to the request interceptor list. Elements that are response interceptors will be added to the response interceptor list. Elements that are both request and response interceptor will be added to both lists. Elements that are neither request nor response interceptor will be ignored.

param
list the list of request and response interceptors from which to initialize

        if (list == null) {
            throw new IllegalArgumentException("List must not be null.");
        }
        if (this.requestInterceptors != null) {
            this.requestInterceptors.clear();
        }
        if (this.responseInterceptors != null) {
            this.responseInterceptors.clear();
        }
        for (int i = 0; i < list.size(); i++) {
            Object obj = list.get(i);
            if (obj instanceof HttpRequestInterceptor) {
                addInterceptor((HttpRequestInterceptor)obj);
            }
            if (obj instanceof HttpResponseInterceptor) {
                addInterceptor((HttpResponseInterceptor)obj);
            }
        }