in embedded-sample/src/main/java/org/apache/directory/seserver/EmbeddedADSVer157.java [154:223]
private void initDirectoryService( File workDir ) throws Exception
{
// Initialize the LDAP service
service = new DefaultDirectoryService();
service.setWorkingDirectory( workDir );
// first load the schema
initSchemaPartition();
// then the system partition
// this is a MANDATORY partition
Partition systemPartition = addPartition( "system", ServerDNConstants.SYSTEM_DN );
service.setSystemPartition( systemPartition );
// Disable the ChangeLog system
service.getChangeLog().setEnabled( false );
service.setDenormalizeOpAttrsEnabled( true );
// Now we can create as many partitions as we need
// Create some new partitions named 'foo', 'bar' and 'apache'.
Partition fooPartition = addPartition( "foo", "dc=foo,dc=com" );
Partition barPartition = addPartition( "bar", "dc=bar,dc=com" );
Partition apachePartition = addPartition( "apache", "dc=apache,dc=org" );
// Index some attributes on the apache partition
addIndex( apachePartition, "objectClass", "ou", "uid" );
// And start the service
service.startup();
// Inject the foo root entry if it does not already exist
try
{
service.getAdminSession().lookup( fooPartition.getSuffixDn() );
}
catch ( LdapException lnnfe )
{
DN dnFoo = new DN( "dc=foo,dc=com" );
ServerEntry entryFoo = service.newEntry( dnFoo );
entryFoo.add( "objectClass", "top", "domain", "extensibleObject" );
entryFoo.add( "dc", "foo" );
service.getAdminSession().add( entryFoo );
}
// Inject the bar root entry
try
{
service.getAdminSession().lookup( barPartition.getSuffixDn() );
}
catch ( LdapException lnnfe )
{
DN dnBar = new DN( "dc=bar,dc=com" );
ServerEntry entryBar = service.newEntry( dnBar );
entryBar.add( "objectClass", "top", "domain", "extensibleObject" );
entryBar.add( "dc", "bar" );
service.getAdminSession().add( entryBar );
}
// Inject the apache root entry
if ( !service.getAdminSession().exists( apachePartition.getSuffixDn() ) )
{
DN dnApache = new DN( "dc=Apache,dc=Org" );
ServerEntry entryApache = service.newEntry( dnApache );
entryApache.add( "objectClass", "top", "domain", "extensibleObject" );
entryApache.add( "dc", "Apache" );
service.getAdminSession().add( entryApache );
}
// We are all done !
}