ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

iText RPG-Java Sample Program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • iText RPG-Java Sample Program

    I was able to work on this a little today, and found the issue I was having this weekend. Here's a quick working example. There are instructions at the top of the program.


    Code:
     ***********************************************************************   
     *                                                                         
     * Program - ITEXT1                                                        
     *                                                                         
     * Written By - Michael Catalani                                           
     *              901.672.7572                                               
     *                                                                         
     * This program will create a PDF document consisting of 5 test pages.     
     * In order to run this example, you must do the following:                
     *                                                                         
     *   1. Install the iText Version 5.1.1 Jar from                           
     *      [URL]http://itextpdf.com/download.php[/URL] (choose the java download)        
     *                                                                         
     *   2. Place the iTextPdf-5.1.1.jar file on your IFS                      
     *      (I placed mine in a path called /java/itext/itextpdf-5.1.1.jar)    
     *                                                                         
     *   3. If you have a prior version of iText installed, then               
     *      comment out the /define itext511 statement, and uncomment the      
     *      /define iText212u statement.  Otherwise, if you are installing     
     *      iText 5.1.1, then skip this step.                                  
     *                                                                         
     *   4. Change the classpath in the ITEXT1C cl program to the path you     
     *      installed the iText jar file, and compile the program.             
     *                                                                            
     *   5. Call the ITEXT1C program.                                             
     *                                                                            
     *   6. Change this program (ITEXT1) to a filepath of where you want the      
     *      PDF to be created.                                                    
     *      (FilePath = Java_NewString( '/ifstest/test.pdf' ); )                  
     *      Change this path to a valid path on your IFS.                         
     *                                                                            
     *   7. Run the ITEXT1 program.                                               
     *                                                                            
     **************************************************************************   
                                                                                  
    h Option( *nodebugio : *SrcStmt )                                             
    h DftActGrp( *No ) ActGrp( *New )                                             
    h Thread( *Serialize )                                                        
                                                                                  
                                                                                  
     **************************************************************************   
     *  iText Version Selector                                                    
     *        Uncomment the iTextapi version you are using.                       
     *        Comment the one(s) you are not using out.                           
     **************************************************************************   
     *                                                                            
     /define iText511                                                             
     */define iText212u                                                           
                                                                                  
     **************************************************************************   
     *  iText 5.1.1 Class Name Constants                                          
     **************************************************************************   
     *                                                                            
     /if defined( iText511 )                                                      
                                                                                  
    d iTextDocumentCLASS...                                                       
    d                 c                   'com.itextpdf.text.Document'            
                                                                                  
    d iTextPdfWriterCLASS...                                                      
    d                 c                   'com.itextpdf.text.pdf.PdfWriter'       
                                                                                  
    d iTextParagraphCLASS...                                                      
    d                 c                   'com.itextpdf.text.Paragraph'           
                                                                                  
    d iTextElementCLASS...                                                        
    d                 c                   'com.itextpdf.text.Element'             
     /endif                                                                       
                                                                                  
     **************************************************************************   
     *  iText 2.1.1u Class Name Constants                                         
     **************************************************************************   
     *                                                                             
     /if defined( iText212u )                                                      
                                                                                   
    d iTextDocumentCLASS...                                                        
    d                 c                   'com.lowagie.text.Document'              
                                                                                   
    d iTextPdfWriterCLASS...                                                       
    d                 c                   'com.lowagie.text.pdf.PdfWriter'         
                                                                                   
    d iTextParagraphCLASS...                                                       
    d                 c                   'com.lowagie.text.Paragraph'             
                                                                                   
    d iTextElementCLASS...                                                         
    d                 c                   'com.lowagie.text.Element'               
                                                                                   
     /endif                                                                        
                                                                                   
     **************************************************************************    
     *   Java Class Name Constants                                                 
     **************************************************************************    
     *                                                                             
    d JavaIoStreamCLASS...                                                         
    d                 c                   'java.io.OutputStream'    
    d JavaFileIoStreamCLASS...                                                  
    d                 c                   'java.io.FileOutputStream'            
                                                                                
    d JavaStringCLASS...                                                        
    d                 c                    'java.lang.String'                   
                                                                                
     ************************************************************************** 
     *   Java Object Descriptions                                               
     ************************************************************************** 
     *                                                                          
                                                                                
    d iTextDocument   s               o   Class(  *Java                         
    d                                           : iTextDocumentCLASS )          
                                                                                
    d iTextPdfWriter  s               o   Class(  *Java                         
    d                                           : iTextPdfWriterCLASS )         
                                                                                
    d ITextParagraph...                                                         
    d                 s               o   Class(  *Java                         
    d                                           : iTextParagraphCLASS )         
                                                                                
    d ITextElement...                                                           
    d                 s               o   Class(  *Java                         
    d                                           : iTextElementCLASS ) 
    
                                                                                
    d jFileOutputStream...                                                      
    d                 s               o   Class(  *Java                         
    d                                           : JavaFileIoStreamCLASS )       
                                                                                
    d jOutputStream...                                                          
    d                 s               o   Class(  *Java                         
    d                                           : JavaIoStreamCLASS )           
                                                                                
     ************************************************************************** 
     *   Java Constructors                                                      
     ************************************************************************** 
     *                                                                          
    d iText_NewDocument...                                                      
    d                 pr                  Like( iTextDocument )                 
    d                                     ExtProc(  *Java                       
    d                                             : iTextDocumentCLASS          
    d                                             : *Constructor )              
                                                                                
    d iText_NewParagraph...                                                     
    d                 pr                  ExtProc(  *Java                       
    d                                             : iTextParagraphCLASS         
    d                                             : *Constructor )              
    d                                     Like( iTextParagraph )                          
    d  jString                            Like( jString )                         
                                                                                  
    d Java_NewString...                                                           
    d                 pr                  Like( jString )                         
    d                                     ExtProc(  *Java                         
    d                                             : JavaStringCLASS               
    d                                             : *Constructor )                
    d                            65535a   Varying Const                           
                                                                                  
    d Java_NewFileIoStream...                                                     
    d                 pr                  Like( jFileOutputStream )               
    d                                     ExtProc(  *Java                         
    d                                             : JavaFileIoStreamCLASS         
    d                                             : *Constructor )                
    d  jString                            Like( jString )                         
                                                                                  
     **************************************************************************   
     *   Java Methods                                                             
     **************************************************************************   
     *                                                                            
    d iText_DocumentOpen...                                                       
    d                 pr                  ExtProc(  *Java                         
    d                                             : iTextDocumentCLASS            
    d                                             : 'open')               
                                                                             
    d iText_DocumentClose...                                                 
    d                 pr                  ExtProc(  *Java                    
    d                                             : iTextDocumentCLASS       
    d                                             : 'close' )                
                                                                             
    d iText_DocumentNewPage...                                               
    d                 pr              n   ExtProc(  *Java                    
    d                                             : iTextDocumentCLASS       
    d                                             : 'newPage')               
                                                                             
    d iText_DocumentAddParagraph...                                          
    d                 pr              n   ExtProc(  *Java                    
    d                                             : iTextDocumentCLASS       
    d                                             : 'add' )                  
    d  iTextElement                       Like( iTextElement )               
                                                                             
    d iText_GetInstance...                                                   
    d                 pr                  ExtProc(  *Java                    
    d                                             : iTextPdfWriterCLASS      
    d                                             : 'getInstance' )          
    d                                     Static                             
    d                                     Like( iTextPdfWriter )             
    d  iTextDocument                      Like( iTextDocument )              
    d  jOutputStream                      Like( jOutputStream )          
                                                                         
                                                                         
     /copy Qsysinc/Qrpglesrc,Jni                                         
                                                                         
    d Document        s                   Like( iTextDocument )          
    d Paragraph       s                   Like( iTextParagraph )         
    d Data            s                   Like( jString )                
    d FilePath        s                   Like( jString )                
    d FileIoStream    s                   Like( jFileOutputStream )      
    d PageNumber      s             10i 0                                
                                                                         
     /free                                                               
                                                                         
       //********************************************************        
       // Warning - no garbage cleanup code has been put in place        
       //********************************************************        
                                                                         
                                                                         
       // Create the file path stream to the PDF document                
       FilePath = Java_NewString( '/ifstest/test.pdf' );                 
       FileIoStream = Java_NewFileIoStream( FilePath );                  
                                                                         
       // Create a new document instance                                 
    
       Document = iText_NewDocument();                                      
       iText_GetInstance( Document : FileIoStream );                        
                                                                            
       // Open document                                                     
       iText_DocumentOpen( Document );                                      
                                                                            
       // Write out 5 test pages                                            
       for PageNumber = 1 to 5;                                             
         iText_DocumentNewPage( Document );                                 
         Data = Java_NewString( 'Data For Page - ' + %char( PageNumber ));  
         Paragraph = iText_NewParagraph( Data );                            
         iText_DocumentAddParagraph( Document   : Paragraph );              
       endfor;                                                              
                                                                            
       // Close the document                                                
       iText_DocumentClose( Document );                                     
                                                                            
       return;                                                              
                                                                                                 
                       [SIZE=2][COLOR=#0000aa][SIZE=2][COLOR=#0000aa]
    [/COLOR][/SIZE][/COLOR][/SIZE]


    And here's a CL program that can be called to set up the classpath. You will need to modify this program to change the classpathif you put the iText jar file in a different IFS directory. You will also need to change the library of where the ITEXT1 program is located. (Mine is in a library called ITEXT)

    Code:
    PGM                                                     
                                                            
     ADDLIBLE ITEXT *LAST                                   
     MONMSG CPF2103                                         
                                                            
     ADDENVVAR ENVVAR(CLASSPATH) +                          
               VALUE('/JAVA/ITEXT/ITEXTPDF-5.1.1.JAR') +    
               LEVEL(*JOB) +                                
               REPLACE(*YES)                                
                                                            
     ADDENVVAR ENVVAR(QIBM_RPG_JAVA_PROPERTIES) +           
                VALUE('-DJAVA.AWT.HEADLESS=TRUE;+           
                       -DOS400.AWT.NATIVE=TRUE;') +         
                REPLACE(*YES)                               
     ENDPGM
    Michael Catalani
    IS Director, eCommerce & Web Development
    Acceptance Insurance Corporation
    www.AcceptanceInsurance.com
    www.ProvatoSys.com

  • #2
    Re: iText RPG-Java Sample Program

    I like this... I hope I can get some free time and throw a wrecking on it..

    jamie
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: iText RPG-Java Sample Program

      I will eventually redesign everything into a service program. It probably wont include every method available in iText, because there are a lot of them. But I would like to be able to at least include tables, images, and barcodes.
      Michael Catalani
      IS Director, eCommerce & Web Development
      Acceptance Insurance Corporation
      www.AcceptanceInsurance.com
      www.ProvatoSys.com

      Comment


      • #4
        Re: iText RPG-Java Sample Program

        I edited the program. It now includes:

        1. Named constants for the class names.
        2. The ability to switch between iText 5.1.1 and iText 2.1.2u.

        There's a /define statement for both the 5.1.1 and 2.1.2u iText version. Whichever version of iText you are using, simply uncomment that /define statement, and comment out the other. This will create the proper class name constants for the version of iText you are running.
        Michael Catalani
        IS Director, eCommerce & Web Development
        Acceptance Insurance Corporation
        www.AcceptanceInsurance.com
        www.ProvatoSys.com

        Comment


        • #5
          Re: iText RPG-Java Sample Program

          I used iText to create a PDF order confirmation at my current employer. The way I did it was to wrap up all of the iText calls into a little Java application. Then from my RPG program I just called simple setter methods to set the data that would appear on the PDF. To retrieve the PDF I used a buffer output stream and read from the buffer in slices. In the RPG I could then add these slices to a pointer and then stream it out to browser using CGIDEV2.

          The reason I did this was to try and keep the RPG to Java interface as simple as possible. There are some aspects of Java such as exceptions, arrays or generics which are not handled all that well from RPG. I believe you can monitor for an exception with a monitor block but this writes out to the job log and there is no way that I know of to distinguish the type of exception. I don't think RPG handles generics at all as this is something the Java compiler sorts out at compile time. I don't know of any construct in RPG to do the equivalent of this:
          PHP Code:
           List<StringstringList = new ArrayList<String>(); 
          To do the prototypes for RPG I wrote a little Java program that uses reflection. It looks through the methods for a particular class and then generates the prototypes for you. Now I have to tell you that this is very rough and ready. I'm not particularly proud of the code, however, it did save me quite a bit of time with something that it is quite a boring task.

          I haven't run this program in a long time but I can tell you that it doesn't get it 100% right. It will include all methods in the class which includes those inherited from Object. You probably won't want these. It doesn't really handle overloading that well either. In Java you can have two methods with the same name as long as they have different parameters, in RPG you need a different procedure name. These two issues could be sorted easily enough given a bit of time.

          Some of the data types don't work 100% either. From memory I think the problems arise if you have an array as a parameter. If you define an array as a parameter in Java then you can pass an array of any size. In RPG you can't do this and it needs to be a fixed size. This is probably the hardest issue to sort out as it requires knowing a bit about the calling RPG program. I guess once you have found these you could prompt the user to enter a fixed size.

          There is no gui for this. It's literally just a quick and dirty bit of code that I wrote to save me some time. Now that the disclaimers are out of the way... here's the code.

          PHP Code:
          import java.io.*;
          import java.lang.reflect.*;
          import java.util.ArrayList;
          import java.util.Iterator;
          import java.util.List;

          public class 
          PrototypeGenerator 
          {
              private 
          BufferedWriter out;
              private Class 
          className;
              private 
          String fullClassName;
              
              private static final 
          int D_SPEC_CHARS 34;
              
              public 
          PrototypeGenerator(Class className)
              {
                  
          this.className className;
                  
          this.fullClassName this.className.getName();
                  try 
                  {
                      
          out = new BufferedWriter(new FileWriter("prototypes.txt"));
                  } catch (
          IOException e) {
                      
          e.printStackTrace();
                  }
              }
              
              public 
          void writeFile() throws IOException
              
          {
                  
          //writeConstructors();
                  
          writeMethods();

                  
          out.close();
              }
              

              private 
          void writeMethods() throws IOException
              
          {
                  
          Method[] methods this.className.getMethods();
                  for(
          int count=0count<methods.lengthcount++)
                  {
                      
          // Only prototype public methods
                      
          if(Modifier.isPublic(methods[count].getModifiers()))
                      {
                          
          writeMethod(methods[count]);
                      }
                  }
              }

              private 
          void writeMethod(Method methodthrows IOException 
              
          {
                  
          // Output the procedure name
                  
          out.write("     D "+method.getName()+"...");
                  
          out.write("\n");
                  
          out.write("     D                 PR");
                  
                  
          // Output the return type
                  
          Class returns method.getReturnType();
                  
          boolean requiresClassname;
                  
          requiresClassname writeReturnType(returns);

                  
          // Now all the Java details
                  
          out.write("\n");
                  
          out.write("     D                                     EXTPROC(*JAVA:");
                  
          out.write("\n");
                  
                  
          // Divide and display the class name
                  
          writeClassName();
                  
                  
          // Output the method name we are exporting
                  
          writeMethodName(method);
                  
                  
          /*
                   * If there was an object being returned then we need the 
                   * classname.
                   */
                  
          if(requiresClassname)
                  {
                      
          writeReturnsClassName(returns);
                  }
                  
                  
          // Does this method have any parameters?
                  
          Class[] parameterTypes;
                  
          parameterTypes method.getParameterTypes();
                  for(
          int countParms=0countParms<parameterTypes.lengthcountParms++)
                  {
                      
          writeParm(parameterTypes[countParms],countParms);
                  }
                  
                  
          out.write("\n");
                  
          out.write("\n");
              }

              private 
          void writeReturnsClassName(Class returnsthrows IOException 
              
          {
                  
          Iterator<StringnameParts;
                  
          out.write("     D                                     Class(*JAVA:");
                  
          out.write("\n");
                  
          nameParts divideName(returns.getName());
                  
          out.write("     D                                     '");
                  while(
          nameParts.hasNext())
                  {
                      
          out.write(nameParts.next());
                      if(
          nameParts.hasNext())
                      {
                          
          out.write("-");
                          
          out.write("\n");
                          
          out.write("     D                                     ");
                      }else{
                          
          out.write("')");
                          
          out.write("\n");
                      }
                  }
              }

              private 
          void writeMethodName(Method methodthrows IOException {
                  
          Iterator<StringnameParts;
                  
          String part;
                  
          nameParts divideName(method.getName());
                  
          out.write("     D                                     :'");
                  while(
          nameParts.hasNext())
                  {
                      
          part nameParts.next();
                      
          out.write(part);
                      if(
          nameParts.hasNext())
                      {
                          
          out.write("-");
                          
          out.write("\n");
                          
          out.write("     D                                     ");
                      }else{
                          
          out.write("')");
                          
          out.write("\n");
                      }
                  }
              }

              private 
          void writeClassName() throws IOException 
              
          {
                  
          Iterator<StringnameParts divideName(this.fullClassName);
                  
          String part;
                  
          out.write("     D                                     '");
                  while(
          nameParts.hasNext())
                  {
                      
          part nameParts.next();
                      
          out.write(part);
                      if(
          nameParts.hasNext())
                      {
                          
          out.write("-");
                          
          out.write("\n");
                          
          out.write("     D                                     ");
                      }else{
                          
          out.write("'");
                          
          out.write("\n");
                      }
                  }
              }

              private 
          boolean writeReturnType(Class returns)
                      
          throws IOException 
              
          {
                  
          boolean requiresClassname false;
                  if(!
          returns.getName().equals("void"))
                  {
                      if(
          returns.getName().equals("int")){
                          
          out.write("            10i 0");
                      }else if(
          returns.getName().equals("long")){
                          
          out.write("            20i 0");
                      }else if(
          returns.getName().equals("short")){
                          
          out.write("             5i 0");
                      }else if(
          returns.getName().equals("float")){
                          
          out.write("             4f  ");    
                      }else if(
          returns.getName().equals("double")){
                          
          out.write("             8f  ");        
                      }else if(
          returns.getName().equals("byte")){
                          
          out.write("             1a   ");        
                      }else if(
          returns.getName().equals("char")){
                          
          out.write("             1a   ");        
                      }else if(
          returns.getName().equals("boolean")){
                          
          out.write("              n   ");        
                      }else if(
          returns.getName().equals("[Z")){
                          
          out.write("              n   Dim(1) Options(*VARSIZE)");    
                      }else if(
          returns.getName().equals("[B")){
                          
          out.write("         10000a   ");        
                      }else if(
          returns.getName().equals("[C")){
                          
          out.write("             1a   Dim(1) Options(*VARSIZE)");        
                      }else if(
          returns.getName().equals("[D")){
                          
          out.write("             8f   Dim(1) Options(*VARSIZE)");
                      }else if(
          returns.getName().equals("[F")){
                          
          out.write("             4f   Dim(1) Options(*VARSIZE)");
                      }else if(
          returns.getName().equals("[I")){
                          
          out.write("            10i 0 Dim(1) Options(*VARSIZE)");
                      }else if(
          returns.getName().equals("[J")){
                          
          out.write("            20i 0 Dim(1) Options(*VARSIZE)");
                      }else if(
          returns.getName().equals("[S")){
                          
          out.write("             5i 0 Dim(1) Options(*VARSIZE)");
                      }else{
                          
          out.write("              O");
                          
          requiresClassname true;
                      }
                  }
                  return 
          requiresClassname;
              }

              
          /**
               * There's only enough space for 37 chars on the D spec for 
               * names so we must divide them up and continue on the next
               * line.
               * @param name
               * @return Iterator over a list of the divided parts
               */
              
          private Iterator<StringdivideName(String name)
              {
                  List<
          StringnameParts = new ArrayList<String>();
                  
                  
          int beginIndex 0;
                  
          int endIndex;
                  if(
          name.length()<=D_SPEC_CHARS)
                  {
                      
          endIndex name.length();
                  }else{
                      
          endIndex D_SPEC_CHARS;
                  }
                  
                  while(
          beginIndex<name.length())
                  {
                      
          nameParts.add(name.substring(beginIndexendIndex));
                      
                      
          beginIndex=endIndex;
                      if((
          name.length()-beginIndex+1)<=D_SPEC_CHARS)
                      {
                          
          endIndex name.length();
                      }else{
                          
          endIndex beginIndex+D_SPEC_CHARS;
                      }
                  }
                  
                  return 
          nameParts.iterator();
              }
              
              private 
          void writeParm(Class parameterTypeint parmNum)
                      
          throws IOException 
              
          {
                  
          out.write("     D parm"+parmNum+"...");
                  
          out.write("\n");
                  
          out.write("     D");
                  
                  
          // Is it an object or a primitive type?
                  
          if(parameterType.getName()=="int"){
                      
          out.write("                               10i 0 Value");
                      
          out.write("\n");
                  }else if(
          parameterType.getName()=="long"){
                      
          out.write("                               20i 0 Value");
                      
          out.write("\n");
                  }else if(
          parameterType.getName()=="short"){
                      
          out.write("                                5i 0 Value");
                      
          out.write("\n");
                  }else if(
          parameterType.getName()=="float"){
                      
          out.write("                                4f   Value");
                      
          out.write("\n");    
                  }else if(
          parameterType.getName()=="double"){
                      
          out.write("                                8f   Value");
                      
          out.write("\n");        
                  }else if(
          parameterType.getName()=="byte"){
                      
          out.write("                                1a   Value");
                      
          out.write("\n");        
                  }else if(
          parameterType.getName()=="char"){
                      
          out.write("                                1a   Value");
                      
          out.write("\n");        
                  }else if(
          parameterType.getName()=="boolean"){
                      
          out.write("                                 n   Value");
                      
          out.write("\n");        
                  }else if(
          parameterType.getName()=="[Z"){
                      
          out.write("                                 n   Value Dim(1) Options(*VARSIZE)");
                      
          out.write("\n");        
                  }else if(
          parameterType.getName()=="[B"){
                      
          out.write("                                1a   Value Dim(1) Options(*VARSIZE)");
                      
          out.write("\n");        
                  }else if(
          parameterType.getName()=="[C"){
                      
          out.write("                                1a   Value Dim(1) Options(*VARSIZE)");
                      
          out.write("\n");        
                  }else if(
          parameterType.getName()=="[D"){
                      
          out.write("                                8f   Value Dim(1) Options(*VARSIZE)");
                      
          out.write("\n");
                  }else if(
          parameterType.getName()=="[F"){
                      
          out.write("                                4f   Value Dim(1) Options(*VARSIZE)");
                      
          out.write("\n");
                  }else if(
          parameterType.getName()=="[I"){
                      
          out.write("                               10i 0 Value Dim(1) Options(*VARSIZE)");
                      
          out.write("\n");
                  }else if(
          parameterType.getName()=="[J"){
                      
          out.write("                               20i 0 Value Dim(1) Options(*VARSIZE)");
                      
          out.write("\n");
                  }else if(
          parameterType.getName()=="[S"){
                      
          out.write("                                5i 0 Value Dim(1) Options(*VARSIZE)");
                      
          out.write("\n");
                  }else{
                      
          out.write("                                 O   Class(*JAVA:");
                      
          out.write("\n");
                      
          // Is it an array?
                      
          String name parameterType.getName();
                      
          boolean isArray false;
                      if(
          parameterType.getName().substring(02).equals("[L"))
                      {
                          
          isArray true;
                          
          name name.substring(2name.length()-1);
                      }
                      
          Iterator<StringnameParts divideName(name);
                      
          String part;
                      
          out.write("     D                                     '");
                      while(
          nameParts.hasNext())
                      {
                          
          part nameParts.next();
                          
          out.write(part);
                          if(
          nameParts.hasNext())
                          {
                              
          out.write("-");
                              
          out.write("\n");
                              
          out.write("     D                                     ");
                          }else{
                              
          out.write("')");
                              
          out.write("\n");
                          }
                      }
                      
          out.write("     D                                     Const");
                      if(
          isArray)
                      {
                          
          out.write(" Dim(1) Options(*VARSIZE)");
                      }
                  }
              }

              
              
          /**
               * @param args
               */
              
          public static void main(String[] args
              {
                  
          /*
                   * This is quite crude really. We simply pass the class to the
                   * constructor and then get it to writeFile(). This writes out
                   * to a text file in the default folder where ever this program
                   * is being executed. The file is called prototypes.txt and 
                   * must be opened in wordpad or something similar. For some
                   * reason notepad gets a bit confused with the line breaks.
                   */
                  
          PrototypeGenerator pg = new PrototypeGenerator(String.class);
                  
                  try 
                  {
                      
          pg.writeFile();
                  } catch (
          IOException e) {
                      
          e.printStackTrace();
                  }
                  
                  
          System.out.println("Done...");
              }


          Please feel free to reuse this code. You could use it as a simple time saver like me. I generated the prototypes for each class and then manually corrected them by removing prototypes I didn't need, de-duplicating procedure names and sorting out array parameters. It could be improved so that these manual interventions aren't required. There will always be a few issues though with things that don't match that well between the two languages.

          p.s. I've also just remembered that it doesn't yet do constructors but you could expand it to do this if you wanted. I didn't bother because I typically only wanted one per class so it didn't take long to do manually.
          Ben

          Comment


          • #6
            Re: iText RPG-Java Sample Program

            Originally posted by BenThurley View Post
            To do the prototypes for RPG I wrote a little Java program that uses reflection. It looks through the methods for a particular class and then generates the prototypes for you. Now I have to tell you that this is very rough and ready. I'm not particularly proud of the code, however, it did save me quite a bit of time with something that it is quite a boring task.
            Thanks Ben!

            You kind of read my mind. I had thought that a really cool RPG tool would be to have a utility program read a jar file, and then automatically generate the object fields, method prototypes, and constructors into a copy member. I gave myself a headache trying to think how I wanted to handle things like overloading.
            Michael Catalani
            IS Director, eCommerce & Web Development
            Acceptance Insurance Corporation
            www.AcceptanceInsurance.com
            www.ProvatoSys.com

            Comment


            • #7
              Re: iText RPG-Java Sample Program

              No problem. That code is quite crude really but you may be able to expand it into something more useful. To handle the overloading you could add a simple 1,2 or 3 to the end of the method name. I guess you could also write a gui that allows you to choose which methods you want to prototype. The gui could also identify any array parameters and allow you to choose a fixed number of elements, although in many cases this may not make much sense and you might be better off using a different method.

              Possibly the hardest part would be loading the jar in at runtime and discovering the classes to prototype.

              At the least it saved me a bit of time by getting the prototypes started.
              Ben

              Comment

              Working...
              X