geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r776890 - in /geronimo/xbean/trunk/xbean-naming/src: main/java/org/apache/xbean/naming/context/WritableContext.java test/java/org/apache/xbean/naming/context/ReferenceableTest.java
Date Wed, 20 May 2009 22:44:15 GMT
Author: djencks
Date: Wed May 20 22:44:15 2009
New Revision: 776890

URL: http://svn.apache.org/viewvc?rev=776890&view=rev
Log:
XBEAN-127 be more cautious about binding References from Referenceable

Modified:
    geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
    geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ReferenceableTest.java

Modified: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java?rev=776890&r1=776889&r2=776890&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
Wed May 20 22:44:15 2009
@@ -19,6 +19,7 @@
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Hashtable;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
@@ -28,6 +29,8 @@
 import javax.naming.NameAlreadyBoundException;
 import javax.naming.NamingException;
 import javax.naming.Referenceable;
+import javax.naming.Reference;
+import javax.naming.spi.NamingManager;
 
 import org.apache.xbean.naming.reference.CachingReference;
 
@@ -85,7 +88,18 @@
 
     protected void addBinding(AtomicReference<Map<String, Object>> bindingsRef,
String name, String nameInNamespace, Object value, boolean rebind) throws NamingException
{
         if (value instanceof Referenceable) {
-            value = ((Referenceable)value).getReference();
+            Reference ref = ((Referenceable)value).getReference();
+            if (ref != null) {
+                try {
+                    Object o = NamingManager.getObjectInstance(ref, null, null, new Hashtable());
+                    if (!value.equals(o)) {
+                        value = ref;
+                    }
+                } catch (Exception e) {
+                    //don't try to bind reference
+                }
+            }
+
         }
         if (cacheReferences) {
             value = CachingReference.wrapReference(getNameInNamespace(name), value);

Modified: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ReferenceableTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ReferenceableTest.java?rev=776890&r1=776889&r2=776890&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ReferenceableTest.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ReferenceableTest.java
Wed May 20 22:44:15 2009
@@ -38,7 +38,7 @@
         context.bind("bar/foo1", foo1);
         Object o1 = context.lookup("bar/foo1");
         assertEquals(foo1, o1);
-        assertNotSame(foo1, o1);
+//        assertNotSame(foo1, o1);
     }
     public void testReferenceable2() throws Exception {
         Context context = new WritableContext();



Mime
View raw message