hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rola...@apache.org
Subject svn commit: r554589 - in /jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol: BasicHttpProcessor.java HttpRequestInterceptorList.java HttpResponseInterceptorList.java
Date Mon, 09 Jul 2007 10:05:09 GMT
Author: rolandw
Date: Mon Jul  9 03:05:05 2007
New Revision: 554589

URL: http://svn.apache.org/viewvc?view=rev&rev=554589
Log:
changed index handling when adding interceptors, made lists protected instead of private,
reformatted to 79 chars/line

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/BasicHttpProcessor.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/BasicHttpProcessor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/BasicHttpProcessor.java?view=diff&rev=554589&r1=554588&r2=554589
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/BasicHttpProcessor.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/BasicHttpProcessor.java
Mon Jul  9 03:05:05 2007
@@ -55,8 +55,8 @@
 public class BasicHttpProcessor implements
     HttpProcessor, HttpRequestInterceptorList, HttpResponseInterceptorList {
 
-    private List requestInterceptors = null; 
-    private List responseInterceptors = null;
+    protected List requestInterceptors = null; 
+    protected List responseInterceptors = null;
 
 
     // non-Javadoc, see interface HttpRequestInterceptorList
@@ -72,40 +72,41 @@
     }
     
     // non-Javadoc, see interface HttpRequestInterceptorList
-    public void addRequestInterceptor(final HttpRequestInterceptor itcp, int index) {
-        
+    public void addRequestInterceptor(final HttpRequestInterceptor itcp,
+                                      int index) {
+        if (index < 0) {
+            throw new IndexOutOfBoundsException(String.valueOf(index));
+        }
         if (itcp == null) {
             return;
         }
+
         if (this.requestInterceptors == null) {
             this.requestInterceptors = new ArrayList();
         }
-        
-        if (index == Integer.MAX_VALUE) {
-            // Add last
-            this.requestInterceptors.add(this.requestInterceptors.size() - 1, itcp);
-        } else {
-            // Insert at preferred index
-            this.requestInterceptors.add(index, itcp);
+        if (index > this.requestInterceptors.size()) {
+            index = this.requestInterceptors.size();
         }
+        this.requestInterceptors.add(index, itcp);
     }
     
 
-    public void addResponseInterceptor(HttpResponseInterceptor itcp, int index) {
+    public void addResponseInterceptor(HttpResponseInterceptor itcp,
+                                       int index) {
+        if (index < 0) {
+            throw new IndexOutOfBoundsException(String.valueOf(index));
+        }
          if (itcp == null) {
             return;
         }
+
         if (this.responseInterceptors == null) {
             this.responseInterceptors = new ArrayList();
         }
-        
-        if (index == Integer.MAX_VALUE) {
-            // Add last
-            this.responseInterceptors.add(this.responseInterceptors.size() - 1, itcp);
-        } else {
-            // Insert at preferred index
-            this.responseInterceptors.add(index, itcp);
+        if (index > this.responseInterceptors.size()) {
+            index = this.responseInterceptors.size();
         }
+        this.responseInterceptors.add(index, itcp);
     }
     
     
@@ -114,7 +115,8 @@
         if (this.requestInterceptors == null) {
             return;
         }
-        for (Iterator it = this.requestInterceptors.iterator(); it.hasNext(); ) {
+        for (Iterator it = this.requestInterceptors.iterator();
+             it.hasNext(); ) {
             Object request = it.next();
             if (request.getClass().equals(clazz)) {
                 it.remove();
@@ -127,7 +129,8 @@
         if (this.responseInterceptors == null) {
             return;
         }
-        for (Iterator it = this.responseInterceptors.iterator(); it.hasNext(); ) {
+        for (Iterator it = this.responseInterceptors.iterator();
+             it.hasNext(); ) {
             Object request = it.next();
             if (request.getClass().equals(clazz)) {
                 it.remove();
@@ -146,7 +149,8 @@
     }
     
      public final
-            void addInterceptor(final HttpRequestInterceptor interceptor, int index) {
+            void addInterceptor(final HttpRequestInterceptor interceptor,
+                                int index) {
         addRequestInterceptor(interceptor, index);
     }
     
@@ -197,7 +201,8 @@
         addResponseInterceptor(interceptor);
     }
     
-    public final void addInterceptor(final HttpResponseInterceptor interceptor, int index)
{
+    public final void addInterceptor(final HttpResponseInterceptor interceptor,
+                                     int index) {
         addResponseInterceptor(interceptor, index);
     }
       
@@ -280,7 +285,8 @@
             throws IOException, HttpException {
         if (this.requestInterceptors != null) {
             for (int i = 0; i < this.requestInterceptors.size(); i++) {
-                HttpRequestInterceptor interceptor = (HttpRequestInterceptor) this.requestInterceptors.get(i);
+                HttpRequestInterceptor interceptor =
+                    (HttpRequestInterceptor) this.requestInterceptors.get(i);
                 interceptor.process(request, context);
             }
         }
@@ -293,7 +299,8 @@
             throws IOException, HttpException {
         if (this.responseInterceptors != null) {
             for (int i = 0; i < this.responseInterceptors.size(); i++) {
-                HttpResponseInterceptor interceptor = (HttpResponseInterceptor) this.responseInterceptors.get(i);
+                HttpResponseInterceptor interceptor =
+                    (HttpResponseInterceptor) this.responseInterceptors.get(i);
                 interceptor.process(response, context);
             }
         }
@@ -307,10 +314,12 @@
     public BasicHttpProcessor copy() {
         BasicHttpProcessor clone = new BasicHttpProcessor();
         if (this.requestInterceptors != null) {
-            clone.requestInterceptors = new ArrayList(this.requestInterceptors);
+            clone.requestInterceptors =
+                new ArrayList(this.requestInterceptors);
         }
         if (this.responseInterceptors != null) {
-            clone.responseInterceptors = new ArrayList(this.responseInterceptors);
+            clone.responseInterceptors =
+                new ArrayList(this.responseInterceptors);
         }
         return clone;
     }

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java?view=diff&rev=554589&r1=554588&r2=554589
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java
Mon Jul  9 03:05:05 2007
@@ -61,8 +61,9 @@
      * Inserts a request interceptor at the specified index.
      *
      * @param itcp      the request interceptor to add
-     * @param index     the index to insert the interceptor at 
-     *                  or MAX_INTEGER to insert last. 
+     * @param index     the index to insert the interceptor at.
+     *                  If the index exceeds the size of the list,
+     *                  the interceptor is appended at the end of the list.
      */
     void addRequestInterceptor(HttpRequestInterceptor itcp, int index);
     

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java?view=diff&rev=554589&r1=554588&r2=554589
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java
Mon Jul  9 03:05:05 2007
@@ -62,8 +62,9 @@
      * Inserts a response interceptor at the specified index.
      *
      * @param itcp      the response interceptor to add
-     * @param index     the index to insert the interceptor at 
-     *                  or MAX_INTEGER to insert last. 
+     * @param index     the index to insert the interceptor at.
+     *                  If the index exceeds the size of the list,
+     *                  the interceptor is appended at the end of the list.
      */
     void addResponseInterceptor(HttpResponseInterceptor itcp, int index);
     



Mime
View raw message