cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andreasm...@apache.org
Subject svn commit: r507913 - in /incubator/cxf/trunk/api/src: main/java/org/apache/cxf/phase/PhaseInterceptorChain.java test/java/org/apache/cxf/phase/PhaseInterceptorChainTest.java
Date Thu, 15 Feb 2007 12:13:17 GMT
Author: andreasmyth
Date: Thu Feb 15 04:13:16 2007
New Revision: 507913

URL: http://svn.apache.org/viewvc?view=rev&rev=507913
Log:
Changed semantics of PhaseInterceptorChain.add(interceptor, false) from "Don't add the interceptor
if it is already on the chain" to "Don't add the interceptor if another phase interceptor
with the same id is already on the chain".

Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
    incubator/cxf/trunk/api/src/test/java/org/apache/cxf/phase/PhaseInterceptorChainTest.java

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java?view=diff&rev=507913&r1=507912&r2=507913
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
(original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
Thu Feb 15 04:13:16 2007
@@ -33,6 +33,7 @@
 import java.util.logging.Logger;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.interceptor.InterceptorChain;
 import org.apache.cxf.message.Message;
@@ -100,7 +101,6 @@
         add(i, false);
     }
     
-    @SuppressWarnings("unchecked")
     public void add(Interceptor i, boolean force) {
         PhaseInterceptor pi = (PhaseInterceptor)i;
 
@@ -114,7 +114,8 @@
         if (phase == null) {
             LOG.fine("Phase " + phaseName + " does not exist. Skipping handler "
                       + i.getClass().getName());
-        } else if (force | !phase.contains(pi)) {            
+        } else if (force 
+            | !containsType(CastUtils.cast(phase, PhaseInterceptor.class), pi.getId())) {
           
             insertInterceptor(phase, pi);
         }
     }
@@ -366,6 +367,15 @@
         }
     }
     
+    boolean containsType(List<PhaseInterceptor> phase, String id) {
+        for (PhaseInterceptor pi : phase) {
+            if (id.equals(pi.getId())) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
     class PhaseInterceptorIterator implements ListIterator<Interceptor<? extends Message>>
{
         List<Interceptor<? extends Message>> called
             = new ArrayList<Interceptor<? extends Message>>();
@@ -487,5 +497,7 @@
     public void setFaultObserver(MessageObserver faultObserver) {
         this.faultObserver = faultObserver;
     }
+    
+    
 
 }

Modified: incubator/cxf/trunk/api/src/test/java/org/apache/cxf/phase/PhaseInterceptorChainTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/test/java/org/apache/cxf/phase/PhaseInterceptorChainTest.java?view=diff&rev=507913&r1=507912&r2=507913
==============================================================================
--- incubator/cxf/trunk/api/src/test/java/org/apache/cxf/phase/PhaseInterceptorChainTest.java
(original)
+++ incubator/cxf/trunk/api/src/test/java/org/apache/cxf/phase/PhaseInterceptorChainTest.java
Thu Feb 15 04:13:16 2007
@@ -69,10 +69,12 @@
         assertTrue(!it.hasNext());
     }
     
-    public void testForceAddOneInterceptor() {
+    public void testForceAddSameInterceptor() {
+
         AbstractPhaseInterceptor p = setUpPhaseInterceptor("phase1", "p1");
         control.replay();
         chain.add(p, false);
+        chain.add(p, false);
         Iterator<Interceptor<? extends Message>> it = chain.iterator();
         assertSame(p, it.next());
         assertTrue(!it.hasNext());
@@ -80,7 +82,24 @@
         it = chain.iterator();
         assertSame(p, it.next());
         assertSame(p, it.next());
-        assertTrue(!it.hasNext());        
+        assertTrue(!it.hasNext()); 
+    }
+    
+    public void testForceAddSameInterceptorType() {
+
+        AbstractPhaseInterceptor p1 = setUpPhaseInterceptor("phase1", "p1");
+        AbstractPhaseInterceptor p2 = setUpPhaseInterceptor("phase1", "p1");
+        control.replay();
+        chain.add(p1, false);
+        chain.add(p2, false);
+        Iterator<Interceptor<? extends Message>> it = chain.iterator();
+        assertSame(p1, it.next());
+        assertTrue(!it.hasNext());
+        chain.add(p2, true);
+        it = chain.iterator();
+        assertSame(p2, it.next());
+        assertSame(p1, it.next());
+        assertTrue(!it.hasNext()); 
     }
 
     @SuppressWarnings("unchecked")



Mime
View raw message