geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r761803 - in /geronimo/xbean/trunk/xbean-naming/src: main/java/org/apache/xbean/naming/context/ test/java/org/apache/xbean/naming/context/
Date Fri, 03 Apr 2009 21:24:27 GMT
Author: djencks
Date: Fri Apr  3 21:24:26 2009
New Revision: 761803

URL: http://svn.apache.org/viewvc?rev=761803&view=rev
Log:
XBEAN-125 fix nameInNamespace handling for writable context, add some tests for it and immutable
context

Modified:
    geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
    geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractFederatedContext.java
    geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java
    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/ImmutableContextTest.java
    geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/WritableContextTest.java

Modified: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java?rev=761803&r1=761802&r2=761803&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
Fri Apr  3 21:24:26 2009
@@ -110,12 +110,6 @@
         }
         if (stringName == null) stringName = parsedName.toString();
 
-        // If the name starts with our name in namespace strip it off
-        // This works because the name in namespace is assumed to be absolute
-        if (stringName.startsWith(nameInNamespace)) {
-            stringName = stringName.substring(nameInNamespace.length());
-        }
-
         // try to look up the name directly (this is the fastest path)
         Object directLookup = getDeepBinding(stringName);
         if (directLookup != null) {

Modified: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractFederatedContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractFederatedContext.java?rev=761803&r1=761802&r2=761803&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractFederatedContext.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractFederatedContext.java
Fri Apr  3 21:24:26 2009
@@ -45,10 +45,10 @@
         this.contextFederation = new ContextFederation(this);
     }
 
-    public AbstractFederatedContext(AbstractFederatedContext masterContext, String path)
throws NamingException {
-        super(masterContext.getNameInNamespace(path), masterContext.getContextAccess());
+    public AbstractFederatedContext(AbstractFederatedContext masterContext, String nameInNamespace)
throws NamingException {
+        super(nameInNamespace, masterContext.getContextAccess());
         this.masterContext = masterContext;
-        this.contextFederation = this.masterContext.contextFederation.createSubcontextFederation(path,
this);
+        this.contextFederation = this.masterContext.contextFederation.createSubcontextFederation(nameInNamespace,
this);
     }
 
     protected Object faultLookup(String stringName, Name parsedName) {

Modified: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java?rev=761803&r1=761802&r2=761803&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java
Fri Apr  3 21:24:26 2009
@@ -248,7 +248,7 @@
                 // recursive call create bindings to cause building the context depth first
                 String path = nameInNameSpace == null ? name : nameInNameSpace + "/" + name;
 
-                Map nestedBindings = createBindings(path, nestedNode, factory);
+                Map<String, Object> nestedBindings = createBindings(path, nestedNode,
factory);
                 Context nestedContext = factory.createNestedSubcontext(path, nestedBindings);
                 bindings.put(name, nestedContext);
             } else {

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=761803&r1=761802&r2=761803&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
Fri Apr  3 21:24:26 2009
@@ -163,7 +163,10 @@
     }
 
     public Context createNestedSubcontext(String path, Map<String, Object> bindings)
throws NamingException {
-        return new NestedWritableContext(path,bindings);
+        if (getNameInNamespace().length() > 0) {
+            path = getNameInNamespace() + "/" + path;
+        }
+        return new NestedWritableContext(path, bindings);
     }
 
     private static Map<String, Object> buildIndex(String nameInNamespace, Map<String,
Object> bindings) {
@@ -212,7 +215,7 @@
         }
 
         public Context createNestedSubcontext(String path, Map<String, Object> bindings)
throws NamingException {
-            return new NestedWritableContext(path, bindings);
+            return new NestedWritableContext(getNameInNamespace(path), bindings);
         }
 
         protected Object getDeepBinding(String name) {

Modified: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ImmutableContextTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ImmutableContextTest.java?rev=761803&r1=761802&r2=761803&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ImmutableContextTest.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ImmutableContextTest.java
Fri Apr  3 21:24:26 2009
@@ -27,16 +27,49 @@
     private static final String STRING_VAL = "some string";
 
     public void testBasic() throws Exception {
-        Map map = new HashMap();
+        Map<String, Object> map = new HashMap<String, Object>();
         map.put("string", STRING_VAL);
         map.put("nested/context/string", STRING_VAL);
         map.put("a/b/c/d/e/string", STRING_VAL);
-        map.put("a/b/c/d/e/one", new Integer(1));
-        map.put("a/b/c/d/e/two", new Integer(2));
-        map.put("a/b/c/d/e/three", new Integer(3));
+        map.put("a/b/c/d/e/one", 1);
+        map.put("a/b/c/d/e/two", 2);
+        map.put("a/b/c/d/e/three", 3);
+        map.put("a/a/b/c/d/e/three", 3);
+        map.put("a/b/b/c/d/e/three", 3);
 
         Context context = new ImmutableContext(map);
 
         assertEq(map, context);
+
+        assertEquals("a", ((Context)context.lookup("a")).getNameInNamespace());
+        assertEquals("a/a", ((Context)context.lookup("a/a")).getNameInNamespace());
+        assertEquals("a/b/b", ((Context)context.lookup("a/b/b")).getNameInNamespace());
+        assertEquals("a/b", ((Context)context.lookup("a/b")).getNameInNamespace());
+        assertEquals("a/b/c", ((Context)context.lookup("a/b/c")).getNameInNamespace());
+        assertEquals("a/b/c/d", ((Context)context.lookup("a/b/c/d")).getNameInNamespace());
+        assertEquals("a/b/c/d/e", ((Context)context.lookup("a/b/c/d/e")).getNameInNamespace());
+
+    }
+
+    public void testNameInNamespace() throws Exception {
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put("string", STRING_VAL);
+        map.put("nested/context/string", STRING_VAL);
+        map.put("a/b/c/d/e/string", STRING_VAL);
+        map.put("a/b/c/d/e/one", 1);
+        map.put("a/b/c/d/e/two", 2);
+        map.put("a/b/c/d/e/three", 3);
+        map.put("a/a/b/c/d/e/three", 3);
+        map.put("a/b/b/c/d/e/three", 3);
+
+        Context context = new ImmutableContext("a", map, false);
+        assertEquals("a/a", ((Context)context.lookup("a")).getNameInNamespace());
+        assertEquals("a/a/a", ((Context)context.lookup("a/a")).getNameInNamespace());
+        assertEquals("a/a/b/b", ((Context)context.lookup("a/b/b")).getNameInNamespace());
+        assertEquals("a/a/b", ((Context)context.lookup("a/b")).getNameInNamespace());
+        assertEquals("a/a/b/c", ((Context)context.lookup("a/b/c")).getNameInNamespace());
+        assertEquals("a/a/b/c/d", ((Context)context.lookup("a/b/c/d")).getNameInNamespace());
+        assertEquals("a/a/b/c/d/e", ((Context)context.lookup("a/b/c/d/e")).getNameInNamespace());
+
     }
 }

Modified: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/WritableContextTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/WritableContextTest.java?rev=761803&r1=761802&r2=761803&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/WritableContextTest.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/WritableContextTest.java
Fri Apr  3 21:24:26 2009
@@ -23,6 +23,8 @@
 import javax.naming.NameAlreadyBoundException;
 import javax.naming.InvalidNameException;
 import javax.naming.ContextNotEmptyException;
+import javax.naming.NamingException;
+
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -971,4 +973,38 @@
         }
     }
 
