directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Denis Robert <>
Subject Re: Loading custom schemas with AbstractServerTest under 1.5.4
Date Tue, 17 Mar 2009 19:23:49 GMT

Here's my take on this. I subclassed DefaultDirectoryService, then overrode
startup(). In startup, I first call super.startup() to ensure that the
directory is properly initialized, then I populate the schema directly,
using the underlying API.

Doing this is a little involved, but it works quite well. The first step is
to create a dummy ServerEntry containing the proper attributes for the
schema object you want to create, e.g.:

ServerEntry entry = new DefaultServerEntry(service.getRegistries());
		entry.add(typeRegistry.lookup("m-oid"), oid);
		entry.add(typeRegistry.lookup("m-name"), name);
		entry.add(typeRegistry.lookup("m-description"), desc);
		entry.add(typeRegistry.lookup("m-equality"), equality);
		entry.add(typeRegistry.lookup("m-syntax"), syntax);

(the attributes in the entry can be looked up in the existing schema entries
in the ou=schema partition).

Then you use the SchemaEntityFactory to create a schema object from the
directory entry (this is how ApacheDS populates the schema internally from
schema entried in the ou=schema partition). For an attribute type:

factory.getAttributeType(entry, service.getRegistries(),

for an objectclass:

factory.getObjectClass(entry, service.getRegistries(),

Once you have the schemaEntity object, you need to register it with the
correct registry:

e.g., for an attributetype:


for an objectclasss:


et voilĂ , your schema is registered. Hope it helps.

(Of course, you could put the entities in an Ldif file, and use the
LdifReader() to build the ServerEntries instead of creating them in code as

Emmanuel Lecharny-3 wrote:
> Mark Derricutt wrote:
>> For our own tests we opted for #2, however, it'd be great if someone
>> extracted the "export to LDIF" code from Studio so that it could be
>> called
>> to convert a schema to LdifReader.  That'd be a good compromise I think.
> If you mean, convert from schema format to LDIF format, the code already 
> exists in the independent subproject shared-converted (in shared). There 
> are plenty of tests which can be used to create a working tool.
> A good idea would be to create a command line toold to provide such a 
> conversion, something which should be drafted in a couple of hours, IMO. 
> (and if someone provide it, we will be very pleased to integrate it in 
> the project !)
> -- 
> --
> cordialement, regards,
> Emmanuel LĂ©charny

View this message in context:
Sent from the Apache Directory Project mailing list archive at

View raw message