Here are some examples of how object factories are used to read the objects created in the Storing Objects in the Directory lesson and the State Factories lesson.
- Reference example . The object factory FruitFactory is used because its class name is identified in the reference. The factory creates an instance of Fruit.
- Attributes example . The client programs (lookup, list, and search) set the Context.OBJECT_FACTORIES environment property to "DrinkFactory" so that NamingManager.getObjectInstance() will load and instantiate DrinkFactory to create an instance of Drink.
- Serialization example . No object factory is used. The serialized object (an instance of java.awt.Button) is returned unchanged by the NamingManager.getObjectInstance().
- Remote reference example . The RMI URL context factory turns the RMI URL stored in a reference in the directory into an RMI stub found in the RMI registry.
- Remote (JRMP) object example . An object factory (bundled with the service provider) turns the marshalled object of the RMI stub stored in the directory back into an RMI stub.
- Remote (IIOP) object example . An object factory (bundled with the service provider) turns the stringified CORBA object reference stored in the directory into a live CORBA object.
- CORBA example . An object factory (bundled with the service provider) turns the stringified CORBA object reference stored in the directory into a live CORBA object.
- Custom object example . The object factory PersonObjectFactory turns an LDAP entry (represented by a set of attributes) into a Person object. PersonObjectFactory is identified in the application resource file used by the client program (CustomObj).
The rest of this lesson describes the object factories FruitFactory, DrinkFactory, and PersonObjectFactory.