+    public void test2PathsCreateSubcontext() throws Exception {
+        WritableContext w = new WritableContext();
+        doBind(w, "a/b/c", "c");
+        doBind(w, "a/b/b/c", "c");
+        assertEquals("a", ((Context)w.lookup("a")).getNameInNamespace());
+        assertEquals("a/b", ((Context)w.lookup("a/b")).getNameInNamespace());
+        assertEquals("a/b/b", ((Context)w.lookup("a/b/b")).getNameInNamespace());
+
+        w = new WritableContext("a");
+        doBind(w, "a/b/c", "c");
+        doBind(w, "a/b/b/c", "c");
+        assertEquals("a/a", ((Context)w.lookup("a")).getNameInNamespace());
+        assertEquals("a/a/b", ((Context)w.lookup("a/b")).getNameInNamespace());
+        assertEquals("a/a/b/b", ((Context)w.lookup("a/a/b/b")).getNameInNamespace());
+    }
+
+    private void doBind(Context context, String nameString, Object value) throws NamingException
{
+        Name name = context.getNameParser("").parse(nameString);
+        Context current = context;
+        for (int i = 0; i< name.size() - 1; i++) {
+            String part = name.get(i);
+            try {
+                Object o = current.lookup(part);
+                if (!(o instanceof Context)) {
+                    throw new NamingException("not a context at " + part +" found: " + o);
+                }
+                current = (Context) o;
+            } catch (NamingException e) {
+                current = current.createSubcontext(part);
+            }
+        }
+        current.bind(name.get(name.size() - 1), value);
+    }
+
 }



Mime
View raw message