IBM WebSphere Multichannel Bank Transformation Toolkit, Version 7.1

Using the JXFSPrt Service

About this task

The following is an example of a operation using the JXFS Printer Service. First, in this example, there is a synchronous print of a form called form01, using the media called ma4 and the jxfsFormat receipt. All that is needed is to obtain the jxfsFormat and call the printFormSync function with these parameters. A waitForPaper call causes the service to wait for the document to be ready to print.

Next, there is an asynchronous print of raw data. The operation registers itself for the events of the asynchronous function by means of the handleEvents method (it inherits this from the DSEHandler), and using a reference to the apJxfsPrt service alias. To manage the events, the dispatchEvent method is used; where the application operation receives the OperationCompleteEvent, it checks the identificationID to be sure it corresponds to the printing operation and then checks the return code.

The following is an example of using this service:

XML service definition:

<JXFSPrt id="DocPrinter" DeviceName="DocuPrinter" UseAllFields="never" 
    AutomaticOpen="true" JXFSIniConfig="c:\\jxfs\\jxfs.cfg"/>

XML context definition:

<context id=workstation type=wks>
    <refKColl refId="workstation">
    </refKColl>
    <refService refId="DocPrinter" alias="apJxfsPrt"/>
</context>

XML format definition, corresponding to the form to print:

<fmtDef id="receipt">
  <jxfsForm dataName="kcollName">
    <fstring dataName="username"/>
    <fDate dataName="date"/><fstring dataName="address"/><jxfsFieldLabel 
        value="customerAddress"/>
  </jxfsForm>
</fmtDef>

Application flow:

// Synchronous printing of a form in an operation execution

JXFSPrt prt = getContext().getService("apJxfsPrt");
try { 
  // not necessary doing prt.openSync(), because it has been specified AutomaticOpen = true.
  if (prt.waitOpen(60000))
    if (prt.claim(60000)) { 
      JxfsFormat jxfmt = (JxfsFormat)FormatElement.readObject("receipt");
      prt.waitForPaper(0);
      prt.printFormSync("form01", "ma4", jxfmt, getContext());
      if (!prt.release(60000) ) 
      System.out.println ("timeout releasing device"); // there should be any user way 
                                                       // to try to release the printer 
      }
      else
          System.out.println ("timeout claiming device");
  else System.out.println ("timeout opening device");
catch ( JxfsException jxfse) {
  // analyze jxfsE.errorCode
  .
  .
  System.out.println("JxfsException: " + jxfse.description);
}
..// Asynchronous printing of some raw data
// The operation to do this must inherit from DSEHandler or implement Handler, 
// to manage the events posted by the JxfsPrt service.
// If it inherits form DSEHandler:
this.handleEvent ("allEvents", "apJxfsPrt", getContext()); 
String st = "Text to print. May be constant like this or passed from other methods";
try {
if (prt.waitOpen(60000))
  if (prt.claim(60000)) { 
    prt.waitForPaper(0);
    identificationID = prt.printRawData( st.getBytes() , false ); 
    //identificationID must be 
    //operation attribute
  else
    System.out.println ("timeout claiming device");
  else System.out.println ("timeout opening device");
    catch ( JxfsException jxfse) {
    // analyze jxfsE.errorCode
    .
    .
    System.out.println("JxfsException: " + jxfse.description);
}
.
// Event management:
public com.ibm.dse.base.Handler dispatchEvent(com.ibm.dse.base.DSEEventObject anEvent) {
  if (anEvent.getName().equals("OperationCompleteEvent")) 
    if (anEvent.getParameters().get("identificationID").intValue() = = identificationID) 
      if (anEvent.getParameters().getResult().intValue()= = JXFS_RC_SUCCESSFUL)
        if (!prt.release(60000) ) 
          System.out.println ("timeout releasing device");
  return null; 
} 


Feedback