Writing a Home class
Introduction
The home class is used to lookup the resource instance. It can act as a factory for creating instances upon request, or build all instances. It is meant to be the entry point for locating a resource instance.
If you use the Wsdl2Java tool, the home class is automatically generated but will need to modified to create instances of your resource. This section will describe how to write a home class for your resource. Initially, you should model your resource off of the included FilesystemHome example to ensure that you write a valid home class for your resource.
Class Declaration
The generated home class extends AbstractResourceHome. Extending AbstractResourceHome provides services for caching instances and looking them up. It also ensures that the correct interfaces are implemented so that Apache WSRF can interact with your home.
The FileSystemHome class extends AbstractResourceHome and implements Serializable:
public class FileSystemHome extends AbstractResourceHome implements Serializable
Operations
If you extend AbstractResourceHome, the only required operation you will need to implement is:
public void init()
The init() operation can be used to initialize any instances at startup. In the FileSystem example, the init() method is used:
public void init() throws Exception { super.init(); add( createInstance( LVOL1_ID ) ); add( createInstance( LVOL2_ID ) ); }
The createInstance() method:
- Creates an instance of the resource.
- Sets an endpoint reference on the resource.
- Calls init() on the resource.