in apacheds-archetype-webapp/src/main/resources/archetype-resources/src/main/java/StartStopListener.java [125:168]
private void initSchema() throws Exception
{
SchemaPartition schemaPartition = directoryService.getSchemaService().getSchemaPartition();
// Init the LdifPartition
LdifPartition ldifPartition = new LdifPartition();
String workingDirectory = directoryService.getWorkingDirectory().getPath();
ldifPartition.setWorkingDirectory( workingDirectory + "/schema" );
// Extract the schema on disk (a brand new one) and load the registries
File serverWorkDirectory = new File( workingDirectory );
File schemaRepository = new File( serverWorkDirectory, "schema" );
SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( serverWorkDirectory );
if( ! schemaRepository.exists() )
{
// extract only if the schema directory is not present
extractor.extractOrCopy();
}
else
{
System.out.println( "schema partition directory exists, skipping schema extraction" );
}
schemaPartition.setWrappedPartition( ldifPartition );
SchemaLoader loader = new LdifSchemaLoader( schemaRepository );
SchemaManager schemaManager = new DefaultSchemaManager( loader );
directoryService.setSchemaManager( schemaManager );
// We have to load the schema now, otherwise we won't be able
// to initialize the Partitions, as we won't be able to parse
// and normalize their suffix DN
schemaManager.loadAllEnabled();
schemaPartition.setSchemaManager( schemaManager );
List<Throwable> errors = schemaManager.getErrors();
if ( errors.size() != 0 )
{
System.out.println( errors );
throw new RuntimeException( "there were errors while loading schema" );
}
}