Example #1
0
 /** Build of all required standard procedures */
 static void generateOther(Table table, String output, PrintWriter outLog) {
   for (int i = 0; i < table.procs.size(); i++) {
     Proc proc = (Proc) table.procs.elementAt(i);
     if (proc.isData || proc.isStd || proc.hasNoData()) continue;
     try {
       outLog.println("Code: " + output + table.useName() + proc.upperFirst() + ".cls");
       OutputStream outFile =
           new FileOutputStream(output + table.useName() + proc.upperFirst() + ".cls");
       try {
         PrintWriter outData = new PrintWriter(outFile);
         outData.println("VERSION 1.0 CLASS");
         outData.println("BEGIN");
         outData.println("  MultiUse = -1");
         outData.println("END");
         outData.println("ATTRIBUTE VB_NAME=\"t" + table.useName() + proc.upperFirst() + "\"");
         outData.println("Option explicit");
         outData.println(
             "' This code was generated, do not modify it, modify it at source and regenerate it.");
         for (int j = 0; j < proc.comments.size(); j++) {
           String comment = (String) proc.comments.elementAt(j);
           outData.println("'" + comment);
         }
         boolean hasMulti = true;
         if (proc.inputs.size() > 0) {}
         if (proc.outputs.size() == 0 || proc.isSingle == true) hasMulti = false;
         outData.println();
         outData.println("Private Type TRec");
         for (int j = 0; j < proc.inputs.size(); j++) {
           Field field = (Field) proc.inputs.elementAt(j);
           String io;
           if (!proc.hasOutput(field.name)) io = "input";
           else io = "input-output";
           outData.println("  " + varType(field) + " '" + io);
           for (int c = 0; c < field.comments.size(); c++) {
             String s = (String) field.comments.elementAt(c);
             outData.println("'" + s);
           }
           if (field.isNull && notString(field))
             outData.println("  " + field.useName() + "IsNull as Boolean");
         }
         for (int j = 0; j < proc.outputs.size(); j++) {
           Field field = (Field) proc.outputs.elementAt(j);
           if (!proc.hasInput(field.name)) {
             outData.println("  " + varType(field) + " 'output");
             for (int c = 0; c < field.comments.size(); c++) {
               String s = (String) field.comments.elementAt(c);
               outData.println("'" + s);
             }
             if (field.isNull && notString(field))
               outData.println("  " + field.useName() + "IsNull as Boolean");
           }
         }
         for (int j = 0; j < proc.dynamics.size(); j++) {
           String s = (String) proc.dynamics.elementAt(j);
           outData.println("  " + s + " As String 'dynamic");
         }
         outData.println("End Type");
         outData.println();
         if (hasMulti) {
           outData.println("Private Rec() as TRec");
           outData.println("Public RecCount as Long");
           outData.println("Private " + proc.name + "Cursor As TCursor");
         } else outData.println("Private Rec as TRec");
         outData.println();
         generateCopy(table.useName() + proc.upperFirst(), outData, hasMulti);
         String optZero = hasMulti ? "(0)" : "";
         String optIndex = hasMulti ? "Optional aIndex as Long" : "";
         String optIndex1 = hasMulti ? ", Optional aIndex as Long" : "";
         String optIndex2 = hasMulti ? "Optional aIndex as Long, " : "";
         String optUseIndex = hasMulti ? "(aIndex)" : "";
         outData.println("Private Sub Class_Initialize()");
         if (hasMulti) outData.println("  RecClear");
         for (int j = 0; j < proc.inputs.size(); j++) {
           Field field = (Field) proc.inputs.elementAt(j);
           outData.println("  Rec" + optZero + "." + initVBVar(field));
           if (field.isNull && notString(field))
             outData.println("  Rec" + optZero + "." + field.useName() + "IsNull = false");
         }
         for (int j = 0; j < proc.outputs.size(); j++) {
           Field field = (Field) proc.outputs.elementAt(j);
           if (proc.hasInput(field.name)) continue;
           outData.println("  Rec" + optZero + "." + initVBVar(field));
           if (field.isNull && notString(field))
             outData.println("  Rec" + optZero + "." + field.useName() + "IsNull = false");
         }
         for (int j = 0; j < proc.dynamics.size(); j++) {
           String s = (String) proc.dynamics.elementAt(j);
           outData.println("  Rec" + optZero + "." + s + " = \"\"");
         }
         outData.println("End Sub");
         outData.println();
         if (ioRoutines) {
           outData.println("Public Sub Class_PutFile(OutFile as Long" + optIndex1 + ")");
           outData.println("  Put OutFile,, Rec" + optUseIndex);
           outData.println("End Sub");
           outData.println();
           outData.println("Public Sub Class_GetFile(InFile as Long" + optIndex1 + ")");
           outData.println("  Get InFile,, Rec" + optUseIndex);
           outData.println("End Sub");
           outData.println();
         }
         for (int j = 0; j < proc.inputs.size(); j++) {
           Field field = (Field) proc.inputs.elementAt(j);
           generateProperties(field, outData, optIndex, optIndex2, optUseIndex);
         }
         for (int j = 0; j < proc.outputs.size(); j++) {
           Field field = (Field) proc.outputs.elementAt(j);
           if (proc.hasInput(field.name)) continue;
           generateProperties(field, outData, optIndex, optIndex2, optUseIndex);
         }
         for (int j = 0; j < proc.dynamics.size(); j++) {
           String s = (String) proc.dynamics.elementAt(j);
           outData.println("Public Property Get " + s + "(" + optIndex + ") as String");
           outData.println("  " + s + " = Rec" + optUseIndex + "." + s);
           outData.println("End Property");
           outData.println();
           outData.println("Public Property Let " + s + "(" + optIndex2 + "aValue as String)");
           outData.println("  Rec" + optUseIndex + "." + s + " = aValue");
           outData.println("End Property");
           outData.println();
         }
         emitCode(proc, outData, table.useName(), optIndex1, optUseIndex);
         outData.flush();
       } finally {
         outFile.close();
       }
     } catch (IOException e1) {
       outLog.println("Generate Procs IO Error");
     }
   }
 }
