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 data types are in the powersoft.datawindow.event package):

    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:

NoteUsing server component methods with the DTC If you are using the Web DataWindow DTC or the Web Target object model, you can use methods of the server component by using the Component property. For example:

webDW.connectToComponent();
webDW.Component.SetServerServiceClasses
		("UpdateStart");

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);
		}
)