KickJava   Java API By Example, From Geeks To Geeks.

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


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.Name JavaDoc;
13 import javax.naming.NameNotFoundException JavaDoc;
14 import javax.naming.NamingEnumeration JavaDoc;
15 import javax.naming.NamingException JavaDoc;
16 import org.codehaus.spice.jndikit.AbstractLocalContext;
17 import org.codehaus.spice.jndikit.Namespace;
18
19 /**
20  * An in memory context implementation.
21  *
22  * @author Peter Donald
23  * @version $Revision: 1.1 $
24  */

25 public class MemoryContext
26     extends AbstractLocalContext
27 {
28     private Hashtable JavaDoc m_bindings;
29
30     protected MemoryContext( final Namespace namespace,
31                              final Hashtable JavaDoc environment,
32                              final Context JavaDoc parent,
33                              final Hashtable JavaDoc bindings )
34     {
35         super( namespace, environment, parent );
36         m_bindings = bindings;
37     }
38
39     public MemoryContext( final Namespace namespace,
40                           final Hashtable JavaDoc environment,
41                           final Context JavaDoc parent )
42     {
43         this( namespace, environment, parent, new Hashtable JavaDoc( 11 ) );
44     }
45
46     protected Context JavaDoc newContext()
47         throws NamingException JavaDoc
48     {
49         return new MemoryContext( getNamespace(), getRawEnvironment(), getParent() );
50     }
51
52     protected Context JavaDoc cloneContext()
53         throws NamingException JavaDoc
54     {
55         return new MemoryContext( getNamespace(), getRawEnvironment(), getParent(), m_bindings );
56     }
57
58     protected void doLocalBind( final Name JavaDoc name, final Object JavaDoc object )
59         throws NamingException JavaDoc
60     {
61         m_bindings.put( name.get( 0 ), object );
62     }
63
64     protected NamingEnumeration JavaDoc doLocalList()
65         throws NamingException JavaDoc
66     {
67         return new MemoryNamingEnumeration( this, getNamespace(), m_bindings, false );
68     }
69
70     protected NamingEnumeration JavaDoc doLocalListBindings()
71         throws NamingException JavaDoc
72     {
73         return new MemoryNamingEnumeration( this, getNamespace(), m_bindings, true );
74     }
75
76     /**
77      * Actually lookup raw entry in local context.
78      * When overidding this it is not neccesary to resolve references etc.
79      *
80      * @param name the name in local context (size() == 1)
81      * @return the bound object
82      * @throws javax.naming.NamingException if an error occurs
83      */

84     protected Object JavaDoc doLocalLookup( final Name JavaDoc name )
85         throws NamingException JavaDoc
86     {
87         final Object JavaDoc object = m_bindings.get( name.get( 0 ) );
88         if( null == object )
89         {
90             throw new NameNotFoundException JavaDoc( name.get( 0 ) );
91         }
92         return object;
93     }
94
95     /**
96      * Actually unbind raw entry in local context.
97      *
98      * @param name the name in local context (size() == 1)
99      * @throws javax.naming.NamingException if an error occurs
100      */

101     protected void doLocalUnbind( final Name JavaDoc name )
102         throws NamingException JavaDoc
103     {
104         m_bindings.remove( name.get( 0 ) );
105     }
106 }
107
108
Popular Tags