geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r433326 - /geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
Date Mon, 21 Aug 2006 19:03:52 GMT
Author: dain
Date: Mon Aug 21 12:03:52 2006
New Revision: 433326

URL: http://svn.apache.org/viewvc?rev=433326&view=rev
Log:
Consolidated common lookup code in AbstractContext

Modified:
    geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.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=433326&r1=433325&r2=433326&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 12:03:52 2006
@@ -126,6 +126,18 @@
         throw new NameNotFoundException(stringName);
     }
 
+    protected Context lookupFinalContext(Name name) throws NamingException {
+        Object value = lookup(name.getPrefix(name.size() - 1));
+
+        if (value == null) {
+            throw new NotContextException("The intermediate context " + name.get(name.size()
- 1) + " does not exist");
+        } else if (!(value instanceof Context)) {
+            throw new NotContextException("The intermediate context " + name.get(name.size()
- 1) + " does is not a context");
+        } else {
+            return (Context) value;
+        }
+    }
+
     //
     //  List Bindings
     //
@@ -149,18 +161,7 @@
             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 context = lookupFinalContext(name);
 
         String lastSegment = name.get(name.size() - 1);
         if (rebind) {
@@ -185,18 +186,7 @@
             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 context = lookupFinalContext(name);
 
         context.unbind(name.getSuffix(name.size() - 1));
     }



Mime
View raw message