Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Java language support
0003  *
0004  * @file java.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 
0035 /*---------------------------Includes-----------------------------------*/
0036 
0037 #include <unistd.h>
0038 #include <stdio.h>
0039 #include <errno.h>
0040 #include <stdlib.h>
0041 #include <atmi.h>
0042 
0043 #include <ndrstandard.h>
0044 #include <ubf.h>
0045 #include <ubf_int.h>
0046 #include <ferror.h>
0047 #include <fieldtable.h>
0048 #include <fdatatype.h>
0049 
0050 #include <ndrstandard.h>
0051 #include <ndebug.h>
0052 #include "mkfldhdr.h"
0053 /*---------------------------Externs------------------------------------*/
0054 /*---------------------------Macros-------------------------------------*/
0055 /*---------------------------Enums--------------------------------------*/
0056 /*---------------------------Typedefs-----------------------------------*/
0057 /*---------------------------Globals------------------------------------*/
0058 /*---------------------------Statics------------------------------------*/
0059 /*---------------------------Prototypes---------------------------------*/
0060 
0061 /**
0062  * Get the java lang output file name
0063  * @param data
0064  */
0065 expublic void java_get_fullname(char *data)
0066 {
0067     /* For java we shall strip off the file extension
0068      * as it might cause problems with the class name...
0069      */
0070     char *p;
0071     
0072     p = strrchr(G_active_file, '.');
0073     if (NULL!=p)
0074     {
0075         NDRX_LOG(log_debug, "Stripping of file extension for class");
0076         *p=EXEOS;
0077     }
0078 
0079     sprintf(data, "%s/%s.java", G_output_dir, G_active_file);
0080 }
0081 
0082 /**
0083  * Write text line to output file
0084  * @param text
0085  * @return
0086  */
0087 expublic int java_put_text_line (char *text)
0088 {
0089     int ret=EXSUCCEED;
0090     
0091     if (0==strncmp(text, "#ifndef", 7) || 
0092         0==strncmp(text, "#define", 7) ||
0093         0==strncmp(text, "#endif", 6))
0094     {
0095         /* just ignore these special C lines */
0096         goto out;
0097     }
0098     
0099     fprintf(G_outf, "%s", text);
0100     
0101     /* Check errors */
0102     if (ferror(G_outf))
0103     {
0104         ndrx_Bset_error_fmt(BFTOPEN, "Failed to write to output file: [%s]", strerror(errno));
0105         EXFAIL_OUT(ret);
0106     }
0107     
0108 out:
0109     return ret;
0110 }
0111 
0112 /**
0113  * Process the baseline
0114  * @param base
0115  * @return
0116  */
0117 expublic int java_put_got_base_line(char *base)
0118 {
0119 
0120     int ret=EXSUCCEED;
0121 
0122     fprintf(G_outf, "public final class %s\n{\n", G_active_file);
0123 
0124     /* Check errors */
0125     if (ferror(G_outf))
0126     {
0127         ndrx_Bset_error_fmt(BFTOPEN, "Failed to write to output file: [%s]",
0128                 strerror(errno));
0129         ret=EXFAIL;
0130     }
0131 
0132     return ret;
0133 }
0134 
0135 /**
0136  * Write definition to output file
0137  * @param def
0138  * @return
0139  */
0140 expublic int java_put_def_line (UBF_field_def_t *def)
0141 {
0142     int ret=EXSUCCEED;
0143     int type = def->bfldid>>EFFECTIVE_BITS;
0144     BFLDID number = def->bfldid & EFFECTIVE_BITS_MASK;
0145     
0146     fprintf(G_outf, "\t  /** number: %d type: %s*/\n", 
0147             number, G_dtype_str_map[type].fldname);
0148     fprintf(G_outf, "\t  public final static int %s = %d;\n", 
0149             def->fldname, def->bfldid);
0150     /* Check errors */
0151     if (ferror(G_outf))
0152     {
0153         ndrx_Bset_error_fmt(BFTOPEN, "Failed to write to output file: [%s]", 
0154                 strerror(errno));
0155         ret=EXFAIL;
0156     }
0157 
0158     return ret;
0159 }
0160 
0161 /**
0162  * Output file have been open
0163  * @param fname
0164  * @return 
0165  */
0166 expublic int java_file_open (char *fname)
0167 {
0168     
0169     if (EXEOS!=G_privdata[0])
0170     {
0171         fprintf(G_outf, "package %s;\n\n", G_privdata);
0172     }
0173     
0174     return EXSUCCEED;
0175 }
0176 
0177 /**
0178  * Output file have been closed
0179  * @param fname
0180  * @return 
0181  */
0182 expublic int java_file_close (char *fname)
0183 {
0184     fprintf(G_outf, "}\n");
0185 
0186     /* Check errors */
0187     if (ferror(G_outf))
0188     {
0189         ndrx_Bset_error_fmt(BFTOPEN, "Failed to write to output file: [%s]", 
0190                 strerror(errno));
0191         return EXFAIL;
0192     }
0193 
0194     return EXSUCCEED;   
0195 }
0196 
0197 /* vim: set ts=4 sw=4 et smartindent: */