Common Methods

In this section:

All exits provide a common set of control and metadata interrogation methods. Normally, these methods are placed into your exit code when the Wizard prepares your skeleton Java source code. Usually, you only modify the init() and term() methods; the others are described here for completeness.

All exits descend from XDExitBase, providing them with common services such as parameter analysis, tracing, and so on. XDExitBase also provides "empty" versions of all required exit methods such as term(), eliminating the need for every exit to provide an implementation if the method is not needed for that exit().

Because all exits provide these methods, they are not further discussed in the sections dealing with individual exits.


Top of page

x
public void init(String[ ] parms) throws XDException

Exits may elect to implement the init() method to initialize the exit when it is loaded. The method receives parameters as configured by the console or the desinger. Parameters are passed in as a positional string array, however, services are provided to help analyze the parameters. Once analyzed, they are available by name in a HashMap. The Exit Wizards automatically provide an init() method that handles the parameters in this way. The code in the generated init() method calls upon services of the XDExitBase class from which all exits descend.

The initParms() method called by the init() method to construct the final parameter map merges the positional parameters with the named parameters from the configuration. Any positional parameters not reflected in the named parameter configuration are placed into the parm map under the name posn where n is the position number. Any user-defined parameter such as user-defined JMS headers are carried in the configuration as parameters, and appear in the parm map under the user-assigned name.

The following is an example of an init() method that your exit might implement that checks a single parameter, named armor, and sets a Boolean value to true if the configuration sets the parameter to true.

public void init(String[] parms) throws XDException
 {
   parmMap = initParms(parms,parmsMeta);
   String a = (String)parmMap.get(armor[0]);
   if (isPresent(a) && a.equals("true"))
   {
       armored=true;
   }
 }

As a convenience, the boolean getParmAsBoolean(map,name) is available to assist. You are guaranteed that all required parameters are present, and that the parameters are in the correct format – such as an integer parameter must be numeric. If parameters fail these simple validation tests, an exception is thrown by the service routine.

Programmers cannot depend on the order in which parameters (especially user parameters) are stored. Consequently, one parameter cannot depend upon the value of another parameter.

Exits may be loaded multiple times as they are paged in and out. Developers should not depend upon the init() method being called once.


Top of page

x
public void term() throws XDException

This method is called as the engine closes down all use of the exit. It is always called as the engine stops, and may be called at other times if the engine elects to page out the exit. If term() is called in such a case, the init() method is called before the exit is used again.


iWay Software