Example #2
0
 private static void generateImplementationStructPairs(
     Proc proc, String mainName, PrintWriter outData) {
   if (proc.outputs.size() > 0) {
     outData.println("@implementation O" + mainName + "Rec");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       if (field.type == Field.BLOB) {
         outData.println("@synthesize " + useLowerName(field) + "_len;");
         outData.println("@synthesize " + useLowerName(field) + "_data;");
       } else outData.println("@synthesize " + useLowerName(field) + ";");
       if (isNull(field) == true)
         outData.println("@synthesize " + useLowerName(field) + "IsNull;");
     }
     outData.println("- (id)init");
     outData.println("  {");
     outData.println("    self = [super init];");
     outData.println("    return self;");
     outData.println("  }");
     outData.println("- (void)clear");
     outData.println("  {");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       clearCall(field, outData);
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println("    self." + useLowerName(field) + "IsNull = NO;");
     }
     outData.println("  }");
     outData.println("- (void)write:(Writer*)writer");
     outData.println("  {");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       writeCall(field, outData);
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println(
             "    [writer putBoolean:self." + useLowerName(field) + "IsNull];[writer filler:6];");
     }
     outData.println("  }");
     outData.println("- (void)read:(Reader*)reader");
     outData.println("  {");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       readCall(field, outData);
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println(
             "    self." + useLowerName(field) + "IsNull = [reader getBoolean];[reader skip:6];");
     }
     outData.println("  }");
     outData.println("- (void)dealloc");
     outData.println("  {");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       freeCall(field, outData);
     }
     outData.println("    [super dealloc];");
     outData.println("  }");
     outData.println("@end");
     outData.println();
   }
   if (proc.inputs.size() + proc.dynamics.size() > 0) {
     outData.println("@implementation D" + mainName + "Rec");
     for (int i = 0; i < proc.inputs.size(); i++) {
       Field field = (Field) proc.inputs.elementAt(i);
       if (proc.hasOutput(field.name)) continue;
       if (field.type == Field.BLOB) {
         outData.println("@synthesize " + useLowerName(field) + "_len;");
         outData.println("@synthesize " + useLowerName(field) + "_data;");
       } else outData.println("@synthesize " + useLowerName(field) + ";");
       if (isNull(field) == true)
         outData.println("@synthesize " + useLowerName(field) + "IsNull;");
     }
     for (int i = 0; i < proc.dynamics.size(); i++) {
       String name = (String) proc.dynamics.elementAt(i);
       Field field = new Field();
       field.name = name;
       outData.println("@synthesize " + useLowerName(field) + ";");
     }
     outData.println("- (id)init");
     outData.println("  {");
     outData.println("    self = [super init];");
     outData.println("    return self;");
     outData.println("  }");
     outData.println("- (void)clear");
     outData.println("  {");
     if (proc.outputs.size() > 0) outData.println("    [super clear];");
     for (int i = 0; i < proc.inputs.size(); i++) {
       Field field = (Field) proc.inputs.elementAt(i);
       clearCall(field, outData);
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println("    self." + useLowerName(field) + "IsNull = NO;");
     }
     for (int i = 0; i < proc.dynamics.size(); i++) {
       Field field = new Field();
       field.name = (String) proc.dynamics.elementAt(i);
       field.length = ((Integer) proc.dynamicSizes.elementAt(i)).intValue();
       field.type = Field.CHAR;
       clearCall(field, outData);
     }
     outData.println("  }");
     outData.println("- (void)write:(Writer*)writer");
     outData.println("  {");
     if (proc.outputs.size() > 0) outData.println("    [super write:writer];");
     for (int i = 0; i < proc.inputs.size(); i++) {
       Field field = (Field) proc.inputs.elementAt(i);
       writeCall(field, outData);
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println(
             "    [writer putBoolean:self." + useLowerName(field) + "IsNull];[writer filler:6];");
     }
     for (int i = 0; i < proc.dynamics.size(); i++) {
       Field field = new Field();
       field.name = (String) proc.dynamics.elementAt(i);
       field.length = ((Integer) proc.dynamicSizes.elementAt(i)).intValue();
       field.type = Field.CHAR;
       writeCall(field, outData);
     }
     outData.println("  }");
     outData.println("- (void)read:(Reader*)reader");
     outData.println("  {");
     if (proc.outputs.size() > 0) outData.println("    [super read:reader];");
     for (int i = 0; i < proc.inputs.size(); i++) {
       Field field = (Field) proc.inputs.elementAt(i);
       readCall(field, outData);
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println(
             "    self." + useLowerName(field) + "IsNull = [reader getBoolean];[reader skip:6];");
     }
     for (int i = 0; i < proc.dynamics.size(); i++) {
       Field field = new Field();
       field.name = (String) proc.dynamics.elementAt(i);
       field.length = ((Integer) proc.dynamicSizes.elementAt(i)).intValue();
       field.type = Field.CHAR;
       readCall(field, outData);
     }
     outData.println("  }");
     outData.println("- (void)dealloc");
     outData.println("  {");
     for (int i = 0; i < proc.dynamics.size(); i++) {
       Field field = new Field();
       field.name = (String) proc.dynamics.elementAt(i);
       outData.println("    [" + useLowerName(field) + " release];");
     }
     outData.println("    [super dealloc];");
     outData.println("  }");
     outData.println("@end");
     outData.println();
   }
 }
