KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > naming > NamingContextFactory


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

16
17 package org.apache.naming;
18
19 import java.util.Hashtable JavaDoc;
20 import javax.naming.Context JavaDoc;
21 import javax.naming.NamingException JavaDoc;
22 import javax.naming.spi.InitialContextFactory JavaDoc;
23
24 /**
25  * Initial context factory returning {@link NamingContext} instances.
26  *
27  * @version $Revision$ $Date$
28  */

29 public class NamingContextFactory implements InitialContextFactory JavaDoc {
30     
31     /**
32      * Get a new (writable) initial context. Always returns a
33      * {@link NamingContext}. If
34      * {@link SynchronizedContext#isSynchronized} returns true for
35      * <code>environment</code> then the
36      * returned context is wrapped in a {@link SynchronizedContext}, so access
37      * to it will be synchronized.
38      *
39      * @param environment environment
40      * @return a new Context
41      * @exception NamingException if a naming exception is encountered
42      */

43     public Context JavaDoc getInitialContext(Hashtable JavaDoc environment)
44     throws NamingException JavaDoc {
45         Context JavaDoc ctx = new NamingContext(environment, "initialContext");
46         if (SynchronizedContext.isSynchronized(environment)) {
47             return new SynchronizedContext(ctx);
48         } else {
49             return ctx;
50         }
51     }
52 }
53
Popular Tags