cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r618859 - in /incubator/cxf/branches/2.0.x-fixes: ./ api/src/main/java/org/apache/cxf/phase/PhaseInterceptor.java api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
Date Wed, 06 Feb 2008 02:50:31 GMT
Author: dkulp
Date: Tue Feb  5 18:50:27 2008
New Revision: 618859

URL: http://svn.apache.org/viewvc?rev=618859&view=rev
Log:
Merged revisions 615468 via svnmerge from 
https://svn.apache.org/repos/asf/incubator/cxf/trunk

........
  r615468 | gmazza | 2008-01-26 13:08:33 -0500 (Sat, 26 Jan 2008) | 1 line
  
  Simplified code and added comments to PhaseInterceptorChain.
........

Modified:
    incubator/cxf/branches/2.0.x-fixes/   (props changed)
    incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/phase/PhaseInterceptor.java
    incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java

Propchange: incubator/cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/phase/PhaseInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/phase/PhaseInterceptor.java?rev=618859&r1=618858&r2=618859&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/phase/PhaseInterceptor.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/phase/PhaseInterceptor.java
Tue Feb  5 18:50:27 2008
@@ -38,7 +38,7 @@
     /**
      * Returns a set of IDs specifying the interceptors that this interceptor should 
      * be placed after in the interceptor chain
-     * @return the ids of the interceptorsr
+     * @return the ids of the interceptors
      */
     Set<String> getAfter();
 

Modified: incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java?rev=618859&r1=618858&r2=618859&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
Tue Feb  5 18:50:27 2008
@@ -58,8 +58,16 @@
     private final Map<String, Integer> nameMap;
     private final Phase phases[];
 
+    // heads[phase] refers to the first interceptor of the given phase
     private InterceptorHolder heads[];
+    // tails[phase] refers to the last interceptor of the given phase
     private InterceptorHolder tails[];
+    // hasAfters[phase] indicates that the given phase has already inserted
+    // interceptors that may need to be placed after future to-be-inserted
+    // interceptors.  This flag is used to activate ordering of interceptors
+    // when new ones are added to the list for this phase.
+    // Note no hasBefores[] is needed because implementation adds subsequent
+    // interceptors to the end of the list by default.
     private boolean hasAfters[];
 
     
@@ -68,8 +76,9 @@
     private MessageObserver faultObserver;
     private PhaseInterceptorIterator iterator;
     
-    // currently one chain for one request/response, use below as signal to avoid duplicate
fault processing
-    // on nested calling of doIntercept(), which will throw same fault multi-times
+    // currently one chain for one request/response, use below as signal 
+    // to avoid duplicate fault processing on nested calling of
+    // doIntercept(), which will throw same fault multi-times
     private boolean faultOccurred;
     
     
@@ -370,8 +379,10 @@
     private void insertInterceptor(int phase, PhaseInterceptor interc, boolean force) {
         InterceptorHolder ih = new InterceptorHolder(interc, phase);
         if (heads[phase] == null) {
+            // no interceptors yet in this phase
             heads[phase] = ih;
             tails[phase] = ih;
+            hasAfters[phase] = !interc.getAfter().isEmpty();
             
             int idx = phase - 1;
             while (idx >= 0) {
@@ -381,7 +392,7 @@
                 --idx;
             }
             if (idx >= 0) {
-                //found something before us
+                //found something before us, in an earlier phase
                 ih.prev = tails[idx];
                 ih.next = tails[idx].next;
                 if (ih.next != null) {
@@ -404,46 +415,50 @@
                     heads[idx].prev = ih;
                 }
             }
-            hasAfters[phase] = !interc.getAfter().isEmpty();
-        } else {
+        } else { // this phase already has interceptors attached
         
+            // list of interceptors that the new interceptor should precede
             Set beforeList = interc.getBefore();
+
+            // list of interceptors that the new interceptor should be after
             Set afterList = interc.getAfter();
-            InterceptorHolder before = null;
-            InterceptorHolder after = null;
+            
+            // firstBefore will hold the first interceptor of a given phase
+            // that the interceptor to be added must precede
+            InterceptorHolder firstBefore = null;
+
+            // lastAfter will hold the last interceptor of a given phase
+            // that the interceptor to be added must come after
+            InterceptorHolder lastAfter = null;
             
             String id = interc.getId();
-            if (hasAfters[phase]
-                || !beforeList.isEmpty()) {
+            if (hasAfters[phase] || !beforeList.isEmpty()) {
             
                 InterceptorHolder ih2 = heads[phase];
                 while (ih2 != tails[phase].next) {
                     PhaseInterceptor cmp = ih2.interceptor;
                     String cmpId = cmp.getId();
-                    if (cmpId != null
-                        && before == null
+                    if (cmpId != null && firstBefore == null
                         && (beforeList.contains(cmpId)
                             || cmp.getAfter().contains(id))) {
-                        //first one we need to be before
-                        before = ih2;
+                        firstBefore = ih2;
                     } 
-                    if (cmpId != null 
-                        && afterList.contains(cmpId)) {
-                        after = ih2;
+                    if (cmpId != null && afterList.contains(cmpId)) {
+                        lastAfter = ih2;
                     }
-                    if (!force
-                        && cmpId.equals(id)) {
+                    if (!force && cmpId.equals(id)) {
+                        // interceptor is already in chain
                         return;
                     }
                     ih2 = ih2.next;
                 }
-                if (after == null
-                    && beforeList.contains("*")) {
-                    before = heads[phase];
+                if (lastAfter == null && beforeList.contains("*")) {
+                    firstBefore = heads[phase];
                 }
                 //System.out.print("Didn't skip: " + phase.toString());
                 //System.out.println("             " + interc.getId());
             } else if (!force) {
+                // skip interceptor if already in chain
                 InterceptorHolder ih2 = heads[phase];
                 while (ih2 != tails[phase].next) {
                     if (ih2.interceptor.getId().equals(id)) {
@@ -457,26 +472,25 @@
             }
             hasAfters[phase] |= !afterList.isEmpty();
             
-            if (before == null) {
-                //just add at the end
+            if (firstBefore == null) {
+                //just add new interceptor at the end
                 ih.prev = tails[phase];
-                if (tails[phase] != null) {
-                    ih.next = tails[phase].next;
-                    tails[phase].next = ih;
-                }
+                ih.next = tails[phase].next;
+                tails[phase].next = ih;
+                
                 if (ih.next != null) {
                     ih.next.prev = ih;
                 }
                 tails[phase] = ih;
             } else {
-                ih.prev = before.prev;
+                ih.prev = firstBefore.prev;
                 if (ih.prev != null) {
                     ih.prev.next = ih;
                 }
-                ih.next = before;
-                before.prev = ih;
+                ih.next = firstBefore;
+                firstBefore.prev = ih;
                 
-                if (heads[phase] == before) {
+                if (heads[phase] == firstBefore) {
                     heads[phase] = ih;
                 }
             }



Mime
View raw message