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