apache > ws.apache
Pubscribe
 

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.

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

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
Note
Many of the operations in the AbstractResourceHome may be overridden in your Home class, if you have a need to extend its functionality.

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.
Note
If you choose to not use the createInstance() method (e.g. if you have a non-empty constructor), then you must manually set the EPR then call the init() method on the resource. The generated home class contains a utility method from the AbstractResourceHome that can be used to build an EPR.