Try OpenEdge Now
skip to main content
Application Developer's Guide
Developing Business Process Server adapters : Sample adapter code
 

Sample adapter code

The following sections explain how you can connect a Business Process Server process to a database and to a printer.

Connecting Business Process Server to a database

The following is a sample adapter, written in Java, that connects a Business Process Server process to a database using JDBC.
import java.sql.*;
import sun.jdbc.odbc.*;
public class SaveInfo {
    Connection dbConnect = null;
    public SaveInfo() {
        //initialize db connection in the constructor
        new JdbcOdbcDriver();
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            //connect to db
            dbConnect = DriverManager.getConnection(
            "jdbc:odbc:SQLServer", "sa", "");
        }
        catch (Exception e) {}
    }
    public void writeToDB() {
        try {
            Statement stmt = dbConnect.createStatement();
            stmt.execute("/*some sql statement here*/");
        }
        catch (Exception e) {}
    }
}

Connecting Business Process Server to a printer

The following is a sample adapter, written in Java, that connects a Business Process Server process to a printer. The example demonstrates classic adapter methods, as well as native methods.
public class PrintFile{
    String m_strFilename;
    String m_strPrinterFullPath;
    long m_lResult =0;
    
// classic Adapter methods
    public void setFilename(String s) { m_strFilename = s; }
    public void setPrinterFullPath(String s){ m_strPrinterFullPath=s; }
    public void printFile() {
        if (m_strPrinterFullPath.length() == 0)
        m_lResult = printFile(m_strFilename);
        else
        m_lResult = printFile(m_strFilename, m_strPrinterFullPath);
        }
    
    public Long getPrinterResult() { return new Long(m_lResult); }
    
// native methods
    public native int printFile(java.lang.String strFilename,
    java.lang.String strPrinterFullPath);
    public native int printFile(java.lang.String strFilename);
    
// loading the dll
    static {
    System.loadLibrary("CPrinter");
    System.out.println("CPrinter.dll has been loaded");
    }
}
The sample Printer Connection adapter uses four classic Java methods:
*setFileName()
*setPrinterFullPath()
*printFile()
*getPrinterResult()
The setFileName() and setPrinterFullPath()pass the values of the dataslots "FileName" (the name of the file to print) and "PrinterFullPathName" (the full path of the printer) to the adapter. The void method printFile() actually prints the file. The final method passes the values from the adapter back to the process.
The example also uses two native methods for the adapter. The first method specifies the full path name of the printer. The second method works in conjunction with the default printer. Once the shared library is loaded, you can find the implementation of these native methods in the DLL (Dynamic Link Library).
* Generating the sample adapter