1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 /***
18 * Created on Feb 4, 2004
19 *
20 *
21 * @author
22 */
23 package org.apache.jetspeed.components.jndi;
24
25 import java.util.Hashtable;
26
27 import javax.naming.Context;
28 import javax.naming.NamingException;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32
33 import tyrex.naming.MemoryContext;
34 import tyrex.tm.RuntimeContext;
35
36 /***
37 * <p>
38 * TyrexJNDIComponent
39 * </p>
40 * <p>
41 *
42 * </p>
43 * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
44 * @version $Id: TyrexJNDIComponent.java 516881 2007-03-11 10:34:21Z ate $
45 *
46 */
47 public class TyrexJNDIComponent implements JNDIComponent
48 {
49
50 private static final Log log = LogFactory.getLog(TyrexJNDIComponent.class);
51
52 private MemoryContext rootJNDIContext;
53
54 /***
55 * @see org.apache.fulcrum.Service#init()
56 */
57 public TyrexJNDIComponent() throws NamingException
58 {
59 Context ctx = null;
60
61
62 Hashtable env = new Hashtable();
63 env.put(Context.INITIAL_CONTEXT_FACTORY, "tyrex.naming.MemoryContextFactory");
64 rootJNDIContext = new MemoryContext(null);
65 rootJNDIContext.createSubcontext("jdbc");
66 ctx = rootJNDIContext.createSubcontext("comp");
67 ctx = ctx.createSubcontext("env");
68 ctx = ctx.createSubcontext("jdbc");
69
70
71
72
73 bindToCurrentThread();
74 log.info("JNDI successfully initiallized");
75
76 }
77
78
79 /***
80 * @see org.apache.jetspeed.cps.jndi.JNDIService#getRootContext()
81 */
82 public Context getRootContext()
83 {
84 return rootJNDIContext;
85 }
86
87 /***
88 * @see org.apache.jetspeed.cps.jndi.JNDIService#bindToCurrentThread()
89 */
90 public void bindToCurrentThread() throws NamingException
91 {
92 RuntimeContext runCtx = RuntimeContext.newRuntimeContext(rootJNDIContext, null);
93 RuntimeContext.setRuntimeContext(runCtx);
94 }
95
96 /***
97 *
98 * <p>
99 * bindObject
100 * </p>
101 *
102 * @see org.apache.jetspeed.cps.jndi.JNDIComponent#bindObject(java.lang.String, java.lang.Object)
103 * @param bindToName
104 * @param obj
105 * @throws NamingException
106 */
107 public void bindObject(String bindToName, Object obj) throws NamingException
108 {
109 log.debug("Binding "+obj+" to name "+bindToName);
110 Context ctx = getRootContext();
111 ctx.bind(bindToName, obj);
112 }
113
114 /***
115 * <p>
116 * unbindFromCurrentThread
117 * </p>
118 *
119 * @see org.apache.jetspeed.components.jndi.JNDIComponent#unbindFromCurrentThread()
120 * @throws NamingException
121 */
122 public void unbindFromCurrentThread() throws NamingException
123 {
124 RuntimeContext.unsetRuntimeContext();
125 RuntimeContext.cleanup(Thread.currentThread());
126 }
127
128
129
130
131 public void unbindObject( String name ) throws NamingException
132 {
133 log.debug("Unbinding name "+name);
134 Context ctx = getRootContext();
135 ctx.unbind(name);
136
137 }
138 }