geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r523560 - in /geronimo/server/trunk/modules/geronimo-webservices/src: main/java/org/apache/geronimo/webservices/saaj/SAAJUniverse.java test/java/org/apache/geronimo/webservices/saaj/SAAJUniverseTest.java
Date Thu, 29 Mar 2007 04:56:45 GMT
Author: gawor
Date: Wed Mar 28 21:56:44 2007
New Revision: 523560

URL: http://svn.apache.org/viewvc?view=rev&rev=523560
Log:
support nesting for saaj universe

Modified:
    geronimo/server/trunk/modules/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/saaj/SAAJUniverse.java
    geronimo/server/trunk/modules/geronimo-webservices/src/test/java/org/apache/geronimo/webservices/saaj/SAAJUniverseTest.java

Modified: geronimo/server/trunk/modules/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/saaj/SAAJUniverse.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/saaj/SAAJUniverse.java?view=diff&rev=523560&r1=523559&r2=523560
==============================================================================
--- geronimo/server/trunk/modules/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/saaj/SAAJUniverse.java
(original)
+++ geronimo/server/trunk/modules/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/saaj/SAAJUniverse.java
Wed Mar 28 21:56:44 2007
@@ -16,6 +16,9 @@
  */
 package org.apache.geronimo.webservices.saaj;
 
+import java.util.LinkedList;
+import java.util.List;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -29,39 +32,39 @@
     public static final Type SUN = Type.SUN;
     public static final Type AXIS1 = Type.AXIS1;
     public static final Type AXIS2 = Type.AXIS2;
-
-    private Type oldUniverse;
-    private boolean universeSet = false;
-    
-    private static ThreadLocal<Type> currentUniverse = new InheritableThreadLocal<Type>();
     
+    private static final ThreadLocal<LinkedList<Type>> currentUniverse = 
+        new InheritableThreadLocal<LinkedList<Type>>();
+        
     public void set(Type newUniverse) {
-        if (this.universeSet) {
-            throw new RuntimeException("Universe must be unset first");
-        } else {
-            this.oldUniverse = getCurrentUniverse();
-            setCurrentUniverse(newUniverse);   
-            this.universeSet = true;            
-            LOG.debug("Set universe: " + this + " " + newUniverse);
+        LinkedList<Type> universeList = currentUniverse.get();
+        if (universeList == null) {
+            universeList = new LinkedList<Type>();
+            currentUniverse.set(universeList);
+        }
+        universeList.add(newUniverse);
+        if (LOG.isDebugEnabled()) {                   
+            LOG.debug("Set universe: " + Thread.currentThread() + " " + newUniverse);
         }
     }
     
     public void unset() {
-        if (this.universeSet) {
-            setCurrentUniverse(this.oldUniverse);
-            this.universeSet = false;
-            LOG.debug("Restored universe: " + this);
-        } else {
-            LOG.warn("Universe was not set: " + this);
+        LinkedList<Type> universeList = currentUniverse.get();
+        if (universeList != null && !universeList.isEmpty()) {
+            universeList.removeLast();
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Restored universe: " + Thread.currentThread());
+            }
         }
     }
     
     static Type getCurrentUniverse() {
-        return currentUniverse.get();
-    }
-    
-    static void setCurrentUniverse(Type universe) {
-        currentUniverse.set(universe);
+        LinkedList<Type> universeList = currentUniverse.get();
+        if (universeList != null && !universeList.isEmpty()) {
+            return universeList.getLast();
+        } else {
+            return null;
+        }                
     }
-   
+       
 }

Modified: geronimo/server/trunk/modules/geronimo-webservices/src/test/java/org/apache/geronimo/webservices/saaj/SAAJUniverseTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-webservices/src/test/java/org/apache/geronimo/webservices/saaj/SAAJUniverseTest.java?view=diff&rev=523560&r1=523559&r2=523560
==============================================================================
--- geronimo/server/trunk/modules/geronimo-webservices/src/test/java/org/apache/geronimo/webservices/saaj/SAAJUniverseTest.java
(original)
+++ geronimo/server/trunk/modules/geronimo-webservices/src/test/java/org/apache/geronimo/webservices/saaj/SAAJUniverseTest.java
Wed Mar 28 21:56:44 2007
@@ -24,6 +24,9 @@
 
     private static final String SUN_MESSAGE_CLASS = 
         "com.sun.xml.messaging.saaj.soap.ver1_1.Message1_1Impl";
+
+    private static final String AXIS1_MESSAGE_CLASS = 
+        "org.apache.axis.Message";
     
     private static final String DEFAULT_MESSAGE_CLASS = SUN_MESSAGE_CLASS;
        
@@ -50,9 +53,41 @@
         
         // case 4, Axis1 universe set        
         u.set(SAAJUniverse.AXIS1);        
-        assertEquals("org.apache.axis.Message", 
+        assertEquals(AXIS1_MESSAGE_CLASS,
                      MessageFactory.newInstance().createMessage().getClass().getName());
       
         u.unset();       
+    }
+
+    public void testNested() throws Exception {
+        SAAJGBean b = new SAAJGBean();
+        b.doStart();
+
+        assertEquals(DEFAULT_MESSAGE_CLASS, 
+                     MessageFactory.newInstance().createMessage().getClass().getName());
+        
+        SAAJUniverse u = new SAAJUniverse();
+
+        // set axis1
+        u.set(SAAJUniverse.AXIS1);        
+        assertEquals(AXIS1_MESSAGE_CLASS,
+                     MessageFactory.newInstance().createMessage().getClass().getName());
 
+        
+        // set sun, nested
+        u.set(SAAJUniverse.SUN);
+        assertEquals(SUN_MESSAGE_CLASS, 
+                     MessageFactory.newInstance().createMessage().getClass().getName());
  
+
+        // unset sun
+        u.unset();
+
+        // should be axis
+        assertEquals(AXIS1_MESSAGE_CLASS,
+                     MessageFactory.newInstance().createMessage().getClass().getName());
 
+
+        u.unset();
+
+        assertEquals(DEFAULT_MESSAGE_CLASS, 
+                     MessageFactory.newInstance().createMessage().getClass().getName());
     }
 
 }



Mime
View raw message