KickJava   Java API By Example, From Geeks To Geeks.

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


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. This factory will
19  * retrieve the {@link MemoryContext} from a static variable.
20  * Thus this factory will always return the same instance of
21  * memory context.
22  *
23  * @author Peter Donald
24  * @version $Revision: 1.1 $
25  */

26 public class StaticMemoryInitialContextFactory
27     implements InitialContextFactory JavaDoc
28 {
29     private static final MemoryContext MEMORY_CONTEXT = createMemoryContext();
30
31     public Context JavaDoc getInitialContext( final Hashtable JavaDoc environment )
32         throws NamingException JavaDoc
33     {
34         return MEMORY_CONTEXT;
35     }
36
37     /**
38      * Method to create the inital {@link MemoryContext}.
39      *
40      * @return the new {@link MemoryContext}.
41      */

42     private static final MemoryContext createMemoryContext()
43     {
44         final DefaultNamespace namespace = new DefaultNamespace( new DefaultNameParser() );
45         return new MemoryContext( namespace,
46                                   new Hashtable JavaDoc(),
47                                   null );
48     }
49 }
50
51
Popular Tags