Example #3
0
  /** Build of output data rec for user procedures */
  static void generateUserOutputRecs(Table table, PrintWriter outData) {
    for (int i = 0; i < table.procs.size(); i++) {
      Proc proc = (Proc) table.procs.elementAt(i);
      if (proc.isData || proc.isStd || proc.hasNoData()) continue;
      if (proc.isStdExtended()) continue;
      String work = "(object)";
      String superName = "";
      if (proc.outputs.size() > 0) {
        for (int j = 0; j < proc.comments.size(); j++)
          outData.println("##" + (String) proc.comments.elementAt(j));
        String typeChar = "D";
        if (proc.hasDiscreteInput()) typeChar = "O";
        work = "(" + typeChar + table.useName() + proc.upperFirst() + ")";
        superName = typeChar + table.useName() + proc.upperFirst();
        outData.println("## \\class " + typeChar + table.useName() + proc.upperFirst());
        outData.println("class " + typeChar + table.useName() + proc.upperFirst() + "(object):");
        outData.println(
            "    def _make(self): return " + typeChar + table.useName() + proc.upperFirst() + "()");
        if (proc.hasDiscreteInput())
          outData.println(
              "    def _name(self): return ('"
                  + typeChar
                  + table.useName()
                  + proc.upperFirst()
                  + "')");
        else
          outData.println(
              "    def _name(self): return ('D"
                  + table.useName()
                  + proc.upperFirst()
                  + "', 'O"
                  + table.useName()
                  + proc.upperFirst()
                  + "')");
        generateDataFields(
            proc.outputs,
            "",
            typeChar + table.useName() + proc.upperFirst(),
            table.useName(),
            outData);
        outData.println();
      }
      if (proc.hasDiscreteInput()) {
        outData.println("## \\class D" + table.useName() + proc.upperFirst());
        outData.println("class D" + table.useName() + proc.upperFirst() + work + ":");
        outData.println(
            "    def _make(self): return D" + table.useName() + proc.upperFirst() + "()");
        outData.println(
            "    def _name(self): return ('D" + table.useName() + proc.upperFirst() + "')");
        Vector<Field> discreteInputs = new Vector<Field>();
        for (int j = 0; j < proc.inputs.size(); j++) {
          Field field = (Field) proc.inputs.elementAt(j);
          if (!proc.hasOutput(field.name)) discreteInputs.addElement(field);
        }

        for (int j = 0; j < proc.dynamics.size(); j++) {
          Field f = new Field();
          Integer length = (Integer) proc.dynamicSizes.elementAt(j);
          f.name = (String) proc.dynamics.elementAt(j);
          f.type = Field.CHAR;
          f.length = length.intValue();
          discreteInputs.addElement(f);
        }
        generateDataFields(
            discreteInputs,
            superName,
            "D" + table.useName() + proc.upperFirst(),
            table.useName(),
            outData);
        outData.println();
      } else if (proc.outputs.size() > 0) {
        outData.println("## \\class O" + table.useName() + proc.upperFirst());
        outData.println("## \\field see:O" + table.useName() + proc.upperFirst());
        outData.println(
            "O"
                + table.useName()
                + proc.upperFirst()
                + " = D"
                + table.useName()
                + proc.upperFirst());
        outData.println();
      }
      if (pymodName.length() > 0) {
        coverFunctions = new Vector<String>();
        outData.println(
            "class "
                + table.useName()
                + proc.upperFirst()
                + "(D"
                + table.useName()
                + proc.upperFirst()
                + "):");
        outData.println(
            "    def __init__(self): D" + table.useName() + proc.upperFirst() + ".__init__(self)");
        if (proc.isMultipleInput) generateBulkAction(table, proc, outData);
        else if (proc.isInsert && proc.hasReturning) generateAction(table, proc, outData);
        else if (proc.outputs.size() > 0)
          if (proc.isSingle) generateSingle(table, proc, outData);
          else generateMultiple(table, proc, outData);
        else generateAction(table, proc, outData);
        outData.println();
        for (int j = 0; j < coverFunctions.size(); j++)
          outData.println((String) coverFunctions.elementAt(j));
      }
    }
  }
