Defining a service class for Java components

StepsTo create and register a service class for Java components:

  1. Make sure your Java service class is in the system classpath.

  2. In your Java service class, define one or more methods. Method prototypes must match one of these (all event datatypes are in the powersoft.datawindow.event package):

    • DBError (DatabaseEvent event, DataStore ds)

    • RetrieveEnd (RetrieveEvent event, DataStore ds)

    • RetrieveStart (RetrieveEvent event, DataStore ds)

    • SQLPreview (DatabaseEvent event, DataStore ds)

    • UpdateEnd (UpdateEvent event, DataStore ds)

    • UpdateStart (UpdateEvent event, DataStore ds)

    The arguments are the same as those documented for the similarly named DataWindow, Java Edition events in the DataWindow Reference, with the exception of the additional DataStore argument, which gives the Java class access to the Web DataWindow data.

  3. In the class methods, set the return codes to specify whether the server component should cancel the event.

    The return codes are also the same as those documented in the DataWindow Reference. Any of the service classes that implements the event can specify that the event be canceled.

  4. Register the service classes for the component.

    There are two ways to make the Java class available as a service class:

    • For any component in EAServer, call the SetServerServiceClasses method in the Web page template’s server-side script:

      dwGen.SetServerServiceClasses
      
      				("UpdateValidate;RetrieveProcess");
      
    • For a custom component in EAServer, add this property in EAServer Manager:

      com.sybase.datawindow.serverServiceClasses
      

      Set its value to the list of user object names, with names separated by semicolons. For example:

      UpdateValidate;RetrieveProcess
      

Example

Suppose that you want to check that data did not exceed a budgeted total before it was updated in the database. You might set up a service class that implements the UpdateStart event.

The method declaration would be:

public void UpdateStart (UpdateEvent event, 
   DataStore ds)

The body of this method has a DataStore that retrieves data from a budget table and compares it to the component’s data:

import powersoft.datawindow.event.*;
import powersoft.datawindow.*;

public void UpdateStart (UpdateEvent event, DataStore ds)
{
		DataStore ds_budget;
		ds_budget = new DataStore();
		ds_budget.setSourceFileName
			("c:\\mydirectory\\mypbd.pbd");
		ds_budget.setDataWindowObjectName			("d_object");
		ds_budget.setTransObject(...);	
		ds_budget.retrieve( );	
		// Get data to be validated
		int rowcount = ds.getRowCount();
		int total = 0;
		for (int i = 1; i<=rowcount;i++){
			total=total + ds.getItemNumber(i, "expenses",
				ds.Primary);
		}
		String expense_total = ds_1.describe (...);
		double d_expense_total = Double.parseDouble
			(expense_total);
		if (d_expense_total<total){
			event.setReturnCode(1);
		}
)