KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > naming > geronimo > GeronimoContext


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.naming.geronimo;
19
20 import java.util.HashSet JavaDoc;
21 import java.util.Hashtable JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Map JavaDoc;
24 import java.util.Set JavaDoc;
25
26 import javax.naming.Name JavaDoc;
27 import javax.naming.NamingEnumeration JavaDoc;
28 import javax.naming.NamingException JavaDoc;
29
30 import org.apache.geronimo.naming.java.ReadOnlyContext;
31
32 /**
33  *
34  *
35  * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
36  *
37  * */

38 public class GeronimoContext extends ReadOnlyContext {
39
40     GeronimoContext() {
41         super();
42     }
43
44     GeronimoContext(GeronimoContext context, Hashtable JavaDoc environment) {
45         super(context, environment);
46     }
47
48     protected synchronized Map JavaDoc internalBind(String JavaDoc name, Object JavaDoc value) throws NamingException JavaDoc {
49         return super.internalBind(name, value);
50     }
51
52     protected ReadOnlyContext newContext() {
53         return new GeronimoContext();
54     }
55
56     protected synchronized Set JavaDoc internalUnbind(String JavaDoc name) throws NamingException JavaDoc {
57         assert name != null;
58         assert !name.equals("");
59         Set JavaDoc removeBindings = new HashSet JavaDoc();
60         int pos = name.indexOf('/');
61         if (pos == -1) {
62             if (treeBindings.remove(name) == null) {
63                 throw new NamingException JavaDoc("Nothing was bound at " + name);
64             }
65             bindings.remove(name);
66             removeBindings.add(name);
67         } else {
68             String JavaDoc segment = name.substring(0, pos);
69             assert segment != null;
70             assert !segment.equals("");
71             Object JavaDoc o = treeBindings.get(segment);
72             if (o == null) {
73                 throw new NamingException JavaDoc("No context was bound at " + name);
74             } else if (!(o instanceof GeronimoContext)) {
75                 throw new NamingException JavaDoc("Something else bound where a subcontext should be " + o);
76             }
77             GeronimoContext gerContext = (GeronimoContext)o;
78
79             String JavaDoc remainder = name.substring(pos + 1);
80             Set JavaDoc subBindings = gerContext.internalUnbind(remainder);
81             for (Iterator JavaDoc iterator = subBindings.iterator(); iterator.hasNext();) {
82                 String JavaDoc subName = segment + "/" + (String JavaDoc) 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 JavaDoc lookup(String JavaDoc name) throws NamingException JavaDoc {
97         return super.lookup(name);
98     }
99
100     public Object JavaDoc lookup(Name JavaDoc name) throws NamingException JavaDoc {
101         return super.lookup(name);
102     }
103
104     public synchronized Object JavaDoc lookupLink(String JavaDoc name) throws NamingException JavaDoc {
105         return super.lookupLink(name);
106     }
107
108     public synchronized Name JavaDoc composeName(Name JavaDoc name, Name JavaDoc prefix) throws NamingException JavaDoc {
109         return super.composeName(name, prefix);
110     }
111
112     public synchronized String JavaDoc composeName(String JavaDoc name, String JavaDoc prefix) throws NamingException JavaDoc {
113         return super.composeName(name, prefix);
114     }
115
116     public synchronized NamingEnumeration JavaDoc list(String JavaDoc name) throws NamingException JavaDoc {
117         return super.list(name);
118     }
119
120     public synchronized NamingEnumeration JavaDoc listBindings(String JavaDoc name) throws NamingException JavaDoc {
121         return super.listBindings(name);
122     }
123
124     public synchronized Object JavaDoc lookupLink(Name JavaDoc name) throws NamingException JavaDoc {
125         return super.lookupLink(name);
126     }
127
128     public synchronized NamingEnumeration JavaDoc list(Name JavaDoc name) throws NamingException JavaDoc {
129         return super.list(name);
130     }
131
132     public synchronized NamingEnumeration JavaDoc listBindings(Name JavaDoc name) throws NamingException JavaDoc {
133         return super.listBindings(name);
134     }
135
136 }
137
Popular Tags