in embedded-sample-trunk/src/main/java/org/apache/directory/seserver/EmbeddedADSVerTrunk.java [154:232]
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
// DO NOT add this via addPartition() method, trunk code complains about duplicate partition
// while initializing
JdbmPartition systemPartition = new JdbmPartition();
systemPartition.setId( "system" );
systemPartition.setPartitionDir( new File( service.getWorkingDirectory(), systemPartition.getId() ) );
systemPartition.setSuffix( new DN( ServerDNConstants.SYSTEM_DN ) );
systemPartition.setSchemaManager( service.getSchemaManager() );
// mandatory to call this method to set the system partition
// Note: this system partition might be removed from trunk
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.getSuffix() );
}
catch ( LdapException lnnfe )
{
DN dnFoo = new DN( "dc=foo,dc=com" );
Entry 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.getSuffix() );
}
catch ( LdapException lnnfe )
{
DN dnBar = new DN( "dc=bar,dc=com" );
Entry 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.getSuffix() ) )
{
DN dnApache = new DN( "dc=Apache,dc=Org" );
Entry entryApache = service.newEntry( dnApache );
entryApache.add( "objectClass", "top", "domain", "extensibleObject" );
entryApache.add( "dc", "Apache" );
service.getAdminSession().add( entryApache );
}
// We are all done !
}