Previous | Next | Trail Map | Java Objects and the Directory | Reading Objects from the Directory

Lookups

In the serialization example (in the Java Objects and the Directory trail), you saw that an object that was stored (serialized) into the directory could be read back using Context.lookup()(in the API reference documentation):

// Check that it is bound
Button b2 = (Button)ctx.lookup("cn=Button");
System.out.println(b2);

Similarly, in the reference example (in the Java Objects and the Directory trail) and the attributes example (in the Java Objects and the Directory trail) you were able to simply use Context.lookup() to retrieve the stored object.

Object Factories

In the attributes example, the environment used to create the initial context had an additional property, Context.OBJECT_FACTORIES(in the API reference documentation). This property specifies the class names of one or more object factories to use when turning information stored in the directory into Java objects expected by the application.

When the object is represented as a reference in the directory, the reference contains the class name and optionally the location of the object factory. Consequently, the reference example did not need to set the Context.OBJECT_FACTORIES property. Similarly, when an object is serialized, typically it needs only to be deserialized and not transformed any further. This was the case with the java.awt.Button example above, so again, no object factory was specified.

For the attributes example, since what is stored to represent the Drink object is just a collection of attributes, you need to specify an object factory, DrinkFactory, to use when converting those attributes to a Drink object.

Object factories are described in more detail in the Object Factories (in the Java Objects and the Directory trail) lesson.


Previous | Next | Trail Map | Java Objects and the Directory | Reading Objects from the Directory