1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.jndi;
18
19 import java.util.HashMap;
20 import java.util.HashSet;
21 import java.util.Hashtable;
22 import java.util.Map;
23 import java.util.Set;
24
25 import javax.naming.Context;
26 import javax.naming.InitialContext;
27 import javax.naming.NamingException;
28
29 import org.apache.ldap.server.configuration.Configuration;
30 import org.apache.ldap.server.partition.ContextPartition;
31
32 /***
33 * Provides JNDI service to {@link AbstractContextFactory}.
34 *
35 * @author The Apache Directory Project
36 * @version $Rev: 264732 $, $Date: 2005-08-30 04:04:51 -0400 (Tue, 30 Aug 2005) $
37 */
38 public abstract class ContextFactoryService
39 {
40 private static final Map instances = new HashMap();
41
42 /***
43 * Returns the default instance. This method is identical with calling
44 * <tt>getInstance( Configuration.DEFAULT_INSTANCE_ID )</tt>.
45 */
46 public static ContextFactoryService getInstance()
47 {
48 return getInstance( Configuration.DEFAULT_INSTANCE_ID );
49 }
50
51 /***
52 * Returns {@link ContextFactoryService} with the specified instance ID.
53 */
54 public synchronized static ContextFactoryService getInstance( String instanceId )
55 {
56 instanceId = instanceId.trim();
57 ContextFactoryService service = ( ContextFactoryService ) instances.get( instanceId );
58 if( service == null )
59 {
60 service = new DefaultContextFactoryService( instanceId );
61 instances.put( instanceId, service );
62 }
63
64 return service;
65 }
66
67 /***
68 * Returns all instances of instantiated {@link ContextFactoryService}.
69 */
70 public synchronized static Set getAllInstances()
71 {
72 return new HashSet( instances.values() );
73 }
74
75 /***
76 * Starts up this service.
77 *
78 * @param listener a listener that listens to the lifecycle of this service
79 * @param environment JNDI {@link InitialContext} environment
80 *
81 * @throws NamingException if failed to start up
82 */
83 public abstract void startup( ContextFactoryServiceListener listener, Hashtable environment ) throws NamingException;
84
85 /***
86 * Shuts down this service.
87 *
88 * @throws NamingException if failed to shut down
89 */
90 public abstract void shutdown() throws NamingException;
91
92 /***
93 * Calls {@link ContextPartition#sync()} for all registered {@link ContextPartition}s.
94 * @throws NamingException if synchronization failed
95 */
96 public abstract void sync() throws NamingException;
97
98 /***
99 * Returns <tt>true</tt> if this service is started.
100 */
101 public abstract boolean isStarted();
102
103 /***
104 * Returns the configuration of this service.
105 */
106 public abstract ContextFactoryConfiguration getConfiguration();
107
108 /***
109 * Returns an anonymous JNDI {@link Context} with the specified <tt>baseName</tt>
110 * @throws NamingException if failed to create a context
111 */
112 public abstract Context getJndiContext( String baseName ) throws NamingException;
113
114 /***
115 * Returns a JNDI {@link Context} with the specified authentication information
116 * (<tt>principal</tt>, <tt>credential</tt>, and <tt>authentication</tt>) and
117 * <tt>baseName</tt>.
118 *
119 * @param principal {@link Context#SECURITY_PRINCIPAL} value
120 * @param credential {@link Context#SECURITY_CREDENTIALS} value
121 * @param authentication {@link Context#SECURITY_AUTHENTICATION} value
122 * @throws NamingException if failed to create a context
123 */
124 public abstract Context getJndiContext( String principal, byte[] credential, String authentication, String baseName ) throws NamingException;
125 }