geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r432439 - in /geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context: AbstractContext.java AbstractUnmodifiableContext.java
Date Fri, 18 Aug 2006 00:01:47 GMT
Author: dain
Date: Thu Aug 17 17:01:46 2006
New Revision: 432439

URL: http://svn.apache.org/viewvc?rev=432439&view=rev
Log:
Removed redundant lookup and list methods from AbstractUnmodifiableContext

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/AbstractUnmodifiableContext.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=432439&r1=432438&r2=432439&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
Thu Aug 17 17:01:46 2006
@@ -141,7 +141,16 @@
 
     public Object lookup(String name) throws NamingException {
         if (name == null) throw new NullPointerException("name is null");
-        return lookup(new CompositeName(name));
+
+        Object value = lookup(name, null);
+
+        // if we got a link back we need to resolve it
+        if (value instanceof LinkRef) {
+            LinkRef linkRef = (LinkRef) value;
+            value = lookup(linkRef.getLinkName());
+        }
+
+        return value;
     }
 
     public Object lookup(Name name) throws NamingException {
@@ -161,7 +170,7 @@
 
     public Object lookupLink(String name) throws NamingException {
         if (name == null) throw new NullPointerException("name is null");
-        return lookupLink(new CompositeName(name));
+        return lookup(name, null);
     }
 
     public Object lookupLink(Name name) throws NamingException {
@@ -237,38 +246,94 @@
     // List
     //
 
+    protected NamingEnumeration list() throws NamingException {
+        Map bindings = getBindings();
+        return new ContextUtil.ListEnumeration(bindings);
+    }
+
+    protected NamingEnumeration listBindings() throws NamingException {
+        Map bindings = getBindings();
+        return new ContextUtil.ListBindingEnumeration(bindings);
+    }
+
     public NamingEnumeration list(String name) throws NamingException {
         if (name == null) throw new NullPointerException("name is null");
-        return list(new CompositeName(name));
+
+        // if the name is empty, list the current context
+        if (name.length() == 0) {
+            return list();
+        }
+
+        // lookup the target context
+        Object target = lookup(name);
+
+        if (target == this) {
+            return list();
+        } else if (target instanceof Context) {
+            return ((Context) target).list("");
+        } else {
+            throw new NotContextException("The name " + name + " cannot be listed");
+        }
     }
 
     public NamingEnumeration list(Name name) throws NamingException {
         if (name == null) throw new NullPointerException("name is null");
+
+        // if the name is empty, list the current context
         if (name.isEmpty()) {
-            return new ContextUtil.ListEnumeration(getBindings());
+            return list();
         }
+
+        // lookup the target context
         Object target = lookup(name);
-        if (target instanceof Context) {
+
+        if (target == this) {
+            return list();
+        } else if (target instanceof Context) {
             return ((Context) target).list("");
+        } else {
+            throw new NotContextException("The name " + name + " cannot be listed");
         }
-        throw new NotContextException("The name " + name + " cannot be listed");
     }
 
     public NamingEnumeration listBindings(String name) throws NamingException {
         if (name == null) throw new NullPointerException("name is null");
-        return listBindings(new CompositeName(name));
+
+        // if the name is empty, list the current context
+        if (name.length() == 0) {
+            return listBindings();
+        }
+
+        // lookup the target context
+        Object target = lookup(name);
+
+        if (target == this) {
+            return listBindings();
+        } else if (target instanceof Context) {
+            return ((Context) target).listBindings("");
+        } else {
+            throw new NotContextException("The name " + name + " cannot be listed");
+        }
     }
 
     public NamingEnumeration listBindings(Name name) throws NamingException {
         if (name == null) throw new NullPointerException("name is null");
+
+        // if the name is empty, list the current context
         if (name.isEmpty()) {
-            return new ContextUtil.ListBindingEnumeration(getBindings());
+            return listBindings();
         }
+
+        // lookup the target context
         Object target = lookup(name);
-        if (target instanceof Context) {
+
+        if (target == this) {
+            return listBindings();
+        } else if (target instanceof Context) {
             return ((Context) target).listBindings("");
+        } else {
+            throw new NotContextException("The name " + name + " cannot be listed");
         }
-        throw new NotContextException("The name " + name + " cannot be listed");
     }
 
     //

Modified: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractUnmodifiableContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractUnmodifiableContext.java?rev=432439&r1=432438&r2=432439&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractUnmodifiableContext.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractUnmodifiableContext.java
Thu Aug 17 17:01:46 2006
@@ -23,7 +23,6 @@
 import javax.naming.LinkRef;
 import javax.naming.Name;
 import javax.naming.NameNotFoundException;
-import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.NotContextException;
 import javax.naming.OperationNotSupportedException;
@@ -157,16 +156,6 @@
         throw new OperationNotSupportedException("This context is not listable");
     }
 
-    protected NamingEnumeration list() throws NamingException {
-        Map bindings = getBindings();
-        return new ContextUtil.ListEnumeration(bindings);
-    }
-
-    protected NamingEnumeration listBindings() throws NamingException {
-        Map bindings = getBindings();
-        return new ContextUtil.ListBindingEnumeration(bindings);
-    }
-
     //
     //  Add Binding
     //
@@ -333,105 +322,6 @@
     // ==================================================================================
     // =================== Final Methods (see methods above) ============================
     // ==================================================================================
-
-    //
-    //  Lookup methods
-    //
-
-    public final Object lookup(String name) throws NamingException {
-        if (name == null) throw new NullPointerException("name is null");
-
-        Object value = lookup(name, null);
-
-        // if we got a link back we need to resolve it
-        if (value instanceof LinkRef) {
-            LinkRef linkRef = (LinkRef) value;
-            value = lookup(linkRef.getLinkName());
-        }
-        return value;
-    }
-
-    public final Object lookup(Name name) throws NamingException {
-        if (name == null) throw new NullPointerException("name is null");
-
-        Object value = lookup(null, name);
-
-        // if we got a link back we need to resolve it
-        if (value instanceof LinkRef) {
-            LinkRef linkRef = (LinkRef) value;
-            value = lookup(linkRef.getLinkName());
-        }
-
-        return value;
-    }
-
-    public final Object lookupLink(String name) throws NamingException {
-        if (name == null) throw new NullPointerException("name is null");
-
-        return lookup(name, null);
-    }
-
-    public final Object lookupLink(Name name) throws NamingException {
-        if (name == null) throw new NullPointerException("name is null");
-
-        return lookup(null, name);
-    }
-
-    //
-    //  List Operations
-    //
-
-    public final NamingEnumeration list(String name) throws NamingException {
-        if (name == null) throw new NullPointerException("name is null");
-
-        Object o = lookup(name);
-        if (o == this) {
-            return list();
-        } else if (o instanceof Context) {
-            return ((Context) o).list("");
-        } else {
-            throw new NotContextException();
-        }
-    }
-
-    public final NamingEnumeration listBindings(String name) throws NamingException {
-        if (name == null) throw new NullPointerException("name is null");
-
-        Object o = lookup(name);
-        if (o == this) {
-            return listBindings();
-        } else if (o instanceof Context) {
-            return ((Context) o).listBindings("");
-        } else {
-            throw new NotContextException();
-        }
-    }
-
-    public final NamingEnumeration list(Name name) throws NamingException {
-        if (name == null) throw new NullPointerException("name is null");
-
-        Object o = lookup(name);
-        if (o == this) {
-            return list();
-        } else if (o instanceof Context) {
-            return ((Context) o).list("");
-        } else {
-            throw new NotContextException();
-        }
-    }
-
-    public final NamingEnumeration listBindings(Name name) throws NamingException {
-        if (name == null) throw new NullPointerException("name is null");
-
-        Object o = lookup(name);
-        if (o == this) {
-            return listBindings();
-        } else if (o instanceof Context) {
-            return ((Context) o).listBindings("");
-        } else {
-            throw new NotContextException();
-        }
-    }
 
     //
     //  Unsupported Operations



Mime
View raw message