You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2009/07/11 02:02:03 UTC

svn commit: r793150 - in /geronimo/server/trunk/plugins/openejb/geronimo-openejb/src: main/java/org/apache/geronimo/openejb/DeepBindableContext.java test/java/org/apache/geronimo/openejb/DeepBindableContextTest.java

Author: djencks
Date: Sat Jul 11 00:02:03 2009
New Revision: 793150

URL: http://svn.apache.org/viewvc?rev=793150&view=rev
Log:
GERONIMO-4599 make the unbind used by openejb prune empty subcontexts

Added:
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/test/java/org/apache/geronimo/openejb/DeepBindableContextTest.java   (with props)
Modified:
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/DeepBindableContext.java

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/DeepBindableContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/DeepBindableContext.java?rev=793150&r1=793149&r2=793150&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/DeepBindableContext.java (original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/DeepBindableContext.java Sat Jul 11 00:02:03 2009
@@ -58,6 +58,10 @@
         addDeepBinding(new CompositeName(name), value, false, true);
     }
 
+    void removeDeepBinding(Name name) throws NamingException {
+        removeDeepBinding(name, true, false);
+    }
+
     public JndiFactory newJndiFactory() throws NamingException {
         return new XBeanJndiFactory();
     }
@@ -95,9 +99,14 @@
 
     class ContextWrapper implements Context {
         private final Context rootContext;
+        private final String shortPrefix;
+        private final String longPrefix;
+
 
-        ContextWrapper(Context rootContext) {
+        ContextWrapper(Context rootContext) throws NamingException {
             this.rootContext = rootContext;
+            shortPrefix = DeepBindableContext.this.getNameInNamespace();
+            longPrefix = "java:" + shortPrefix;
         }
 
         public Object lookup(Name name) throws NamingException {
@@ -113,10 +122,10 @@
         }
 
         public void bind(String name, Object value) throws NamingException {
-            if (name.startsWith("java:openejb/")) {
-                name = name.substring("java:openejb/".length());
-            } else if (name.startsWith("openejb/")) {
-                name = name.substring("openejb/".length());
+            if (name.startsWith(longPrefix + "/")) {
+                name = name.substring(longPrefix.length() + 1);
+            } else if (name.startsWith(shortPrefix + "/")) {
+                name = name.substring(shortPrefix.length() + 1);
             }
             addDeepBinding(name, value);
         }
@@ -130,12 +139,16 @@
         }
 
         public void unbind(Name name) throws NamingException {
-            rootContext.unbind(name);
+            if (name.get(0).equals(shortPrefix) || name.get(0).equals(longPrefix)) {
+                name = (Name) name.clone();
+                name.remove(0);
+            }
+            removeDeepBinding(name);
         }
 
-        public void unbind(String s) throws NamingException {
-            rootContext.unbind(s);
-        }
+        public void unbind(String name) throws NamingException {
+            unbind(getNameParser(name).parse(name));
+         }
 
         public void rename(Name name, Name name1) throws NamingException {
             rootContext.rename(name, name1);

Added: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/test/java/org/apache/geronimo/openejb/DeepBindableContextTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/test/java/org/apache/geronimo/openejb/DeepBindableContextTest.java?rev=793150&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/test/java/org/apache/geronimo/openejb/DeepBindableContextTest.java (added)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/test/java/org/apache/geronimo/openejb/DeepBindableContextTest.java Sat Jul 11 00:02:03 2009
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.geronimo.openejb;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.gjndi.GlobalContextGBean;
+import org.apache.xbean.naming.global.GlobalContextManager;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DeepBindableContextTest extends TestCase {
+    
+    public void testBindUnbind() throws Exception {
+        System.setProperty("java.naming.factory.initial", "org.apache.xbean.naming.global.GlobalContextManager");
+        GlobalContextGBean globalContext = new GlobalContextGBean(null);
+        GlobalContextManager.setGlobalContext(globalContext);
+        DeepBindableContext context = new DeepBindableContext("openejb", false, true, false, false);
+        globalContext.bind("openejb", context);
+
+        Context contextWrapper = context.newJndiFactory().createRootContext();
+        testBindUnbind(context, contextWrapper, "openejb/foo/bar", "");
+        testBindUnbind(context, contextWrapper, "java:openejb/foo/bar", "java:");
+
+    }
+
+    private void testBindUnbind(DeepBindableContext context, Context contextWrapper, String s, String prefix) throws NamingException {
+        contextWrapper.bind(s, "bar");
+        assertEquals("bar", context.lookup(s.substring(prefix.length())));
+        contextWrapper.unbind(s);
+        try {
+            context.lookup(s);
+            fail(s + "should not be bound");
+        } catch (NamingException ne) {
+            //expected
+        }
+    }
+}

Propchange: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/test/java/org/apache/geronimo/openejb/DeepBindableContextTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/test/java/org/apache/geronimo/openejb/DeepBindableContextTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/test/java/org/apache/geronimo/openejb/DeepBindableContextTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain