1 17 18 package org.apache.geronimo.naming.geronimo; 19 20 import java.util.HashSet ; 21 import java.util.Hashtable ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 import java.util.Set ; 25 26 import javax.naming.Name ; 27 import javax.naming.NamingEnumeration ; 28 import javax.naming.NamingException ; 29 30 import org.apache.geronimo.naming.java.ReadOnlyContext; 31 32 38 public class GeronimoContext extends ReadOnlyContext { 39 40 GeronimoContext() { 41 super(); 42 } 43 44 GeronimoContext(GeronimoContext context, Hashtable environment) { 45 super(context, environment); 46 } 47 48 protected synchronized Map internalBind(String name, Object value) throws NamingException { 49 return super.internalBind(name, value); 50 } 51 52 protected ReadOnlyContext newContext() { 53 return new GeronimoContext(); 54 } 55 56 protected synchronized Set internalUnbind(String name) throws NamingException { 57 assert name != null; 58 assert !name.equals(""); 59 Set removeBindings = new HashSet (); 60 int pos = name.indexOf('/'); 61 if (pos == -1) { 62 if (treeBindings.remove(name) == null) { 63 throw new NamingException ("Nothing was bound at " + name); 64 } 65 bindings.remove(name); 66 removeBindings.add(name); 67 } else { 68 String segment = name.substring(0, pos); 69 assert segment != null; 70 assert !segment.equals(""); 71 Object o = treeBindings.get(segment); 72 if (o == null) { 73 throw new NamingException ("No context was bound at " + name); 74 } else if (!(o instanceof GeronimoContext)) { 75 throw new NamingException ("Something else bound where a subcontext should be " + o); 76 } 77 GeronimoContext gerContext = (GeronimoContext)o; 78 79 String remainder = name.substring(pos + 1); 80 Set subBindings = gerContext.internalUnbind(remainder); 81 for (Iterator iterator = subBindings.iterator(); iterator.hasNext();) { 82 String subName = segment + "/" + (String ) iterator.next(); 83 treeBindings.remove(subName); 84 removeBindings.add(subName); 85 } 86 if (gerContext.bindings.isEmpty()) { 87 bindings.remove(segment); 88 treeBindings.remove(segment); 89 removeBindings.add(segment); 90 } 91 } 92 return removeBindings; 93 } 94 95 96 public synchronized Object lookup(String name) throws NamingException { 97 return super.lookup(name); 98 } 99 100 public Object lookup(Name name) throws NamingException { 101 return super.lookup(name); 102 } 103 104 public synchronized Object lookupLink(String name) throws NamingException { 105 return super.lookupLink(name); 106 } 107 108 public synchronized Name composeName(Name name, Name prefix) throws NamingException { 109 return super.composeName(name, prefix); 110 } 111 112 public synchronized String composeName(String name, String prefix) throws NamingException { 113 return super.composeName(name, prefix); 114 } 115 116 public synchronized NamingEnumeration list(String name) throws NamingException { 117 return super.list(name); 118 } 119 120 public synchronized NamingEnumeration listBindings(String name) throws NamingException { 121 return super.listBindings(name); 122 } 123 124 public synchronized Object lookupLink(Name name) throws NamingException { 125 return super.lookupLink(name); 126 } 127 128 public synchronized NamingEnumeration list(Name name) throws NamingException { 129 return super.list(name); 130 } 131 132 public synchronized NamingEnumeration listBindings(Name name) throws NamingException { 133 return super.listBindings(name); 134 } 135 136 } 137 | Popular Tags |