directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Denis Robert <drob...@bfm.bm>
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);
		entry.add(typeRegistry.lookup("m-singleValue"),
String.valueOf(singleValue));

(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(),
				schemaName);

for an objectclass:

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

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

e.g., for an attributetype:

service.getRegistries().getAttributeTypeRegistry().register(myattributetype);

for an objectclasss:

service.getRegistries().getObjectClassRegistry().register(myobjectclass);

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
above).




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
> www.iktek.com
> directory.apache.org
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Loading-custom-schemas-with-AbstractServerTest-under-1.5.4-tp19485510p22566076.html
Sent from the Apache Directory Project mailing list archive at Nabble.com.


Mime
View raw message