Example #4
0
 private static void generateInterfaceStructPairs(
     Proc proc, String mainName, PrintWriter outData) {
   if (proc.outputs.size() > 0) {
     outData.println("@interface O" + mainName + "Rec:NSObject");
     outData.println("{");
     outData.println(" @protected");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       outData.println("  " + fieldDef(field));
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println("  BOOL " + useLowerName(field) + "IsNull;");
     }
     outData.println("}");
     for (int i = 0; i < proc.outputs.size(); i++) {
       Field field = (Field) proc.outputs.elementAt(i);
       if (field.type == Field.BLOB) {
         outData.println("@property (readwrite) int32 " + useLowerName(field) + "_len;");
         outData.println("@property (retain) NSMutableData* " + useLowerName(field) + "_data;");
       } else outData.println("@property (" + fieldProp(field) + ") " + fieldDef(field));
       if (isNull(field) == true) // && field.isEmptyOrAnsiAsNull() == false)
       outData.println("@property (readwrite) BOOL " + useLowerName(field) + "IsNull;");
     }
     outData.println("- (id)init;");
     outData.println("- (void)clear;");
     outData.println("- (void)write:(Writer*)writer;");
     outData.println("- (void)read:(Reader*)reader;");
     outData.println("- (void)dealloc;");
     outData.println("@end");
     if (proc.inputs.size() + proc.dynamics.size() == 0)
       outData.println("#define D" + mainName + "Rec O" + mainName + "Rec");
     outData.println();
   }
   if (proc.inputs.size() + proc.dynamics.size() > 0) {
     if (proc.outputs.size() > 0)
       outData.println("@interface D" + mainName + "Rec:O" + mainName + "Rec");
     else outData.println("@interface D" + mainName + "Rec:NSObject");
     outData.println("{");
     outData.println(" @protected");
     for (int j = 0; j < proc.inputs.size(); j++) {
       Field field = (Field) proc.inputs.elementAt(j);
       if (proc.hasOutput(field.name)) continue;
       outData.println("  " + fieldDef(field));
       if (isNull(field) == true) outData.println("  BOOL " + useLowerName(field) + "IsNull;");
     }
     for (int j = 0; j < proc.dynamics.size(); j++) {
       String s = (String) proc.dynamics.elementAt(j);
       Integer n = (Integer) proc.dynamicSizes.elementAt(j);
       Field field = new Field();
       field.name = s;
       field.type = Field.CHAR;
       field.length = n.intValue();
       outData.println("  " + fieldDef(field));
     }
     outData.println("}");
     for (int j = 0; j < proc.inputs.size(); j++) {
       Field field = (Field) proc.inputs.elementAt(j);
       if (proc.hasOutput(field.name)) continue;
       if (field.type == Field.BLOB) {
         outData.println("@property (readwrite) int32 " + useLowerName(field) + "_len;");
         outData.println("@property (retain) NSMutableData* " + useLowerName(field) + "_data;");
       } else outData.println("@property (" + fieldProp(field) + ") " + fieldDef(field));
       if (isNull(field) == true)
         outData.println("@property (readwrite) BOOL " + useLowerName(field) + "IsNull;");
     }
     for (int j = 0; j < proc.dynamics.size(); j++) {
       String s = (String) proc.dynamics.elementAt(j);
       Field field = new Field();
       field.name = s;
       outData.println("@property (retain) NSString* " + useLowerName(field) + ";");
     }
     outData.println("- (id)init;");
     outData.println("- (void)clear;");
     outData.println("- (void)write:(Writer*)writer;");
     outData.println("- (void)read:(Reader*)reader;");
     outData.println("- (void)dealloc;");
     outData.println("@end");
     if (proc.outputs.size() == 0)
       outData.println("#define O" + mainName + "Rec D" + mainName + "Rec");
     outData.println();
   }
 }