Previous | Next | Trail Map | Tips for LDAP Users | Miscellaneous

Storing Objects

In the Objects (in the Java Objects and the Directory trail) trail, you saw how to store and read Java objects from the directory. Specifically, in the LDAP Directories (in the Java Objects and the Directory trail) section, you learned how Java objects are presented as attributes in an LDAP directory. If you have not yet gone through that trail, you might want to at least read through it to understand some of the terminology before going further.

The LDAP Directories (in the Java Objects and the Directory trail) section and RFC 2713 describe the representation of a Reference (in the API reference documentation) as LDAP attributes. By default, the hash character ("#") is used to encode the RefAddr (in the API reference documentation) in the Reference. If this character already appears in the contents of the RefAddr, then you need to choose another character to use. You do this by setting the "java.naming.ldap.ref.separator" environment property to a string containing the separator character. Here's an example.

If you run the reference example (in the Java Objects and the Directory trail) , and then examine the "cn=favorite" entry in the directory, you will see the following attributes:

objectclass: top, javaContainer, javaObject, javaNamingReference
javaclassname: Fruit 
javafactory: FruitFactory
javareferenceaddress: #0#fruit#orange
cn: favorite

You can modify that example to use the colon character (":") as the separator, as follows:

// Ask to use ':' as the encoding character
env.put("java.naming.ldap.ref.separator", ":");

// Create the initial context
DirContext ctx = new InitialDirContext(env);

// Create object to be bound
Fruit fruit = new Fruit("orange");

// Perform bind
ctx.rebind("cn=favorite", fruit);
The modified program produces attributes that look as follows:
objectclass: top, javaContainer, javaObject, javaNamingReference
javaclassname: Fruit
javafactory: FruitFactory
javareferenceaddress: :0:fruit:orange
cn: favorite


Previous | Next | Trail Map | Tips for LDAP Users | Miscellaneous