![]() ![]() ![]() ![]() |
Reading Objects from the Directory |
In the serialization example, you saw that an object that was stored (serialized) into the directory could be read back using Context.lookup()
:
// Check that it is bound Button b2 = (Button)ctx.lookup("cn=Button"); System.out.println(b2);Similarly, in the reference example
and the attributes example
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. 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
lesson.
![]() ![]() ![]() ![]() |
Reading Objects from the Directory |