Hi Emmanuel!
Thanks for your quick response.
Emmanuel Lecharny wrote:
I will respond in detail to you mail, but first, why not using the
annotations to start a server ?
It's way easier, you don't have to worry about what's going on and what
needs to be initialized first.
I'm also wondering if this should not be the standard way to start the
server.
I am not 100% convinced by this approach. IMHO the standard way should be
ApacheDS myServer = new ApacheDS();
myServer.start();
(simplified ;-)
Although annotations are technically interesting, IMHO using annotations
in this place will make it more difficult for people who simply try to
embed the server. Within spring configurations, within Groovy scripts,
etc. Too much magic.
If a user plans to extend the server (like the simple custom partition
in the example, or a custom interceptor), the JavaBeans approach will
always work. It is possible to readjust the Spring config etc.
I guess, it is not possible to add a custom partition with the current
annotations. And if it would be, you start to reimplement Google Guice.
Greetings from Bielefeld,
StefanZ
Let me give you an example :
package org.apache.directory.server.factory;
import org.apache.commons.io.FileUtils;
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.core.annotations.CreateDS;
import org.apache.directory.server.core.factory.DSAnnotationProcessor;
public class MyServer
{
@CreateDS( name = "myServer" )
public static void main( String[] args ) throws Exception
{
DirectoryService service =
DSAnnotationProcessor.getDirectoryService();
if ( service.isStarted() )
{
System.out.println( "Service started !" );
}
service.shutdown();
FileUtils.deleteDirectory( service.getWorkingDirectory() );
}
}
That should be enough to start a server.
You can of course define some more elements :
package org.apache.directory.server.factory;
import org.apache.commons.io.FileUtils;
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.core.annotations.CreateDS;
import org.apache.directory.server.core.factory.DSAnnotationProcessor;
public class MyBetterServer
{
@CreateDS(
name = "MethodDSWithPartition",
partitions =
{
@CreatePartition(
name = "example",
suffix = "dc=example,dc=com",
contextEntry = @ContextEntry(
entryLdif =
"dn: dc=example,dc=com\n" +
"dc: example\n" +
"objectClass: top\n" +
"objectClass: domain\n\n" ),
indexes =
{
@CreateIndex( attribute = "objectClass" ),
@CreateIndex( attribute = "dc" ),
@CreateIndex( attribute = "ou" )
} )
} )
@CreateLdapServer (
transports =
{
@CreateTransport( protocol = "LDAP" ),
@CreateTransport( protocol = "LDAPS" )
})
public static void main( String[] args ) throws Exception
{
DirectoryService service =
DSAnnotationProcessor.getDirectoryService();
if ( service.isStarted() )
{
System.out.println( "Service started !" );
}
service.shutdown();
FileUtils.deleteDirectory( service.getWorkingDirectory() );
}
}
Does this sound good to you ?