View Javadoc

1   /*
2    *   Copyright 2004 The Apache Software Foundation
3    *
4    *   Licensed under the Apache License, Version 2.0 (the "License");
5    *   you may not use this file except in compliance with the License.
6    *   You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *   Unless required by applicable law or agreed to in writing, software
11   *   distributed under the License is distributed on an "AS IS" BASIS,
12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *   See the License for the specific language governing permissions and
14   *   limitations under the License.
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                  // this is a big time cludge for now to just play
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  }