1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server;
18
19
20 import java.util.Properties;
21
22 import javax.naming.Context;
23 import javax.naming.directory.InitialDirContext;
24
25 import org.apache.ldap.server.configuration.MutableServerStartupConfiguration;
26 import org.apache.ldap.server.configuration.ServerStartupConfiguration;
27 import org.apache.ldap.server.configuration.SyncConfiguration;
28 import org.apache.ldap.server.jndi.ServerContextFactory;
29 import org.springframework.context.ApplicationContext;
30 import org.springframework.context.support.FileSystemXmlApplicationContext;
31 import org.slf4j.LoggerFactory;
32 import org.slf4j.Logger;
33
34
35 /***
36 * The command line main for the server. Warning this used to be a simple test
37 * case so there really is not much here.
38 *
39 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
40 * @version $Rev: 264732 $
41 */
42 public class ServerMain
43 {
44 private static final Logger log = LoggerFactory.getLogger(ServerMain.class);
45
46 /***
47 * Takes a single argument, an optional properties file to load with server
48 * startup settings.
49 *
50 * @param args the arguments
51 */
52 public static void main( String[] args ) throws Exception
53 {
54 long startTime = System.currentTimeMillis();
55 Properties env;
56 ServerStartupConfiguration cfg;
57
58 if ( args.length > 0 )
59 {
60 log.info( "server: loading settings from {}", args[0] );
61 ApplicationContext factory = new FileSystemXmlApplicationContext( args[0] );
62 cfg = ( ServerStartupConfiguration ) factory.getBean( "configuration" );
63 env = ( Properties ) factory.getBean( "environment" );
64 }
65 else
66 {
67 log.info( "server: using default settings ..." );
68 env = new Properties();
69 cfg = new MutableServerStartupConfiguration();
70 }
71
72 env.setProperty( Context.PROVIDER_URL, "ou=system" );
73 env.setProperty( Context.INITIAL_CONTEXT_FACTORY, ServerContextFactory.class.getName() );
74 env.putAll( cfg.toJndiEnvironment() );
75
76 new InitialDirContext( env );
77
78 if (log.isInfoEnabled())
79 {
80 log.info( "server: started in {} milliseconds",
81 ( System.currentTimeMillis() - startTime ) + "");
82 }
83
84 while ( true )
85 {
86 try
87 {
88
89 Thread.sleep( 20000 );
90 }
91 catch ( InterruptedException e )
92 {
93 }
94
95 env.putAll( new SyncConfiguration().toJndiEnvironment() );
96 new InitialDirContext( env );
97 }
98 }
99 }