Source Code Cross Referenced for ContextBindings.java in  » Sevlet-Container » tomcat-catalina » org » apache » naming » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Sevlet Container » tomcat catalina » org.apache.naming 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999,2004 The Apache Software Foundation.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.apache.naming;
018:
019:        import java.util.Hashtable;
020:        import javax.naming.NamingException;
021:        import javax.naming.Context;
022:
023:        /**
024:         * Handles the associations :
025:         * <ul>
026:         * <li>Catalina context name with the NamingContext</li>
027:         * <li>Calling thread with the NamingContext</li>
028:         * </ul>
029:         *
030:         * @author Remy Maucherat
031:         * @version $Revision: 1.3 $ $Date: 2004/02/27 14:58:53 $
032:         */
033:
034:        public class ContextBindings {
035:
036:            // -------------------------------------------------------------- Variables
037:
038:            /**
039:             * Bindings name - naming context. Keyed by name.
040:             */
041:            private static Hashtable contextNameBindings = new Hashtable();
042:
043:            /**
044:             * Bindings thread - naming context. Keyed by thread id.
045:             */
046:            private static Hashtable threadBindings = new Hashtable();
047:
048:            /**
049:             * Bindings thread - name. Keyed by thread id.
050:             */
051:            private static Hashtable threadNameBindings = new Hashtable();
052:
053:            /**
054:             * Bindings class loader - naming context. Keyed by CL id.
055:             */
056:            private static Hashtable clBindings = new Hashtable();
057:
058:            /**
059:             * Bindings class loader - name. Keyed by CL id.
060:             */
061:            private static Hashtable clNameBindings = new Hashtable();
062:
063:            /**
064:             * The string manager for this package.
065:             */
066:            protected static StringManager sm = StringManager
067:                    .getManager(Constants.Package);
068:
069:            // --------------------------------------------------------- Public Methods
070:
071:            /**
072:             * Binds a context name.
073:             * 
074:             * @param name Name of the context
075:             * @param context Associated naming context instance
076:             */
077:            public static void bindContext(Object name, Context context) {
078:                bindContext(name, context, null);
079:            }
080:
081:            /**
082:             * Binds a context name.
083:             * 
084:             * @param name Name of the context
085:             * @param context Associated naming context instance
086:             * @param token Security token
087:             */
088:            public static void bindContext(Object name, Context context,
089:                    Object token) {
090:                if (ContextAccessController.checkSecurityToken(name, token))
091:                    contextNameBindings.put(name, context);
092:            }
093:
094:            /**
095:             * Unbind context name.
096:             * 
097:             * @param name Name of the context
098:             */
099:            public static void unbindContext(Object name) {
100:                unbindContext(name, null);
101:            }
102:
103:            /**
104:             * Unbind context name.
105:             * 
106:             * @param name Name of the context
107:             * @param token Security token
108:             */
109:            public static void unbindContext(Object name, Object token) {
110:                if (ContextAccessController.checkSecurityToken(name, token))
111:                    contextNameBindings.remove(name);
112:            }
113:
114:            /**
115:             * Retrieve a naming context.
116:             * 
117:             * @param name Name of the context
118:             */
119:            static Context getContext(Object name) {
120:                return (Context) contextNameBindings.get(name);
121:            }
122:
123:            /**
124:             * Binds a naming context to a thread.
125:             * 
126:             * @param name Name of the context
127:             */
128:            public static void bindThread(Object name) throws NamingException {
129:                bindThread(name, null);
130:            }
131:
132:            /**
133:             * Binds a naming context to a thread.
134:             * 
135:             * @param name Name of the context
136:             * @param token Security token
137:             */
138:            public static void bindThread(Object name, Object token)
139:                    throws NamingException {
140:                if (ContextAccessController.checkSecurityToken(name, token)) {
141:                    Context context = (Context) contextNameBindings.get(name);
142:                    if (context == null)
143:                        throw new NamingException(sm.getString(
144:                                "contextBindings.unknownContext", name));
145:                    threadBindings.put(Thread.currentThread(), context);
146:                    threadNameBindings.put(Thread.currentThread(), name);
147:                }
148:            }
149:
150:            /**
151:             * Unbinds a naming context to a thread.
152:             * 
153:             * @param name Name of the context
154:             */
155:            public static void unbindThread(Object name) {
156:                unbindThread(name, null);
157:            }
158:
159:            /**
160:             * Unbinds a naming context to a thread.
161:             * 
162:             * @param name Name of the context
163:             * @param token Security token
164:             */
165:            public static void unbindThread(Object name, Object token) {
166:                if (ContextAccessController.checkSecurityToken(name, token)) {
167:                    threadBindings.remove(Thread.currentThread());
168:                    threadNameBindings.remove(Thread.currentThread());
169:                }
170:            }
171:
172:            /**
173:             * Retrieves the naming context bound to a thread.
174:             */
175:            public static Context getThread() throws NamingException {
176:                Context context = (Context) threadBindings.get(Thread
177:                        .currentThread());
178:                if (context == null)
179:                    throw new NamingException(
180:                            sm
181:                                    .getString("contextBindings.noContextBoundToThread"));
182:                return context;
183:            }
184:
185:            /**
186:             * Retrieves the naming context name bound to a thread.
187:             */
188:            static Object getThreadName() throws NamingException {
189:                Object name = threadNameBindings.get(Thread.currentThread());
190:                if (name == null)
191:                    throw new NamingException(
192:                            sm
193:                                    .getString("contextBindings.noContextBoundToThread"));
194:                return name;
195:            }
196:
197:            /**
198:             * Tests if current thread is bound to a context.
199:             */
200:            public static boolean isThreadBound() {
201:                return (threadBindings.containsKey(Thread.currentThread()));
202:            }
203:
204:            /**
205:             * Binds a naming context to a class loader.
206:             * 
207:             * @param name Name of the context
208:             */
209:            public static void bindClassLoader(Object name)
210:                    throws NamingException {
211:                bindClassLoader(name, null);
212:            }
213:
214:            /**
215:             * Binds a naming context to a thread.
216:             * 
217:             * @param name Name of the context
218:             * @param token Security token
219:             */
220:            public static void bindClassLoader(Object name, Object token)
221:                    throws NamingException {
222:                bindClassLoader(name, token, Thread.currentThread()
223:                        .getContextClassLoader());
224:            }
225:
226:            /**
227:             * Binds a naming context to a thread.
228:             * 
229:             * @param name Name of the context
230:             * @param token Security token
231:             */
232:            public static void bindClassLoader(Object name, Object token,
233:                    ClassLoader classLoader) throws NamingException {
234:                if (ContextAccessController.checkSecurityToken(name, token)) {
235:                    Context context = (Context) contextNameBindings.get(name);
236:                    if (context == null)
237:                        throw new NamingException(sm.getString(
238:                                "contextBindings.unknownContext", name));
239:                    clBindings.put(classLoader, context);
240:                    clNameBindings.put(classLoader, name);
241:                }
242:            }
243:
244:            /**
245:             * Unbinds a naming context to a class loader.
246:             * 
247:             * @param name Name of the context
248:             */
249:            public static void unbindClassLoader(Object name) {
250:                unbindClassLoader(name, null);
251:            }
252:
253:            /**
254:             * Unbinds a naming context to a class loader.
255:             * 
256:             * @param name Name of the context
257:             * @param token Security token
258:             */
259:            public static void unbindClassLoader(Object name, Object token) {
260:                unbindClassLoader(name, token, Thread.currentThread()
261:                        .getContextClassLoader());
262:            }
263:
264:            /**
265:             * Unbinds a naming context to a class loader.
266:             * 
267:             * @param name Name of the context
268:             * @param token Security token
269:             */
270:            public static void unbindClassLoader(Object name, Object token,
271:                    ClassLoader classLoader) {
272:                if (ContextAccessController.checkSecurityToken(name, token)) {
273:                    Object n = clNameBindings.get(classLoader);
274:                    if ((n == null) || !(n.equals(name))) {
275:                        return;
276:                    }
277:                    clBindings.remove(classLoader);
278:                    clNameBindings.remove(classLoader);
279:                }
280:            }
281:
282:            /**
283:             * Retrieves the naming context bound to a class loader.
284:             */
285:            public static Context getClassLoader() throws NamingException {
286:                ClassLoader cl = Thread.currentThread().getContextClassLoader();
287:                Context context = null;
288:                do {
289:                    context = (Context) clBindings.get(cl);
290:                    if (context != null) {
291:                        return context;
292:                    }
293:                } while ((cl = cl.getParent()) != null);
294:                throw new NamingException(sm
295:                        .getString("contextBindings.noContextBoundToCL"));
296:            }
297:
298:            /**
299:             * Retrieves the naming context name bound to a class loader.
300:             */
301:            static Object getClassLoaderName() throws NamingException {
302:                ClassLoader cl = Thread.currentThread().getContextClassLoader();
303:                Object name = null;
304:                do {
305:                    name = clNameBindings.get(cl);
306:                    if (name != null) {
307:                        return name;
308:                    }
309:                } while ((cl = cl.getParent()) != null);
310:                throw new NamingException(sm
311:                        .getString("contextBindings.noContextBoundToCL"));
312:            }
313:
314:            /**
315:             * Tests if current class loader is bound to a context.
316:             */
317:            public static boolean isClassLoaderBound() {
318:                ClassLoader cl = Thread.currentThread().getContextClassLoader();
319:                do {
320:                    if (clBindings.containsKey(cl)) {
321:                        return true;
322:                    }
323:                } while ((cl = cl.getParent()) != null);
324:                return false;
325:            }
326:
327:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.