KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > spice > jndikit > memory > MemoryInitialContextFactory


1 /*
2  * Copyright (C) The Spice Group. All rights reserved.
3  *
4  * This software is published under the terms of the Spice
5  * Software License version 1.1, a copy of which has been included
6  * with this distribution in the LICENSE.txt file.
7  */

8 package org.codehaus.spice.jndikit.memory;
9
10 import java.util.Hashtable JavaDoc;
11 import javax.naming.Context JavaDoc;
12 import javax.naming.NamingException JavaDoc;
13 import javax.naming.spi.InitialContextFactory JavaDoc;
14 import org.codehaus.spice.jndikit.DefaultNameParser;
15 import org.codehaus.spice.jndikit.DefaultNamespace;
16
17 /**
18  * Initial context factory for memorycontext.
19  *
20  * <p><b>WARNING:</b> This class should never be use used in a real
21  * system. It is is just a class that demonstrates how to write a
22  * basic <code>InitialContextFactory</code> for MemeoryContext.
23  * However this factory creates a new Context every time which is
24  * rarely desired behaviour.</p>
25  *
26  * <p>In a real application you may want the policy of Context
27  * creation to be specific application. Some strategies include.</p>
28  * <ul>
29  * <li>ClassLoader-wide. ie Every user who is in same ClassLoader
30  * or loaded from a Child ClassLoader will see same JNDI tree.
31  * In this case the InitialContextFactory should cache root
32  * context in a static variable.</li>
33  * <li>Thread-specific. ie Give out initial context based on which
34  * thread the caller is in. In this case the InitialContextFactory
35  * should cache root context in a [Inheritable]ThreadLocal
36  * variable.</li>
37  * <li>Parameter-specific. ie Give out initial context based on
38  * a parameter passed in. The parameter could be passed in as
39  * PROVIDER_URL or another standard context property. In this
40  * case the InitialContextFactory should cache root context(s)
41  * in a static map variable that maps between parameter and
42  * context.</li>
43  * </ul>
44  *
45  * @author Peter Donald
46  * @version $Revision: 1.1 $
47  */

48 public class MemoryInitialContextFactory
49     implements InitialContextFactory JavaDoc
50 {
51     public Context JavaDoc getInitialContext( final Hashtable JavaDoc environment )
52         throws NamingException JavaDoc
53     {
54         final DefaultNameParser parser = new DefaultNameParser();
55         final DefaultNamespace namespace = new DefaultNamespace( parser );
56         return new MemoryContext( namespace, environment, null );
57     }
58 }
59
60
Popular Tags