Defining a service class for Java components
To create and register a service class for Java
components:
-
Make sure your Java service class is in
the system classpath. -
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. -
-
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. -
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:1dwGen.SetServerServiceClasses1("UpdateValidate;RetrieveProcess"); -
For a custom component in EAServer,
add this property in EAServer Manager:1com.sybase.datawindow.serverServiceClassesSet its value to the list of user object names, with names
separated by semicolons. For example:1UpdateValidate;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:
1 |
public void UpdateStart (UpdateEvent event, <br>   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:
1 |
import powersoft.datawindow.event.*; |
1 |
import powersoft.datawindow.*; |
1 |
1 |
public void UpdateStart (UpdateEvent event, DataStore ds) |
1 |
{ |
1 |
DataStore ds_budget; |
1 |
ds_budget = new DataStore(); |
1 |
ds_budget.setSourceFileName<br> ("c:\mydirectory\mypbd.pbd"); |
1 |
ds_budget.setDataWindowObjectName ("d_object"); |
1 |
ds_budget.setTransObject(...); |
1 |
ds_budget.retrieve( ); |
1 |
// Get data to be validated |
1 |
int rowcount = ds.getRowCount(); |
1 |
int total = 0; |
1 |
for (int i = 1; i<=rowcount;i++){ |
1 |
total=total + ds.getItemNumber(i, "expenses", |
1 |
ds.Primary); |
1 |
} |
1 |
String expense_total = ds_1.describe (...); |
1 |
double d_expense_total = Double.parseDouble |
1 |
(expense_total); |
1 |
if (d_expense_total<total){ |
1 |
event.setReturnCode(1); |
1 |
} |
1 |
)<br> |