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

Storing Objects

The Java Objects and the Directory (in the Java Objects and the Directory trail) trail showed you how to store and read Java objects from the directory. Specifically, the LDAP Directories (in the Java Objects and the Directory trail) section discussed how Java objects are represented as attributes in an LDAP directory. If you have not yet gone through that trail, then before going further you might want to at least read through that trail to understand some of the terminology used here.

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 multiple 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 use another character. 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 this 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 the object to be bound
Fruit fruit = new Fruit("orange");

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


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