geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r433366 - in /geronimo/xbean/branches/colossus/xbean-naming/src: main/java/org/apache/xbean/naming/context/ test/java/org/apache/xbean/naming/context/
Date Mon, 21 Aug 2006 21:27:40 GMT
Author: dain
Date: Mon Aug 21 14:27:38 2006
New Revision: 433366

URL: http://svn.apache.org/viewvc?rev=433366&view=rev
Log:
Pulled up support for automatic creation of intermediate contexts in deep bind from AbstractUnmodifiableContext.

Added:
    geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/NestedContextFactory.java
      - copied, changed from r433303, geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFactory.java
Removed:
    geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFactory.java
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
    geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java
    geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java
    geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/UnmodifiableContext.java
    geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/WritableContext.java
    geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/UnmodifiableContextTest.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=433366&r1=433365&r2=433366&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 14:27:38 2006
@@ -33,7 +33,7 @@
 import java.util.Hashtable;
 import java.util.Map;
 
-public abstract class AbstractContext implements Context, ContextFactory, Serializable {
+public abstract class AbstractContext implements Context, NestedContextFactory, Serializable
{
     private static final long serialVersionUID = 6481918425692261483L;
     private final String nameInNamespace;
 
@@ -155,24 +155,146 @@
     //  Add Binding
     //
 
-    protected void addDeepBinding(Name name, Object value, boolean rebind) throws NamingException
{
+    protected void addDeepBinding(Name name, Object value, boolean rebind, boolean createIntermediateContexts)
throws NamingException {
+        if (name == null) throw new NullPointerException("name is null");
+        if (value == null) throw new NullPointerException("value is null");
+
+        if (name.isEmpty()) {
+            throw new InvalidNameException("Name is empty");
+        }
+
         if (name.size() == 1) {
             addBinding(name.get(0), value, rebind);
             return;
         }
 
-        Context context = lookupFinalContext(name);
+        if (!createIntermediateContexts) {
+            Context context = lookupFinalContext(name);
 
-        String lastSegment = name.get(name.size() - 1);
-        if (rebind) {
-            context.rebind(lastSegment, value);
+            String lastSegment = name.get(name.size() - 1);
+            if (rebind) {
+                context.rebind(lastSegment, value);
+            } else {
+                context.bind(lastSegment, value);
+            }
         } else {
-            context.bind(lastSegment, value);
+            Context currentContext = this;
+            for (int i = 0; i < name.size(); i++) {
+                String part = name.get(i);
+
+                // empty path parts are not allowed
+                if (part.length() == 0) {
+                    // this could be supported but it would be tricky
+                    throw new InvalidNameException("Name part " + i + " is empty: " + name);
+                }
+
+                // Is this the last element in the name?
+                if (i == name.size() - 1) {
+                    // we're at the end... (re)bind the value into the parent context
+                    addBinding(currentContext, part, value, rebind);
+
+                    // all done... this is redundant but makes the code more readable
+                    break;
+                } else {
+                    Object currentValue = getBinding(currentContext, part);
+                    if (currentValue == null) {
+                        if (createIntermediateContexts) {
+                            // the next step in the tree is not present, so create everything
down
+                            // and add it to the current bindings
+                            Context subcontext = createSubcontextTree(name.getPrefix(i).toString(),
name.getSuffix(i), value);
+                            addBinding(currentContext, part, subcontext, rebind);
+
+                            // all done
+                            break;
+                        } else {
+                            throw new NotContextException("The intermediate context " + name.get(name.size()
- 1) + " does not exist");
+                        }
+                    } else {
+                        // the current value must be a nested subcontext
+                        if (!isNestedSubcontext(currentValue)) {
+                            throw new NotContextException("Expected a nested subcontext to
be bound at " +
+                                    part + " but found an instance of " + currentValue.getClass().getName());
+                        }
+                        currentContext = (Context) currentValue;
+                        // now we recurse into the current context
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Gets the value bound to the specified name within the specified context.  If the specified
context is an
+     * AbstractContext this method will call the faster getBinding method, otherwise it will
call lookup.
+     *
+     * @param context the context to get the binding from
+     * @param name the binding name
+     * @return the bound value or null if no value was bound
+     */
+    private static Object getBinding(Context context, String name) {
+        try {
+            if (context instanceof AbstractContext) {
+                AbstractContext abstractContext = (AbstractContext) context;
+                Object value = abstractContext.getBinding(name);
+                return value;
+            } else {
+                Object value = context.lookup(name);
+                return value;
+            }
+        } catch (NamingException e) {
+            return null;
+        }
+    }
+
+    /**
+     * Gets the value bound to the specified name within the specified context.  If the specified
context is an
+     * AbstractContext this method will call the faster getBinding method, otherwise it will
call lookup.
+     *
+     * @param context the context to get the binding from
+     * @param name the binding name
+     * @param value the value to bind
+     * @param rebind if true, this method will replace any exsiting binding, otherwise a
NamingException will be thrown
+     * @throws NamingException
+     */
+    private static void addBinding(Context context, String name, Object value, boolean rebind)
throws NamingException {
+        if (context instanceof AbstractContext) {
+            AbstractContext abstractContext = (AbstractContext) context;
+            abstractContext.addBinding(name, value, rebind);
+        } else {
+            if (rebind) {
+                context.rebind(name, value);
+            } else {
+                context.bind(name, value);
+            }
         }
     }
 
     protected abstract void addBinding(String name, Object value, boolean rebind) throws
NamingException;
 
+    /**
+     * Creates a context tree which will be rooted at the specified path and contain a single
entry located down
+     * a path specified by the name.  All necessary intermediate contexts will be created
using the createContext method.
+     * @param path the path to the context that will contains this context
+     * @param name the name under which the value should be bound
+     * @param value the vale
+     * @return a context with the value bound at the specified name
+     * @throws NamingException
+     */
+    protected Context createSubcontextTree(String path, Name name, Object value) throws NamingException
{
+        if (path == null) throw new NullPointerException("path is null");
+        if (name == null) throw new NullPointerException("name is null");
+        if (name.size() < 2) throw new InvalidNameException("name must have at least 2
parts " + name);
+
+        if (!path.endsWith("/")) path += "/";
+
+        for (int i = name.size() - 2; i >= 0; i--) {
+            String fullPath = path + name.getSuffix(i);
+            String key = name.get(i + 1);
+            value = createNestedSubcontext(fullPath, Collections.singletonMap(key, value));
+        }
+        return (Context) value;
+    }
+
 
     //
     //  Remove Binding
@@ -337,7 +459,7 @@
         if (name.isEmpty()) {
             throw new NameAlreadyBoundException("Cannot bind to an empty name (this context)");
         }
-        addDeepBinding(name, obj, false);
+        addDeepBinding(name, obj, false, true);
     }
 
     public void rebind(String name, Object obj) throws NamingException {
@@ -350,7 +472,7 @@
         if (name.isEmpty()) {
             throw new NameAlreadyBoundException("Cannot rebind an empty name (this context)");
         }
-        addDeepBinding(name, obj, true);
+        addDeepBinding(name, obj, true, true);
     }
 
     public void rename(String oldName, String newName) throws NamingException {
@@ -492,8 +614,8 @@
         if (name.isEmpty()) {
             throw new InvalidNameException("Cannot create a subcontext if the name is empty");
         }
-        Context abstractContext = createContext(name.toString(), Collections.EMPTY_MAP);
-        addDeepBinding(name, abstractContext, false);
+        Context abstractContext = createNestedSubcontext(name.toString(), Collections.EMPTY_MAP);
+        addDeepBinding(name, abstractContext, false, true);
         return abstractContext;
     }
 

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=433366&r1=433365&r2=433366&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
Mon Aug 21 14:27:38 2006
@@ -24,13 +24,12 @@
 import javax.naming.NotContextException;
 import javax.naming.OperationNotSupportedException;
 import java.io.Serializable;
-import java.util.Collections;
 import java.util.Map;
 
 /**
  * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $
  */
-public abstract class AbstractUnmodifiableContext extends AbstractContext implements Context,
ContextFactory, Serializable {
+public abstract class AbstractUnmodifiableContext extends AbstractContext implements Context,
NestedContextFactory, Serializable {
     private static final long serialVersionUID = 3808693663629444493L;
 
     protected AbstractUnmodifiableContext(String nameInNamespace) {
@@ -96,93 +95,6 @@
      */
     protected Map getBindings() throws NamingException {
         throw new OperationNotSupportedException("This context is not listable");
-    }
-
-    //
-    //  Add Binding
-    //
-
-    protected void addDeepBinding(Name name, Object value, boolean rebind) throws NamingException
{
-        if (rebind) {
-            throw new OperationNotSupportedException("This conext does not support rebind");
-        }
-        addDeepBinding(name.toString(), value);
-    }
-
-    protected void addDeepBinding(String name, Object value) throws NamingException {
-        if (name == null) throw new NullPointerException("name is null");
-        if (value == null) throw new NullPointerException("value is null");
-
-        Name compoundName = ContextUtil.parseName(name);
-        if (compoundName.isEmpty()) {
-            throw new InvalidNameException("Name is empty");
-        }
-
-        AbstractUnmodifiableContext currentContext = this;
-        for (int i = 0; i < compoundName.size(); i++) {
-            String part = compoundName.get(i);
-
-            // empty path parts are not allowed
-            if (part.length() == 0) {
-                throw new InvalidNameException("Name part " + i + " is empty: " + name);
-            }
-
-            // Is this the last element in the name?
-            if (i == compoundName.size() - 1) {
-                // we're at the end... bind the value into the parent context
-                currentContext.addBinding(part, value, false);
-
-                // all done... this is redundant but makes the code more readable
-                break;
-            } else {
-                Map currentBindings = currentContext.getBindings();
-                Object currentValue = currentBindings.get(part);
-                if (currentValue == null) {
-                    // the next step in the tree is not present, so create everything down
-                    // and add it to the current bindings
-                    Context context = currentContext.createContextTree(compoundName.getPrefix(i).toString(),
-                            compoundName.getSuffix(i),
-                            value);
-                    currentContext.addBinding(part, context, false);
-
-                    // all done
-                    break;
-                } else {
-                    // the current value must be an abstract read only context
-                    // todo this is a problem since a nested node could be an AbstractReadOnlyContext
but not one of our contexts
-                    if (!(currentValue instanceof AbstractUnmodifiableContext)) {
-                        throw new NotContextException("Expected an instance of AbstractReadOnlyContext
to be bound at " +
-                                part + " but found an instance of " + currentValue.getClass().getName());
-                    }
-                    currentContext = (AbstractUnmodifiableContext) currentValue;
-                    // now we recurse into the current context
-                }
-            }
-        }
-    }
-
-    /**
-     * Creates a context tree which will be rooted at the specified path and contain a single
entry located down
-     * a path specified by the name.  All necessary intermediate contexts will be created
using the createContext method.
-     * @param path the path to the context that will contains this context
-     * @param name the name under which the value should be bound
-     * @param value the vale
-     * @return a context with the value bound at the specified name
-     * @throws NamingException
-     */
-    protected Context createContextTree(String path, Name name, Object value) throws NamingException
{
-        if (path == null) throw new NullPointerException("path is null");
-        if (name == null) throw new NullPointerException("name is null");
-        if (name.size() < 2) throw new InvalidNameException("name must have at least 2
parts " + name);
-
-        if (!path.endsWith("/")) path += "/";
-
-        for (int i = name.size() - 2; i >= 0; i--) {
-            String fullPath = path + name.getSuffix(i);
-            String key = name.get(i + 1);
-            value = createContext(fullPath, Collections.singletonMap(key, value));
-        }
-        return (AbstractUnmodifiableContext) value;
     }
 
     //

Modified: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java?rev=433366&r1=433365&r2=433366&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextUtil.java
Mon Aug 21 14:27:38 2006
@@ -216,7 +216,7 @@
         }
     }
 
-    public static Map createBindings(Map absoluteBindings, ContextFactory factory) throws
NamingException {
+    public static Map createBindings(Map absoluteBindings, NestedContextFactory factory)
throws NamingException {
         // create a tree of Nodes using the absolute bindings
         Node node = buildMapTree(absoluteBindings);
 
@@ -226,7 +226,7 @@
         return localBindings;
     }
 
-    private static Map createBindings(String nameInNameSpace, Node node, ContextFactory factory)
{
+    private static Map createBindings(String nameInNameSpace, Node node, NestedContextFactory
factory) {
         Map bindings = new HashMap(node.size());
         for (Iterator iterator = node.entrySet().iterator(); iterator.hasNext();) {
             Map.Entry entry = (Map.Entry) iterator.next();
@@ -241,7 +241,7 @@
                 String path = nameInNameSpace == null ? name : nameInNameSpace + "/" + name;
 
                 Map nestedBindings = createBindings(path, nestedNode, factory);
-                Context nestedContext = factory.createContext(path, nestedBindings);
+                Context nestedContext = factory.createNestedSubcontext(path, nestedBindings);
                 bindings.put(name, nestedContext);
             } else {
                 bindings.put(name, value);

Modified: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java?rev=433366&r1=433365&r2=433366&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java
Mon Aug 21 14:27:38 2006
@@ -67,8 +67,8 @@
             Map.Entry entry = (Map.Entry) iterator.next();
             String name = (String) entry.getKey();
             Object value = entry.getValue();
-            if (value instanceof ImmutableContext.NestedMapContext) {
-                ImmutableContext.NestedMapContext nestedContext = (ImmutableContext.NestedMapContext)value;
+            if (value instanceof ImmutableContext.NestedImmutableContext) {
+                ImmutableContext.NestedImmutableContext nestedContext = (ImmutableContext.NestedImmutableContext)value;
                 globalBindings.putAll(ImmutableContext.buildAbsoluteIndex(nestedContext.getNameInNamespace(),
nestedContext.localBindings));
             }
             globalBindings.put(path + name, value);
@@ -84,7 +84,7 @@
         return localBindings;
     }
 
-    protected void addDeepBinding(String name, Object value) throws NamingException {
+    protected void addDeepBinding(String name, Object value, boolean createIntermediateContexts)
throws NamingException {
         throw new OperationNotSupportedException("Context is immutable");
     }
 
@@ -96,18 +96,22 @@
         throw new OperationNotSupportedException("Context is immutable");
     }
 
-    public Context createContext(String path, Map bindings) {
-        return new NestedMapContext(path, bindings);
+    public boolean isNestedSubcontext(Object value) {
+        return value instanceof NestedImmutableContext;
+    }
+
+    public Context createNestedSubcontext(String path, Map bindings) {
+        return new NestedImmutableContext(path, bindings);
     }
 
     /**
      * Nested context which shares the absolute index map in MapContext.
      */
-    public final class NestedMapContext extends AbstractUnmodifiableContext {
+    public final class NestedImmutableContext extends AbstractUnmodifiableContext {
         private final Map localBindings;
         private final String pathWithSlash;
 
-        public NestedMapContext(String path, Map bindings) {
+        public NestedImmutableContext(String path, Map bindings) {
             super(ImmutableContext.this.getNameInNamespace(path));
 
             if (!path.endsWith("/")) path += "/";
@@ -125,7 +129,7 @@
             return localBindings;
         }
 
-        protected void addDeepBinding(String name, Object value) throws NamingException {
+        protected void addDeepBinding(String name, Object value, boolean createIntermediateContexts)
throws NamingException {
             throw new OperationNotSupportedException("Context is immutable");
         }
 
@@ -137,8 +141,12 @@
             throw new OperationNotSupportedException("Context is immutable");
         }
 
-        public Context createContext(String path, Map bindings) {
-            return new NestedMapContext(path, bindings);
+        public boolean isNestedSubcontext(Object value) {
+            return value instanceof NestedImmutableContext;
+        }
+
+        public Context createNestedSubcontext(String path, Map bindings) {
+            return new NestedImmutableContext(path, bindings);
         }
     }
 }

Copied: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/NestedContextFactory.java
(from r433303, geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFactory.java)
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/NestedContextFactory.java?p2=geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/NestedContextFactory.java&p1=geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFactory.java&r1=433303&r2=433366&rev=433366&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFactory.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/NestedContextFactory.java
Mon Aug 21 14:27:38 2006
@@ -22,6 +22,19 @@
 /**
  * @version $Rev$ $Date$
  */
-public interface ContextFactory {
-    Context createContext(String path, Map bindings);
+public interface NestedContextFactory {
+    /**
+     * Is the specified value an instance of a nested context
+     * @param value the value to inspect
+     * @return true if the specified value an instance of a nested context; false otherwise
+     */
+    boolean isNestedSubcontext(Object value);
+
+    /**
+     * Creates a nested subcontext instance.  This does not cause the nested context to be
bound.
+     * @param path the path to the new nested context
+     * @param bindings the initial bindings for the context
+     * @return the new nested context
+     */
+    Context createNestedSubcontext(String path, Map bindings);
 }

Modified: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/UnmodifiableContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/UnmodifiableContext.java?rev=433366&r1=433365&r2=433366&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/UnmodifiableContext.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/UnmodifiableContext.java
Mon Aug 21 14:27:38 2006
@@ -88,8 +88,8 @@
         Map index = (Map) indexRef.get();
         Map newIndex = new HashMap(index);
         newIndex.put(name, value);
-        if (value instanceof NestedMapContext) {
-            NestedMapContext nestedcontext = (NestedMapContext) value;
+        if (value instanceof NestedUnmodifiableContext) {
+            NestedUnmodifiableContext nestedcontext = (NestedUnmodifiableContext) value;
             Map newIndexValues = buildIndex(name, nestedcontext.getBindings());
             newIndex.putAll(newIndexValues);
         }
@@ -119,8 +119,8 @@
         Map index = (Map) indexRef.get();
         Map newIndex = new HashMap(index);
         Object oldValue = newIndex.remove(name);
-        if (oldValue instanceof NestedMapContext) {
-            NestedMapContext nestedcontext = (NestedMapContext) oldValue;
+        if (oldValue instanceof NestedUnmodifiableContext) {
+            NestedUnmodifiableContext nestedcontext = (NestedUnmodifiableContext) oldValue;
             Map removedIndexValues = buildIndex(name, nestedcontext.getBindings());
             for (Iterator iterator = removedIndexValues.keySet().iterator(); iterator.hasNext();)
{
                 String key = (String) iterator.next();
@@ -130,8 +130,12 @@
         return newIndex;
     }
 
-    public Context createContext(String path, Map bindings) {
-        return new NestedMapContext(path,bindings);
+    public boolean isNestedSubcontext(Object value) {
+        return value instanceof NestedUnmodifiableContext;
+    }
+
+    public Context createNestedSubcontext(String path, Map bindings) {
+        return new NestedUnmodifiableContext(path,bindings);
     }
 
     private static Map buildIndex(String nameInNamespace, Map bindings) {
@@ -145,8 +149,8 @@
             Map.Entry entry = (Map.Entry) iterator.next();
             String name = (String) entry.getKey();
             Object value = entry.getValue();
-            if (value instanceof UnmodifiableContext.NestedMapContext) {
-                UnmodifiableContext.NestedMapContext nestedContext = (UnmodifiableContext.NestedMapContext)value;
+            if (value instanceof UnmodifiableContext.NestedUnmodifiableContext) {
+                UnmodifiableContext.NestedUnmodifiableContext nestedContext = (UnmodifiableContext.NestedUnmodifiableContext)value;
                 absoluteIndex.putAll(UnmodifiableContext.buildIndex(nestedContext.pathWithSlash,
nestedContext.getBindings()));
             }
             absoluteIndex.put(path + name, value);
@@ -167,15 +171,15 @@
     /**
      * Nested context which shares the absolute index map in MapContext.
      */
-    public final class NestedMapContext extends AbstractUnmodifiableContext {
+    public final class NestedUnmodifiableContext extends AbstractUnmodifiableContext {
         private final AtomicReference bindingsRef;
         private final String pathWithSlash;
 
-        public NestedMapContext(String path, String key, Object value) {
+        public NestedUnmodifiableContext(String path, String key, Object value) {
             this(path, Collections.singletonMap(key, value));
         }
 
-        public NestedMapContext(String path, Map bindings) {
+        public NestedUnmodifiableContext(String path, Map bindings) {
             super(UnmodifiableContext.this.getNameInNamespace(path));
 
             if (!path.endsWith("/")) path += "/";
@@ -184,8 +188,12 @@
             this.bindingsRef = new AtomicReference(Collections.unmodifiableMap(bindings));
         }
 
-        public Context createContext(String path, Map bindings) {
-            return new NestedMapContext(path, bindings);
+        public boolean isNestedSubcontext(Object value) {
+            return value instanceof NestedUnmodifiableContext;
+        }
+
+        public Context createNestedSubcontext(String path, Map bindings) {
+            return new NestedUnmodifiableContext(path, bindings);
         }
 
         protected Object getDeepBinding(String name) {

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=433366&r1=433365&r2=433366&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 14:27:38 2006
@@ -38,7 +38,11 @@
         bindings = new HashMap();
     }
 
-    public Context createContext(String path, Map bindings) {
+    public boolean isNestedSubcontext(Object value) {
+        return value instanceof WritableContext;
+    }
+
+    public Context createNestedSubcontext(String path, Map bindings) {
         return new WritableContext(getNameInNamespace(path));
     }
 

Modified: geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/UnmodifiableContextTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/UnmodifiableContextTest.java?rev=433366&r1=433365&r2=433366&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/UnmodifiableContextTest.java
(original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/test/java/org/apache/xbean/naming/context/UnmodifiableContextTest.java
Mon Aug 21 14:27:38 2006
@@ -18,6 +18,8 @@
 
 import javax.naming.Context;
 import javax.naming.NamingException;
+import javax.naming.Name;
+import javax.naming.NameParser;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -32,8 +34,8 @@
             super(bindings);
         }
 
-        public void addDeepBinding(String name, Object value) throws NamingException {
-            super.addDeepBinding(name, value);
+        public void addDeepBinding(Name name, Object value, boolean rebind, boolean createIntermediateContexts)
throws NamingException {
+            super.addDeepBinding(name, value, rebind, createIntermediateContexts);
         }
 
         public void removeDeepBinding(String name) throws NamingException {
@@ -70,13 +72,14 @@
 
         // add a new deep tree
         map.put("uno/dos/tres", new Integer(123));
-        context.addDeepBinding("uno/dos/tres", new Integer(123));
+        NameParser parser = context.getNameParser();
+        context.addDeepBinding(parser.parse("uno/dos/tres"), new Integer(123), false, true);
 
         assertEq(map, context);
 
         // modify an existing context
         map.put("a/b/c/d/e/four", new Integer(4));
-        context.addDeepBinding("a/b/c/d/e/four", new Integer(4));
+        context.addDeepBinding(parser.parse("a/b/c/d/e/four"), new Integer(4), false, true);
 
         assertEq(map, context);
     }



Mime
View raw message