apache > ws.apache
WSRF
 

Writing a Home class

Introduction

The home class is used to lookup resource instances. 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.

Note
If your service is a singleton and only requires a single resource instance, see the Creating a Singleton Service section.

If you use the Wsdl2Java tool, the home class is automatically generated, but will may be 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
Note
Many of the operations in the AbstractResourceHome may be overridden in your Home class, if you have a need to modify or extend the base functionality.

Operations

If you extend AbstractResourceHome, the only required operation you may wish to override 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 to create and add two resource instances:

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 the resource's EndpointReference.
  • Calls init() on the resource.