TOC PREV NEXT INDEX


Procedure for Using the Generated C++ Encode Method


The procedure to encode an XML message using the generated C++ encode 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 encoding.
2. Create an instance of the generated type class to hold the data to be encoded.
3. Create an instance of an output stream or message buffer object to which the encoded XML message will be written.
4. Create an instance of the generated global element control class to link the generated type class instance with the message buffer or stream instance.
5. Populate the generated type class instance created in step 2 with data to be encoded.
6. Invoke the control class encode method.
7. If encoding was successful (indicated by return status equal to zero), the start-of-message pointer can be obtained by calling the message buffer getMsgPtr method (note: this assumes encoding using a message buffer was done, if a stream was used, the message has already been written to the target).
8. If encoding failed, the message buffer or stream printErrorInfo method can be invoked to print the reason for failure.
9. 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 uses this procedure to encode an employee record is as follows:

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

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

 
   // Create buffer and control objects
 

 
   try {
 
      PersonnelRecord value;
 
      OSXMLEncodeBuffer buffer;
 
      personnelRecord_CC pdu (buffer, value);
 

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

 
      // Populate structure of generated type
 

 
      ... logic to populate structure here ...
 

 
      // Encode
 

 
      stat = pdu.encode();
 

 
      if (0 == stat) {
 
         if (trace) {
 
            msgptr = buffer.getMsgPtr();
 
            printf ("encoded XML message:\n");
 
            printf ((const char*)msgptr);
 
            printf ("\n");
 
         }
 
      }
 
      else {
 
         printf ("Encoding failed\n");
 
         buffer.printErrorInfo();
 
         return stat;
 
      }
 
  
 
      // Write the encoded message out to the output file
 

 
      buffer.write (filename);
 
   }
 
   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