geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r433318 - in /geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context: AbstractContext.java WritableContext.java
Date Mon, 21 Aug 2006 18:37:25 GMT
Author: dain
Date: Mon Aug 21 11:37:24 2006
New Revision: 433318

URL: http://svn.apache.org/viewvc?rev=433318&view=rev
Log:
Pulled up removeBinding method from WritableContext to AbstractContext

Modified:
    geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
    geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java

Modified: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java?rev=433318&r1=433317&r2=433318&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
Mon Aug 21 11:37:24 2006
@@ -177,7 +177,29 @@
     //  Remove Binding
     //
 
-    protected abstract void removeBindings(Name name) throws NamingException;
+    protected abstract void removeBinding(String name) throws NamingException;
+
+    protected void removeBindings(Name name) throws NamingException {
+        if (name.size() == 1) {
+            removeBinding(name.get(0));
+            return;
+        }
+
+        Context context = this;
+        for (int i = 0; i < name.size() - 1; i++) {
+            String segment = name.get(i);
+            Object object = context.lookup(segment);
+            if (object == null) {
+                throw new NotContextException("The intermediate context " + segment + " does
not exist");
+            } else if (!(object instanceof Context)) {
+                throw new NotContextException("The intermediate context " + segment + " does
is not a context");
+            } else {
+                context = (Context) object;
+            }
+        }
+
+        context.unbind(name.getSuffix(name.size() - 1));
+    }
 
     //
     // Environment

Modified: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java?rev=433318&r1=433317&r2=433318&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
Mon Aug 21 11:37:24 2006
@@ -17,12 +17,10 @@
 package org.apache.xbean.naming.context;
 
 import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NamingException;
 import javax.naming.NameAlreadyBoundException;
-import javax.naming.LinkRef;
-import java.util.Map;
+import javax.naming.NamingException;
 import java.util.HashMap;
+import java.util.Map;
 
 /**
  * @version $Rev$ $Date$
@@ -44,53 +42,23 @@
         return new WritableContext(getNameInNamespace(path));
     }
 
-    protected void removeBindings(Name name) throws NamingException {
-        Map bindings;
-        synchronized (this.bindings) {
-            bindings = this.bindings;
-        }
-        if (name.size() == 1) {
-            synchronized (bindings) {
-                bindings.remove(name.toString());
-            }
-        } else {
-            String segment = null;
-            int lastIndex = name.size() - 1;
-            Object terminalContext = null;
-            for (int i = 0; i < lastIndex; i++) {
-                segment = name.get(i);
-                terminalContext = bindings.get(segment);
-                if (terminalContext == null) {
-                    throw new NamingException("The intermediate context "
-                            + segment + " does not exist");
-                } else if (!(terminalContext instanceof Context)) {
-                    throw new NameAlreadyBoundException(
-                            " An object that is not a context is already bound at element
"
-                                    + segment + "of name " + name);
-                } else {
-                    WritableContext writableContext = ((WritableContext) terminalContext);
-                    synchronized (writableContext.bindings) {
-                        bindings = writableContext.bindings;
-                    }
-                }
-            }
-            segment = name.get(lastIndex);
-            ((Context) terminalContext).unbind(segment);
-        }
+    protected Map getBindings() {
+        return bindings;
     }
 
     protected void addBinding(String name, Object value, boolean rebind) throws NamingException
{
         synchronized (bindings) {
-            if (rebind || bindings.get(name.toString()) == null) {
+            if (rebind || !bindings.containsKey(name)) {
                 bindings.put(name, value);
             } else {
-                throw new NameAlreadyBoundException("The name " + name
-                        + "is already bound");
+                throw new NameAlreadyBoundException("The name " + name + " is already bound");
             }
         }
     }
 
-    protected Map getBindings() {
-        return bindings;
+    protected void removeBinding(String name) throws NamingException {
+        synchronized (bindings) {
+            bindings.remove(name);
+        }
     }
 }



Mime
View raw message