TOC PREV NEXT INDEX


Procedure for Calling C++ Decode Methods


The procedure to invoke a C++ decode method is as follows:
1. If exceptions were not disabled via the _NO_EXCEPTIONS C++ compiler switch, open a `try' block to use for message decoding.
2. Create an instance of the generated type class into which the XML message data is to be decoded.
3. Create an instance of an input stream or message buffer object from which the XML message to be decoded will be read.
4. Create an instance of the generated global element control class to link the generated type class instance with the message buffer or input stream instance.
5. Invoke the control class decode method.
6. If decoding was successful (indicated by return status equal to zero), the decoded data will now be available for use in the generated type variable. The generated print method can be called at this time to examine the contents of the data structure.
7. If decoding failed, the message buffer or stream printErrorInfo method can be invoked to print the reason for failure.
8. Close the `try' block opened in step 1 and, at a minimum, catch exceptions of type OSRTLException. The exception class getStatus method can be called to get the run-time error status code.
A program fragment that could be used to decode an employee record is as follows:

#include "employee.h"
 
#include "rtxmlsrc/rtXmlCppMsgBuf.h"
 

 
int main (int argc, char** argv)
 
{
 
   int		       i, stat;
 
   const char*  filename = "message.xml";
 
   OSBOOL       trace = TRUE, verbose = FALSE;
 

 
   try {
 
      OSFileInputStream in (filename);
 
      OSXMLDecodeBuffer decodeBuffer (in);
 
      PersonnelRecord value;
 
      personnelRecord_CC personnelRecord (decodeBuffer, value);
 

 
      if (verbose) 
 
         rtxSetDiag (personnelRecord.getCtxtPtr(), 1);
 

 
      // Decode
 

 
      stat = personnelRecord.decode();
 

 
      if (0 == stat) {
 
         if (trace) {
 
            printf ("decoded XML message:\n");
 
            personnelRecord.print ("personnelRecord");
 
            printf ("\n");
 
         }
 
      }
 
      else {
 
         printf ("Decoding failed\n");
 
         decodeBuffer.printErrorInfo();
 
         return stat;
 
      }
 
   }
 
   catch (OSSAXException& e) {
 
      printf ("SAX exception occurred, status = %d, msg = %s\n", 
 
         e.getStatus(), e.getMessage());
 
   }
 
   catch (OSRTLException e) {
 
	printf 
 
	("Run-time exception occurred, status = %d\n", e.getStatus());
 
   }
 


Objective Systems, Inc.

102 Pickering Way, Suite #506
Exton, Pennsylvania 19341
http://www.obj-sys.com
Phone: (484) 875-9841
Toll-free: (877) 307-6855 (US only)
Fax: (484) 875-9830
info@obj-sys.com
TOC PREV NEXT INDEX