geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r901481 - in /geronimo/xbean/trunk/xbean-naming/src: main/java/org/apache/xbean/naming/context/ main/java/org/apache/xbean/naming/java/ test/java/org/apache/xbean/naming/context/
Date Thu, 21 Jan 2010 01:14:09 GMT
Author: djencks
Date: Thu Jan 21 01:14:08 2010
New Revision: 901481

URL: http://svn.apache.org/viewvc?rev=901481&view=rev
Log:
XBEAN-144 glue together some contexts without binding

Added:
    geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableFederatedContext.java
  (with props)
    geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ImmutableFederatedContextTest.java
  (with props)
Modified:
    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/ContextFederation.java
    geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFlyweight.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/VirtualSubcontext.java
    geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/java/javaURLContextFactory.java

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=901481&r1=901480&r2=901481&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
Thu Jan 21 01:14:08 2010
@@ -18,6 +18,7 @@
 
 import java.util.Collections;
 import java.util.Map;
+import java.util.Set;
 
 import javax.naming.Context;
 import javax.naming.Name;
@@ -45,6 +46,12 @@
         this.contextFederation = new ContextFederation(this);
     }
 
+    public AbstractFederatedContext(String nameInNamespace, ContextAccess contextAccess,
Set<Context> federatedContexts) {
+        super(nameInNamespace, contextAccess);
+        this.masterContext = this;
+        this.contextFederation = new ContextFederation(this, federatedContexts);
+    }
+
     public AbstractFederatedContext(AbstractFederatedContext masterContext, String nameInNamespace)
throws NamingException {
         super(nameInNamespace, masterContext.getContextAccess());
         this.masterContext = masterContext;
@@ -59,8 +66,25 @@
         return super.faultLookup(stringName, parsedName);
     }
 
+    @Override
+    protected Object getDeepBinding(String name) {
+        try {
+            Object value = contextFederation.getFederatedBinding(name);
+            if (value instanceof Context) {
+                return null;
+            }
+            return value;
+        } catch (NamingException e) {
+            return null;
+        }
+    }
+
+    @Override
     protected Object getBinding(String name) throws NamingException {
         Object value = contextFederation.getFederatedBinding(name);
+        if (value instanceof Context) {
+            return createNestedSubcontext(name, getBindings(name));
+        }
         if (value == null) {
             value = getWrapperBindings().get(name);
         }
@@ -68,7 +92,11 @@
     }
 
     protected final Map<String, Object> getBindings() throws NamingException {
-        Map<String, Object> bindings = contextFederation.getFederatedBindings();
+        return getBindings("");
+    }
+
+    protected final Map<String, Object> getBindings(String name) throws NamingException
{
+        Map<String, Object> bindings = contextFederation.getFederatedBindings(name);
         bindings.putAll(getWrapperBindings());
         return bindings;
     }
@@ -124,6 +152,23 @@
             }
         }
     }
