geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r432717 - in /geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context: AbstractContext.java AbstractUnmodifiableContext.java ImmutableContext.java UnmodifiableContext.java WritableContext.java
Date Fri, 18 Aug 2006 20:31:59 GMT
Author: dain
Date: Fri Aug 18 13:31:58 2006
New Revision: 432717

URL: http://svn.apache.org/viewvc?rev=432717&view=rev
Log:
Pulled generic part of addBinding up from WritableContext

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/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

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=432717&r1=432716&r2=432717&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
Fri Aug 18 13:31:58 2006
@@ -44,9 +44,38 @@
         //Ignore. Explicitly do not close the context
     }
 
+    protected void addDeepBinding(Name name, Object value, boolean rebind) throws NamingException
{
+        if (name.size() == 1) {
+            addBinding(name.get(0), value, rebind);
+            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;
+            }
+        }
+
+        String lastSegment = name.get(name.size() - 1);
+        if (rebind) {
+            context.rebind(lastSegment, value);
+        } else {
+            context.bind(lastSegment, value);
+        }
+    }
+
+    protected abstract void addBinding(String name, Object value, boolean rebind) throws
NamingException;
+
+
     protected abstract void removeBindings(Name name) throws NamingException;
     protected abstract Object lookup(String stringName, Name parsedName) throws NamingException;
-    protected abstract void addBinding(Name name, Object obj, boolean rebind) throws NamingException;
     protected abstract Map getBindings() throws NamingException;
 
     //
@@ -195,7 +224,7 @@
         if (name.isEmpty()) {
             throw new NameAlreadyBoundException("Cannot bind to an empty name (this context)");
         }
-        addBinding(name, obj, false);
+        addDeepBinding(name, obj, false);
     }
 
     public void rebind(String name, Object obj) throws NamingException {
@@ -208,7 +237,7 @@
         if (name.isEmpty()) {
             throw new NameAlreadyBoundException("Cannot rebind an empty name (this context)");
         }
-        addBinding(name, obj, true);
+        addDeepBinding(name, obj, true);
     }
 
     public void rename(String oldName, String newName) throws NamingException {
@@ -351,7 +380,7 @@
             throw new InvalidNameException("Cannot create a subcontext if the name is empty");
         }
         Context abstractContext = createContext(name.toString(), Collections.EMPTY_MAP);
-        addBinding(name, abstractContext, false);
+        addDeepBinding(name, abstractContext, false);
         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=432717&r1=432716&r2=432717&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
Fri Aug 18 13:31:58 2006
@@ -160,15 +160,11 @@
     //  Add Binding
     //
 
-    /**
-     * Add the binding to the context.  The name will not contain a path but the value may
-     * be a nested context which should be indexed for indexing contexts.
-     * @param name name under which the value should be bound
-     * @param value the value to bind
-     * @throws NamingException if a problem occurs during the bind such as a value already
being bound
-     */
-    protected void addBinding(String name, Object value) throws NamingException {
-        throw new OperationNotSupportedException("Context is read only");
+    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 {
@@ -192,7 +188,7 @@
             // 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);
+                currentContext.addBinding(part, value, false);
 
                 // all done... this is redundant but makes the code more readable
                 break;
@@ -205,7 +201,7 @@
                     Context context = currentContext.createContextTree(compoundName.getPrefix(i).toString(),
                             compoundName.getSuffix(i),
                             value);
-                    currentContext.addBinding(part, context);
+                    currentContext.addBinding(part, context, false);
 
                     // all done
                     break;

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=432717&r1=432716&r2=432717&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
Fri Aug 18 13:31:58 2006
@@ -88,6 +88,10 @@
         throw new OperationNotSupportedException("Context is immutable");
     }
 
+    protected void addBinding(String name, Object value, boolean rebind) throws NamingException
{
+        throw new OperationNotSupportedException("Context is immutable");
+    }
+
     protected void removeDeepBinding(String name, Object value) throws NamingException {
         throw new OperationNotSupportedException("Context is immutable");
     }
@@ -122,6 +126,10 @@
         }
 
         protected void addDeepBinding(String name, Object value) throws NamingException {
+            throw new OperationNotSupportedException("Context is immutable");
+        }
+
+        protected void addBinding(String name, Object value, boolean rebind) throws NamingException
{
             throw new OperationNotSupportedException("Context is immutable");
         }
 

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=432717&r1=432716&r2=432717&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
Fri Aug 18 13:31:58 2006
@@ -25,6 +25,7 @@
 import javax.naming.NamingException;
 import javax.naming.Context;
 import javax.naming.NameNotFoundException;
+import javax.naming.OperationNotSupportedException;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -60,7 +61,11 @@
         this.indexRef = new AtomicReference(Collections.unmodifiableMap(buildIndex("", localBindings)));
     }
 
-    protected void addBinding(String name, Object value) throws NamingException {
+    protected void addBinding(String name, Object value, boolean rebind) throws NamingException
{
+        if (rebind) {
+            throw new OperationNotSupportedException("This conext does not support rebind");
+        }
+
         writeLock.lock();
         try {
             Map bindings = (Map) bindingsRef.get();
@@ -193,7 +198,11 @@
             return bindings;
         }
 
-        protected void addBinding(String name, Object value) {
+        protected void addBinding(String name, Object value, boolean rebind) throws NamingException
{
+            if (rebind) {
+                throw new OperationNotSupportedException("This conext does not support rebind");
+            }
+
             writeLock.lock();
             try {
                 Map currentBindings = (Map) bindingsRef.get();

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=432717&r1=432716&r2=432717&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
Fri Aug 18 13:31:58 2006
@@ -121,40 +121,13 @@
 
     }
 
-    protected void addBinding(Name name, Object obj, boolean rebind) throws NamingException
{
-        Map bindings = this.bindings;
-        if (name.size() == 1) {
+    protected void addBinding(String name, Object value, boolean rebind) throws NamingException
{
+        synchronized (bindings) {
             if (rebind || bindings.get(name.toString()) == null) {
-                synchronized (bindings) {
-                    bindings.put(name.toString(), obj);
-                }
+                bindings.put(name, value);
             } else {
                 throw new NameAlreadyBoundException("The name " + name
                         + "is already bound");
-            }
-        } 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 {
-                    bindings = ((WritableContext) terminalContext).bindings;
-                }
-            }
-            segment = name.get(lastIndex);
-            if (rebind) {
-                ((Context) terminalContext).rebind(segment, obj);
-            } else {
-                ((Context) terminalContext).bind(segment, obj);
             }
         }
     }



Mime
View raw message