+    
+    protected static void removeFederatedContext(AbstractFederatedContext wrappingContext,
Context innerContext) throws NamingException {
+        wrappingContext.contextFederation.removeContext(innerContext);
+        for (Map.Entry<String, Object> entry : wrappingContext.getWrapperBindings().entrySet())
{
+            String name = entry.getKey();
+            Object value = entry.getValue();
+            if (value instanceof AbstractFederatedContext) {
+                AbstractFederatedContext nestedContext = (AbstractFederatedContext) value;
+
+                Name parsedName = wrappingContext.getNameParser().parse(name);
+                Name nameInNamespace = wrappingContext.getNameInNamespace(parsedName);
+
+                VirtualSubcontext virtualSubcontext = new VirtualSubcontext(nameInNamespace,
innerContext);
+                removeFederatedContext(nestedContext, virtualSubcontext);
+            }
+        }
+    }
 
     public boolean isNestedSubcontext(Object value) {
         if (value instanceof AbstractFederatedContext) {

Modified: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFederation.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFederation.java?rev=901481&r1=901480&r2=901481&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFederation.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFederation.java
Thu Jan 21 01:14:08 2010
@@ -28,6 +28,7 @@
 import javax.naming.Name;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
+import javax.naming.NotContextException;
 import javax.naming.OperationNotSupportedException;
 
 /**
@@ -42,6 +43,12 @@
         this.actualContext = actualContext;
     }
 
+    public ContextFederation(Context actualContext, Set<Context> federatedContexts)
{
+        this.actualContext = actualContext;
+        Set<Context> copy = new LinkedHashSet<Context>(federatedContexts);
+        federatedContextRef.set(Collections.unmodifiableSet(copy));
+    }
+
     public void addContext(Context context) {
         Set<Context> federatedContext;
         Set<Context> newFederatedContext;
@@ -57,6 +64,22 @@
         }
         throw new RuntimeException("Unable to update federatedContextRef within " + MAX_WRITE_ATTEMPTS
+ " attempts");
     }
+    
+    public void removeContext(Context context) {
+        Set<Context> federatedContext;
+        Set<Context> newFederatedContext;
+        for (int i = 0; i < MAX_WRITE_ATTEMPTS; i++) {
+            federatedContext = getFederatedContexts();
+
+            newFederatedContext = new LinkedHashSet<Context>(federatedContext);
+            newFederatedContext.remove(context);
+            newFederatedContext = Collections.unmodifiableSet(newFederatedContext);
+            if (federatedContextRef.compareAndSet(federatedContext, newFederatedContext))
{
+                return;
+            }
+        }
+        throw new RuntimeException("Unable to update federatedContextRef within " + MAX_WRITE_ATTEMPTS
+ " attempts");
+    }
 
     public Set<Context> getFederatedContexts() {
         return federatedContextRef.get();
@@ -77,22 +100,26 @@
         return null;
     }
 
-    public Map<String, Object> getFederatedBindings() throws NamingException {
+    public Map<String, Object> getFederatedBindings(String name) throws NamingException
{
         Map<String, Object> bindings = new HashMap<String, Object>();
         for (Context context : getFederatedContexts()) {
 
             // list federated context
-            NamingEnumeration namingEnumeration = context.listBindings("");
+            try {
+                NamingEnumeration namingEnumeration = context.listBindings(name);
 
-            // add to bindings
-            while (namingEnumeration.hasMoreElements()) {
-                Binding binding = (Binding) namingEnumeration.nextElement();
-                String name = binding.getName();
-
-                // don't overwrite existing bindings
-                if (!bindings.containsKey(name)) {
-                    bindings.put(name, binding.getObject());
+                // add to bindings
+                while (namingEnumeration.hasMoreElements()) {
+                    Binding binding = (Binding) namingEnumeration.nextElement();
+                    String bindingName = binding.getName();
+
+                    // don't overwrite existing bindings
+                    if (!bindings.containsKey(bindingName)) {
+                        bindings.put(bindingName, binding.getObject());
+                    }
                 }
+            } catch (NotContextException e) {
+                //this context does not include the supplied name
             }
         }
         return bindings;

Modified: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFlyweight.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFlyweight.java?rev=901481&r1=901480&r2=901481&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFlyweight.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFlyweight.java
Thu Jan 21 01:14:08 2010
@@ -32,6 +32,14 @@
 public abstract class ContextFlyweight implements Context {
     protected abstract Context getContext() throws NamingException;
 
+    protected Name getName(Name name) throws NamingException {
+        return name;
+    }
+
+    protected String getName(String name) throws NamingException {
+        return name;
+    }
+
     public void close() throws NamingException {
     }
 
@@ -40,91 +48,91 @@
     }
 
     public Object lookup(Name name) throws NamingException {
-        return getContext().lookup(name);
+        return getContext().lookup(getName(name));
     }
 
     public Object lookup(String name) throws NamingException {
-        return getContext().lookup(name);
+        return getContext().lookup(getName(name));
     }
 
     public void bind(Name name, Object obj) throws NamingException {
-        getContext().bind(name, obj);
+        getContext().bind(getName(name), obj);
     }
 
     public void bind(String name, Object obj) throws NamingException {
-        getContext().bind(name, obj);
+        getContext().bind(getName(name), obj);
     }
 
     public void rebind(Name name, Object obj) throws NamingException {
-        getContext().rebind(name, obj);
+        getContext().rebind(getName(name), obj);
     }
 
     public void rebind(String name, Object obj) throws NamingException {
-        getContext().rebind(name, obj);
+        getContext().rebind(getName(name), obj);
     }
 
     public void unbind(Name name) throws NamingException {
-        getContext().unbind(name);
+        getContext().unbind(getName(name));
     }
 
     public void unbind(String name) throws NamingException {
-        getContext().unbind(name);
+        getContext().unbind(getName(name));
     }
 
     public void rename(Name oldName, Name newName) throws NamingException {
-        getContext().rename(oldName, newName);
+        getContext().rename(getName(oldName), getName(newName));
     }
 
     public void rename(String oldName, String newName) throws NamingException {
-        getContext().rename(oldName, newName);
+        getContext().rename(getName(oldName), getName(newName));
     }
 
     public NamingEnumeration<NameClassPair> list(Name name) throws NamingException
{
-        return getContext().list(name);
+        return getContext().list(getName(name));
     }
 
     public NamingEnumeration<NameClassPair> list(String name) throws NamingException
{
-        return getContext().list(name);
+        return getContext().list(getName(name));
     }
 
     public NamingEnumeration<Binding> listBindings(Name name) throws NamingException
{
-        return getContext().listBindings(name);
+        return getContext().listBindings(getName(name));
     }
 
     public NamingEnumeration<Binding> listBindings(String name) throws NamingException
{
-        return getContext().listBindings(name);
+        return getContext().listBindings(getName(name));
     }
 
     public void destroySubcontext(Name name) throws NamingException {
-        getContext().destroySubcontext(name);
+        getContext().destroySubcontext(getName(name));
     }
 
     public void destroySubcontext(String name) throws NamingException {
-        getContext().destroySubcontext(name);
+        getContext().destroySubcontext(getName(name));
     }
 
     public Context createSubcontext(Name name) throws NamingException {
-        return getContext().createSubcontext(name);
+        return getContext().createSubcontext(getName(name));
     }
 
     public Context createSubcontext(String name) throws NamingException {
-        return getContext().createSubcontext(name);
+        return getContext().createSubcontext(getName(name));
     }
 
     public Object lookupLink(Name name) throws NamingException {
-        return getContext().lookupLink(name);
+        return getContext().lookupLink(getName(name));
     }
 
     public Object lookupLink(String name) throws NamingException {
-        return getContext().lookupLink(name);
+        return getContext().lookupLink(getName(name));
     }
 
     public NameParser getNameParser(Name name) throws NamingException {
-        return getContext().getNameParser(name);
+        return getContext().getNameParser(getName(name));
     }
 
     public NameParser getNameParser(String name) throws NamingException {
-        return getContext().getNameParser(name);
+        return getContext().getNameParser(getName(name));
     }
 
     public Name composeName(Name name, Name prefix) throws NamingException {

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=901481&r1=901480&r2=901481&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
Thu Jan 21 01:14:08 2010
@@ -71,7 +71,7 @@
             if (parsedName == null) {
                 parsedName = NAME_PARSER.parse(stringName);
             }
-            return NamingManager.getObjectInstance(reference, parsedName, nameCtx, new Hashtable());
+            return NamingManager.getObjectInstance(reference, parsedName, nameCtx, nameCtx.getEnvironment());
         } catch (NamingException e) {
             throw e;
         } catch (Exception e) {

Added: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableFederatedContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableFederatedContext.java?rev=901481&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableFederatedContext.java
(added)
+++ geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableFederatedContext.java
Thu Jan 21 01:14:08 2010
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.xbean.naming.context;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.OperationNotSupportedException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImmutableFederatedContext extends AbstractFederatedContext {
+
+    public ImmutableFederatedContext(String nameInNamespace, Set<Context> federatedContexts)
{
+        super(nameInNamespace, ContextAccess.UNMODIFIABLE, federatedContexts);
+    }
+
+    public void federateContext(Context context) throws NamingException {
+        addFederatedContext(this, context);
+    }
+
+    public void unfederateContext(Context context) throws NamingException {
+        removeFederatedContext(this, context);
+    }
+
+    @Override
+    protected Map<String, Object> getWrapperBindings() throws NamingException {
+        return Collections.emptyMap();
+    }
+
+    public Context createNestedSubcontext(String path, Map<String, Object> bindings)
throws NamingException {
+        return new NestedImmutableFederatedContext(path, bindings);
+    }
+
+    /**
+      * Nested context which shares the absolute index map in MapContext.
+      */
+     public class NestedImmutableFederatedContext extends AbstractFederatedContext {
+         private final AtomicReference<Map<String, Object>> bindingsRef;
+         private final String pathWithSlash;
+
+         public NestedImmutableFederatedContext(String path, Map<String, Object> bindings)
throws NamingException {
+             super(ImmutableFederatedContext.this, path);
+
+             path = getNameInNamespace();
+             if (!path.endsWith("/")) path += "/";
+             this.pathWithSlash = path;
+
+             this.bindingsRef = new AtomicReference<Map<String, Object>>(Collections.unmodifiableMap(bindings));
+         }
+
+         public Context createNestedSubcontext(String path, Map<String, Object> bindings)
throws NamingException {
+             return new NestedImmutableFederatedContext(getNameInNamespace(path), bindings);
+         }
+
+         protected Object getDeepBinding(String name) {
+             String absoluteName = pathWithSlash + name;
+             return ImmutableFederatedContext.this.getDeepBinding(absoluteName);
+         }
+
+         protected Map<String, Object> getWrapperBindings() throws NamingException
{
+             return bindingsRef.get();
+         }
+
+         protected boolean addBinding(String name, Object value, boolean rebind) throws NamingException
{
+             throw new OperationNotSupportedException("Context is immutable");
+         }
+
+         protected boolean removeBinding(String name, boolean removeNotEmptyContext) throws
NamingException {
+             throw new OperationNotSupportedException("Context is immutable");
+         }
+     }
+
+}

Propchange: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableFederatedContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableFederatedContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableFederatedContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/VirtualSubcontext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/VirtualSubcontext.java?rev=901481&r1=901480&r2=901481&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/VirtualSubcontext.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/context/VirtualSubcontext.java
Thu Jan 21 01:14:08 2010
@@ -29,14 +29,14 @@
 /**
  * @version $Rev$ $Date$
  */
-public class VirtualSubcontext implements Context {
+public class VirtualSubcontext extends ContextFlyweight {
     private final Name nameInContext;
     private final Context context;
 
     public VirtualSubcontext(Name nameInContext, Context context) throws NamingException
{
         if (context instanceof VirtualSubcontext) {
             VirtualSubcontext virtualSubcontext = (VirtualSubcontext) context;
-            this.nameInContext = virtualSubcontext.getNameInContext(nameInContext);
+            this.nameInContext = virtualSubcontext.getName(nameInContext);
             this.context = virtualSubcontext.context;
         } else {
             this.nameInContext = nameInContext;
@@ -44,121 +44,40 @@
         }
     }
 
-    private Name getNameInContext(Name name) throws NamingException {
-        return context.composeName(nameInContext, name);
-    }
-
-    private Name getNameInContext(String name) throws NamingException {
-        Name parsedName = context.getNameParser("").parse(name);
-        return context.composeName(nameInContext, parsedName);
+    @Override
+    protected Context getContext() throws NamingException {
+        return context;
     }
 
-    public Object lookup(Name name) throws NamingException {
-        return context.lookup(getNameInContext(name));
-    }
-
-    public Object lookup(String name) throws NamingException {
-        return context.lookup(getNameInContext(name));
-    }
-
-    public void bind(Name name, Object obj) throws NamingException {
-        context.bind(getNameInContext(name), obj);
-    }
-
-    public void bind(String name, Object obj) throws NamingException {
-        context.bind(getNameInContext(name), obj);
-    }
-
-    public void rebind(Name name, Object obj) throws NamingException {
-        context.rebind(getNameInContext(name), obj);
-    }
-
-    public void rebind(String name, Object obj) throws NamingException {
-        context.rebind(getNameInContext(name), obj);
-    }
-
-    public void unbind(Name name) throws NamingException {
-        context.unbind(getNameInContext(name));
-    }
-
-    public void unbind(String name) throws NamingException {
-        context.unbind(getNameInContext(name));
-    }
-
-    public void rename(Name oldName, Name newName) throws NamingException {
-        context.rename(getNameInContext(oldName), getNameInContext(newName));
-    }
-
-    public void rename(String oldName, String newName) throws NamingException {
-        context.rename(getNameInContext(oldName), getNameInContext(newName));
-    }
-
-    public NamingEnumeration<NameClassPair> list(Name name) throws NamingException
{
-        return context.list(getNameInContext(name));
-    }
-
-    public NamingEnumeration<NameClassPair> list(String name) throws NamingException
{
-        return context.list(getNameInContext(name));
-    }
-
-    public NamingEnumeration<Binding> listBindings(Name name) throws NamingException
{
-        return context.listBindings(getNameInContext(name));
-    }
-
-    public NamingEnumeration<Binding> listBindings(String name) throws NamingException
{
-        return context.listBindings(getNameInContext(name));
-    }
-
-    public void destroySubcontext(Name name) throws NamingException {
-        context.destroySubcontext(getNameInContext(name));
-    }
-
-    public void destroySubcontext(String name) throws NamingException {
-        context.destroySubcontext(getNameInContext(name));
-    }
-
-    public Context createSubcontext(Name name) throws NamingException {
-        return context.createSubcontext(getNameInContext(name));
-    }
-
-    public Context createSubcontext(String name) throws NamingException {
-        return context.createSubcontext(getNameInContext(name));
-    }
-
-    public Object lookupLink(Name name) throws NamingException {
-        return context.lookupLink(getNameInContext(name));
-    }
-
-    public Object lookupLink(String name) throws NamingException {
-        return context.lookupLink(getNameInContext(name));
-    }
-
-    public NameParser getNameParser(Name name) throws NamingException {
-        return context.getNameParser(getNameInContext(name));
+    @Override
+    protected Name getName(Name name) throws NamingException {
+        return context.composeName(nameInContext, name);
     }
 
-    public NameParser getNameParser(String name) throws NamingException {
-        return context.getNameParser(getNameInContext(name));
+    @Override
+    protected String getName(String name) throws NamingException {
+        Name parsedName = context.getNameParser("").parse(name);
+        return context.composeName(nameInContext, parsedName).toString();
     }
 
-    public Name composeName(Name name, Name prefix) throws NamingException {
-        return context.composeName(name, prefix);
-    }
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
 
-    public String composeName(String name, String prefix) throws NamingException {
-        return context.composeName(name, prefix);
-    }
+        VirtualSubcontext that = (VirtualSubcontext) o;
 
-    public Object addToEnvironment(String propName, Object propVal) throws NamingException
{
-        return context.addToEnvironment(propName, propVal);
-    }
+        if (context != null ? !context.equals(that.context) : that.context != null) return
false;
+        if (nameInContext != null ? !nameInContext.equals(that.nameInContext) : that.nameInContext
!= null) return false;
 
-    public Object removeFromEnvironment(String propName) throws NamingException {
-        return context.removeFromEnvironment(propName);
+        return true;
     }
 
-    public Hashtable getEnvironment() throws NamingException {
-        return context.getEnvironment();
+    @Override
+    public int hashCode() {
+        int result = nameInContext != null ? nameInContext.hashCode() : 0;
+        result = 31 * result + (context != null ? context.hashCode() : 0);
+        return result;
     }
 
     public void close() throws NamingException {

Modified: geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/java/javaURLContextFactory.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/java/javaURLContextFactory.java?rev=901481&r1=901480&r2=901481&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/java/javaURLContextFactory.java
(original)
+++ geronimo/xbean/trunk/xbean-naming/src/main/java/org/apache/xbean/naming/java/javaURLContextFactory.java
Thu Jan 21 01:14:08 2010
@@ -24,4 +24,7 @@
  * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $
  */
 public class javaURLContextFactory extends GlobalContextManager {
+    public javaURLContextFactory() {
+        System.out.println(getClass().getName());
+    }
 }

Added: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ImmutableFederatedContextTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ImmutableFederatedContextTest.java?rev=901481&view=auto
==============================================================================
--- geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ImmutableFederatedContextTest.java
(added)
+++ geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ImmutableFederatedContextTest.java
Thu Jan 21 01:14:08 2010
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.xbean.naming.context;
+
+import junit.framework.TestCase;
+
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImmutableFederatedContextTest  extends TestCase {
+
+    public void testJavaContextFederation() throws Exception {
+        Context comp = new ImmutableContext(Collections.<String, Object>singletonMap("comp/env/foo",
"foo"));
+        Context module = new ImmutableContext(Collections.<String, Object>singletonMap("module/env/bar",
"bar"));
+        Context application = new ImmutableContext(Collections.<String, Object>singletonMap("application/env/baz",
"baz"));
+        Context global1 = new ImmutableContext(Collections.<String, Object>singletonMap("global/env/foo1",
"foo1"));
+        Context global2 = new ImmutableContext(Collections.<String, Object>singletonMap("global/env/foo2",
"foo2"));
+
+        Set<Context> globals = new LinkedHashSet<Context>();
+        ImmutableFederatedContext global = new ImmutableFederatedContext("", globals);
+
+        Set<Context> locals = new LinkedHashSet<Context>();
+        locals.add(comp);
+        locals.add(module);
+        locals.add(application);
+        locals.add(global);
+        ImmutableFederatedContext w  = new ImmutableFederatedContext("", locals);
+
+        assertEquals("foo", w.lookup("comp/env/foo"));
+        assertEquals("bar", w.lookup("module/env/bar"));
+        assertEquals("baz", w.lookup("application/env/baz"));
+        try {
+            w.lookup("global/env/foo1");
+            fail("foo1 not yet bound");
+        } catch (NamingException e) {
+
+        }
+        global.federateContext(global1);
+        assertEquals("foo1", w.lookup("global/env/foo1"));
+        try {
+            w.lookup("global/env/foo2");
+            fail("foo2 not yet bound");
+        } catch (NamingException e) {
+
+        }
+
+        global.federateContext(global2);
+        assertEquals("foo2", w.lookup("global/env/foo2"));
+
+        Context c = (Context) w.lookup("global");
+        assertEquals("foo1", c.lookup("env/foo1"));
+        assertEquals("foo2", c.lookup("env/foo2"));
+
+        global.unfederateContext(global2);
+        try {
+            w.lookup("global/env/foo2");
+            fail("foo2 not yet bound");
+        } catch (NamingException e) {
+
+        }
+    }
+}

Propchange: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ImmutableFederatedContextTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ImmutableFederatedContextTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/xbean/trunk/xbean-naming/src/test/java/org/apache/xbean/naming/context/ImmutableFederatedContextTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message