00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "eyedb_p.h"
00026 #include "Attribute_p.h"
00027 #include <string.h>
00028
00029 namespace eyedb {
00030
00031 static const char classSuffix[] = "_Class";
00032 static const char __agritems[] = "getClass(true).getAttributes()";
00033 static const char downCastPrefix[] = "as";
00034
00035 #define ATTRNAME(NAME, OPTYPE, HINTS) \
00036 (HINTS).style->getString(GenCodeHints::OPTYPE, NAME)
00037
00038 #define ATTRNAME_1(NAME, OPTYPE, HINTS) \
00039 (HINTS).style->getString(OPTYPE, NAME)
00040
00041 #define ATTRGET(CL) ((CL)->asCollectionClass() ? \
00042 GenCodeHints::tGetColl : GenCodeHints::tGet)
00043
00044 #define ATTRSET(CL) ((CL)->asCollectionClass() ? \
00045 GenCodeHints::tSetColl : GenCodeHints::tSet)
00046 static const char *
00047 getstr(const char *s)
00048 {
00049 if (!strcmp(s, int32_class_name) || !strcmp(s, "int") ||
00050 !strcmp(s, "eyedblib::int32"))
00051 return "Int";
00052
00053 if (!strcmp(s, int16_class_name) || !strcmp(s, "short") ||
00054 !strcmp(s, "eyedblib::int16"))
00055 return "Short";
00056
00057 if (!strcmp(s, int64_class_name) || !strcmp(s, "long") ||
00058 !strcmp(s, "eyedblib::int64"))
00059 return "Long";
00060
00061 if (!strcmp(s, char_class_name))
00062 return "Char";
00063
00064 if (!strcmp(s, "byte"))
00065 return "Byte";
00066
00067 if (!strcmp(s, "float") || !strcmp(s, "double"))
00068 return "Double";
00069
00070 if (!strcmp(s, "oid"))
00071 return "Oid";
00072
00073 if (!strcmp(s, "org.eyedb.Oid"))
00074 return "Oid";
00075
00076 fprintf(stderr, "eyedbodl: getstr cannot decode type '%s'\n",
00077 s);
00078 abort();
00079 }
00080
00081 static const char *
00082 attrName(const char *name, Bool isGet,
00083 GenCodeHints::AttrStyle attr_style)
00084 {
00085 if (attr_style == GenCodeHints::ImplicitAttrStyle)
00086 return name;
00087
00088 static char sname[256];
00089 strcpy(sname, (isGet ? "get" : "set"));
00090 char c = name[0];
00091 if (c >= 'a' && c <= 'z')
00092 c += 'A' - 'a';
00093 int len = strlen(sname);
00094
00095 sname[len] = c;
00096 sname[len+1] = 0;
00097 strcat(sname, &name[1]);
00098
00099 return sname;
00100 }
00101
00102 static const char *
00103 make_int(int i)
00104 {
00105 static char x[16];
00106 sprintf(x, "%d", i);
00107 return x;
00108 }
00109
00110 static int
00111 pre(char *name, const char *pre)
00112 {
00113 int len = strlen(pre);
00114 if (!strncmp(name, pre, len))
00115 {
00116 name[len] += 'A' - 'a';
00117 return 1;
00118 }
00119 return 0;
00120 }
00121
00122
00123
00124 const char *
00125 classNameToJavaName(const char *name);
00126 const char *getJavaName(const Class *cls);
00127
00128 #if 1
00129 static const char *className(const Class *cls,
00130 Bool makeC = True,
00131 Bool makeAlias = False)
00132 {
00133 const char *name = (makeAlias ? cls->getAliasName() : cls->getName());
00134
00135 if (!strncmp(name, "set<", 4))
00136 return "org.eyedb.CollSet";
00137
00138 if (!strncmp(name, "bag<", 4))
00139 return "org.eyedb.CollBag";
00140
00141 if (!strncmp(name, "array<", 6))
00142 return "org.eyedb.CollArray";
00143
00144 if (!strncmp(name, "list<", 5))
00145 return "org.eyedb.CollList";
00146
00147 if (!strcmp(name, "image"))
00148 return "org.eyedb.utils.Image";
00149
00150 if (!strcmp(name, "URL"))
00151 return "org.eyedb.utils.URL";
00152
00153 if (!strcmp(name, "CURL"))
00154 return "org.eyedb.utils.CURL";
00155
00156 if (!strcmp(name, "date"))
00157 return "org.eyedb.utils.Date";
00158
00159 if (!strcmp(name, "time"))
00160 return "org.eyedb.utils.Time";
00161
00162 if (!strcmp(name, "timestamp"))
00163 return "org.eyedb.utils.TimeStamp";
00164
00165 if (!strcmp(name, "bool"))
00166 return "org.eyedb.Bool";
00167
00168 for (int i = 0; i < idbLAST_Type; i++)
00169 if (!strcmp(name, class_info[i].name))
00170 return classNameToJavaName(name);
00171
00172 if (makeC) {
00173 if (!strcmp(name, char_class_name))
00174 return "org.eyedb.Char";
00175
00176 if (!strcmp(name, int32_class_name))
00177 return "org.eyedb.Int32";
00178
00179 if (!strcmp(name, int64_class_name))
00180 return "org.eyedb.Int64";
00181
00182 if (!strcmp(name, int16_class_name))
00183 return "org.eyedb.Int16";
00184
00185 if (!strcmp(name, "float"))
00186 return "org.eyedb.Float";
00187
00188 if (!strcmp(name, "oid"))
00189 return "org.eyedb.OidP";
00190
00191 if (!strcmp(name, "byte"))
00192 return "org.eyedb.Byte";
00193 }
00194 else {
00195 if (!strcmp(name, int32_class_name))
00196 return "int";
00197
00198 if (!strcmp(name, int64_class_name))
00199 return "long";
00200
00201 if (!strcmp(name, int16_class_name))
00202 return "short";
00203
00204 if (!strcmp(name, "oid"))
00205 return "org.eyedb.Oid";
00206
00207 if (!strcmp(name, "byte"))
00208 return "byte";
00209
00210 if (!strcmp(name, "float"))
00211 return "double";
00212 }
00213
00214
00215 const char *sCName = Class::getSCName(name);
00216 return sCName ? sCName : name;
00217 }
00218
00219 #else
00220 static const char *className(const Class *cls,
00221 Bool makeC=True,
00222 Bool makeAlias=False)
00223 {
00224 const char *name = (makeAlias ? cls->getAliasName() : cls->getName());
00225
00226 if (!strncmp(name, "set<", 4))
00227 return "org.eyedb.CollSet";
00228
00229 if (!strncmp(name, "bag<", 4))
00230 return "org.eyedb.CollBag";
00231
00232 if (!strncmp(name, "array<", 6))
00233 return "org.eyedb.CollArray";
00234
00235 if (!strncmp(name, "list<", 5))
00236 return "CollList";
00237
00238 if (!strcmp(name, "image"))
00239 return "Image";
00240
00241 oups
00242 if (!strcmp(name, "URL"))
00243 return "URL";
00244
00245 for (int i = 0; i < idbLAST_Type; i++)
00246 if (!strcmp(name, class_info[i].name))
00247 {
00248 return classNameToJavaName(name);
00249 }
00250
00251 if (makeC)
00252 {
00253 if (!strcmp(name, char_class_name))
00254 return "org.eyedb.Char";
00255
00256 if (!strcmp(name, int32_class_name))
00257 return "org.eyedb.Int32";
00258
00259 if (!strcmp(name, int64_class_name))
00260 return "org.eyedb.Int64";
00261
00262 if (!strcmp(name, int16_class_name))
00263 return "org.eyedb.Int16";
00264
00265 if (!strcmp(name, "float"))
00266 return "org.eyedb.Float";
00267
00268 if (!strcmp(name, "oid"))
00269 return "org.eyedb.OidP";
00270
00271 if (!strcmp(name, "byte"))
00272 return "org.eyedb.Byte";
00273 }
00274 else
00275 {
00276 if (!strcmp(name, "oid"))
00277 return "org.eyedb.Oid";
00278
00279 if (!strcmp(name, "byte"))
00280 return "byte";
00281
00282 if (!strcmp(name, "float"))
00283 return "double";
00284
00285 if (!strcmp(name, int32_class_name))
00286 return "int";
00287
00288 if (!strcmp(name, int16_class_name))
00289 return "short";
00290
00291 if (!strcmp(name, int64_class_name))
00292 return "long";
00293 }
00294
00295 return name;
00296 }
00297 #endif
00298
00299 static void dimArgsGen(FILE *fd, int ndims, Bool named = False)
00300 {
00301 for (int i = 0; i < ndims; i++)
00302 {
00303 if (i)
00304 fprintf(fd, ", ");
00305 fprintf(fd, "int");
00306 if (named)
00307 fprintf(fd, " a%d", i);
00308 }
00309 }
00310
00311 Status Attribute::generateClassDesc_Java(GenContext *ctx)
00312 {
00313 FILE *fd = ctx->getFile();
00314 int ndims = typmod.ndims;
00315
00316 fprintf(fd, "\n");
00317 if (ndims)
00318 {
00319 fprintf(fd, "%sdims = new int[%d];\n", ctx->get(), ndims);
00320 for (int i = 0; i < ndims; i++)
00321 fprintf(fd, "%sdims[%d] = %d;\n", ctx->get(), i, typmod.dims[i]);
00322 }
00323 else
00324 fprintf(fd, "%sdims = null;\n", ctx->get());
00325
00326 fprintf(fd, "%sattr[%d] = new org.eyedb.Attribute(", ctx->get(), num);
00327
00328 if (cls->asCollectionClass())
00329 fprintf(fd, "((m != null) ? m.getClass(\"%s\") : %s.idbclass), idbclass, \"%s\", ",
00330 cls->getAliasName(), getJavaName(cls), name);
00331 else
00332 fprintf(fd, "((m != null) ? m.getClass(\"%s\") : %s.idbclass), idbclass, \"%s\", ",
00333 cls->getAliasName(), className(cls), name);
00334
00335 fprintf(fd, "%d, %s, %d, dims);\n",
00336 num, (isIndirect() ? "true" : "false"), ndims);
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348 return Success;
00349 }
00350
00351 static void
00352 get_info(CollectionClass *mcoll, const char *&classname,
00353 Bool &ordered)
00354 {
00355 if (mcoll->asCollSetClass())
00356 {
00357 classname = "org.eyedb.CollSet";
00358 ordered = False;
00359 }
00360 else if (mcoll->asCollBagClass())
00361 {
00362 classname = "org.eyedb.CollBag";
00363 ordered = False;
00364 }
00365 else if (mcoll->asCollArrayClass())
00366 {
00367 classname = "org.eyedb.CollArray";
00368 ordered = True;
00369 }
00370 else if (mcoll->asCollListClass())
00371 {
00372 classname = "CollList";
00373 ordered = True;
00374 }
00375 }
00376
00377 Status
00378 Attribute::generateCollRealizeClassMethod_Java(Class *own,
00379 GenContext *ctx,
00380 const GenCodeHints &hints,
00381 Bool isoid,
00382 int xacctype)
00383 {
00384 FILE *fd = ctx->getFile();
00385 int ndims = typmod.ndims, i;
00386 const char *comma = (ndims ? ", " : "");
00387 Bool _isref;
00388 eyedblib::int16 _dim;
00389 Class *cl =
00390 ((CollectionClass *)cls)->getCollClass(&_isref, &_dim);
00391 GenCodeHints::OpType acctype = (GenCodeHints::OpType)xacctype;
00392 #if 0
00393 const char *etc = (acctype == GenCodeHints::tAddItemToColl ?
00394 ", int mag_order" : "");
00395 #else
00396 const char *etc = "";
00397 #endif
00398 const char *accmth = (acctype == GenCodeHints::tAddItemToColl ? "insert" : "suppress");
00399 const char *oclassname = _isref ?
00400 className(cl, True) : className(cl, False);
00401
00402 if (isoid && cl->asBasicClass())
00403 return Success;
00404
00405 const char *cast = (cl->asBasicClass() ? "(org.eyedb.Value)" : "");
00406 const char *classname;
00407 Bool ordered;
00408 get_info(const_cast<CollectionClass *>(cls->asCollectionClass()), classname, ordered);
00409
00410 const char *At = ((acctype == GenCodeHints::tAddItemToColl ||
00411 acctype == GenCodeHints::tRmvItemFromColl)
00412 && ordered ? "At" : "");
00413 const char *etc1 = "";
00414 const char *etc2 = "";
00415 Bool rmv_from_array = (acctype == GenCodeHints::tRmvItemFromColl)
00416 && ordered ? True : False;
00417
00418 if (rmv_from_array && isoid)
00419 return Success;
00420
00421 GenCodeHints::OpType nacctype;
00422 if (ordered)
00423 nacctype = (acctype == GenCodeHints::tRmvItemFromColl ?
00424 GenCodeHints::tUnsetItemInColl :
00425 GenCodeHints::tSetItemInColl);
00426 else
00427 nacctype = acctype;
00428
00429 if (!*At)
00430 {
00431 if (acctype == GenCodeHints::tAddItemToColl)
00432 {
00433 etc1 = ", boolean noDup";
00434 etc2 = ", noDup";
00435 }
00436 else if (acctype == GenCodeHints::tRmvItemFromColl)
00437 {
00438 etc1 = ", boolean checkFirst";
00439 etc2 = ", checkFirst";
00440 }
00441 }
00442
00443 if (_dim == 1)
00444 {
00445
00446 if (*etc1)
00447 {
00448 fprintf(fd, "%spublic void %s(%s%s", ctx->get(),
00449 ATTRNAME_1(name, nacctype, hints),
00450 (*At ? "int where" : ""),
00451 (*At && (!rmv_from_array || ndims >= 1) ? ", " : ""));
00452 dimArgsGen(fd, ndims);
00453 if (rmv_from_array)
00454 fprintf(fd, ")\n");
00455 else if (isoid)
00456 fprintf(fd, "%sorg.eyedb.Oid _oid)\n", comma);
00457 else
00458 fprintf(fd, "%s%s _%s)\n",
00459 comma, oclassname, name);
00460 fprintf(fd, " throws org.eyedb.Exception {\n");
00461 fprintf(fd, "%s %s(%s", ctx->get(),
00462 ATTRNAME_1(name, nacctype, hints),
00463 (*At ? "where, " : ""));
00464 for (i = 0; i < ndims; i++)
00465 fprintf(fd, "a%d, ", i);
00466
00467 if (isoid)
00468 fprintf(fd, "%s_oid%s);\n", ((*comma || *At) ? ", " : ""), ", false");
00469 else
00470 fprintf(fd, "%s_%s%s);\n", ((*comma || *At) ? ", " : ""), name, ", false");
00471 fprintf(fd, "%s}\n\n", ctx->get());
00472 }
00473
00474 fprintf(fd, "%spublic void %s(%s%s", ctx->get(),
00475 ATTRNAME_1(name, nacctype, hints),
00476 (*At ? "int where" : ""),
00477 (*At && (!rmv_from_array || ndims >= 1) ? ", " : ""));
00478 dimArgsGen(fd, ndims);
00479 if (rmv_from_array)
00480 fprintf(fd, ")\n");
00481 else if (isoid)
00482 fprintf(fd, "%sorg.eyedb.Oid _oid%s%s)\n", comma, etc1, etc);
00483 else
00484 fprintf(fd, "%s%s _%s%s%s)\n", comma, oclassname, name,
00485 etc1, etc);
00486 }
00487
00488 fprintf(fd, "%sthrows org.eyedb.Exception {\n", ctx->get());
00489
00490 ctx->push();
00491 fprintf(fd, "%sorg.eyedb.Value __x;\n", ctx->get());
00492 fprintf(fd, "%s%s _coll;\n", ctx->get(), classname);
00493 fprintf(fd, "%sboolean _not_set = false;\n", ctx->get());
00494
00495 if (ndims > 1)
00496 {
00497 fprintf(fd, "%sint from = a%d;\n", ctx->get(), ndims-1);
00498 for (int i = ndims - 2 ; i >= 0; i--)
00499 fprintf(fd, "%sfrom += a%d * %d;\n", ctx->get(), i, typmod.dims[i]);
00500 }
00501 else
00502 fprintf(fd, "%sint from = 0;\n", ctx->get());
00503
00504 fprintf(fd, "\n%s__x = %s[%d].getValue(this, from, true);\n",
00505 ctx->get(), __agritems, num, name);
00506
00507 fprintf(fd, "%s_coll = (%s)__x.sgetObject();\n", ctx->get(), classname);
00508
00509
00510
00511
00512
00513 fprintf(fd, "%sif (_coll == null)", ctx->get());
00514 ctx->push();
00515 if (acctype == GenCodeHints::tAddItemToColl)
00516 {
00517 fprintf(fd, " {\n");
00518 fprintf(fd, "%s _coll = new %s(db, \"\", "
00519 "db.getSchema().getClass(\"%s\"), %s);\n",
00520 ctx->get(), classname,
00521 cl->getAliasName(), (_isref ? "true" : make_int(_dim)));
00522 fprintf(fd, "%s _not_set = true;\n", ctx->get());
00523
00524 ctx->pop();
00525 fprintf(fd, "%s}\n", ctx->get());
00526 }
00527 else {
00528 fprintf(fd, "\n%s throw new org.eyedb.Exception(org.eyedb.Status.IDB_ERROR, \"invalid collection\", \"no valid collection in attribute %s::%s\");\n\n", ctx->get(), class_owner->getName(), name);
00529 ctx->pop();
00530 }
00531
00532 if (rmv_from_array)
00533 fprintf(fd, "\n%s_coll.suppressAt(where);\n", ctx->get());
00534 else if (isoid)
00535 fprintf(fd, "\n%s_coll.%s%s(%s_oid%s);\n", ctx->get(),
00536 accmth, At, (*At ? "where, " : ""), etc2);
00537 else
00538 fprintf(fd, "\n%s_coll.%s%s(%s%s_%s%s);\n", ctx->get(),
00539 accmth, At, (*At ? "where, " : ""), cast, name,
00540 etc2);
00541
00542
00543
00544
00545
00546
00547
00548
00549 fprintf(fd, "%sif (!_not_set)\n%s return;\n", ctx->get(), ctx->get());
00550 fprintf(fd, "%s%s[%d].setValue(this, new org.eyedb.Value(_coll), from);\n",
00551 ctx->get(), __agritems, num);
00552 ctx->pop();
00553 fprintf(fd, "%s}\n\n", ctx->get());
00554 return Success;
00555 }
00556
00557 Status
00558 Attribute::generateCollInsertClassMethod_Java(Class *own,
00559 GenContext *ctx,
00560 const GenCodeHints &hints,
00561 Bool isoid)
00562 {
00563 return generateCollRealizeClassMethod_Java(own, ctx, hints,
00564 isoid,
00565 GenCodeHints::tAddItemToColl);
00566 }
00567
00568 Status
00569 Attribute::generateCollSuppressClassMethod_Java(Class *own,
00570 GenContext *ctx,
00571 const GenCodeHints &hints,
00572 Bool isoid)
00573 {
00574 return generateCollRealizeClassMethod_Java(own, ctx, hints,
00575 isoid,
00576 GenCodeHints::tRmvItemFromColl);
00577 }
00578
00579 #if 0
00580 Status
00581 Attribute_generateCollInsertClassMethod_Java_old(Class *own,
00582 GenContext *ctx,
00583 const GenCodeHints &hints,
00584 Bool isoid)
00585 {
00586 FILE *fd = ctx->getFile();
00587 int ndims = typmod.ndims, i;
00588 const char *comma = (ndims ? ", " : "");
00589 Bool _isref;
00590 eyedblib::int16 _dim;
00591 Class *cl =
00592 ((CollectionClass *)cls)->getCollClass(&_isref, &_dim);
00593
00594 if (isoid && cl->asBasicClass())
00595 return Success;
00596
00597 if (_dim == 1)
00598 {
00599 fprintf(fd, "%spublic void %s(", ctx->get(),
00600 attrName(name, False, hints.attr_style));
00601 dimArgsGen(fd, ndims);
00602 if (isoid)
00603 fprintf(fd, "%sorg.eyedb.Oid _oid)\n", comma);
00604 else
00605 fprintf(fd, "%s%s _%s)\n", comma, className(cl, False), name);
00606 }
00607 else if (!strcmp(cl->getName(), char_class_name))
00608 {
00609 fprintf(fd, "%s%s(", ctx->get(),
00610 attrName(name, False, hints.attr_style));
00611 dimArgsGen(fd, ndims);
00612 fprintf(fd, "%sString _%s)\n", comma, name);
00613 }
00614 else if (!strcmp(cl->getName(), "byte"))
00615 {
00616 fprintf(fd, "%s%s(", ctx->get(),
00617 attrName(name, False, hints.attr_style));
00618 dimArgsGen(fd, ndims);
00619 fprintf(fd, "%sbyte _%s[])\n", comma, name);
00620 }
00621
00622 fprintf(fd, "%sthrows org.eyedb.Exception {\n", ctx->get());
00623
00624 ctx->push();
00625 fprintf(fd, "%sorg.eyedb.Value __x;\n", ctx->get());
00626 fprintf(fd, "%sorg.eyedb.CollSet _set;\n", ctx->get());
00627
00628 if (ndims > 1)
00629 {
00630 fprintf(fd, "%sint from = a%d;\n", ctx->get(), ndims-1);
00631 for (int i = ndims - 2 ; i >= 0; i--)
00632 fprintf(fd, "%sfrom += a%d * %d;\n", ctx->get(), i, typmod.dims[i]);
00633 }
00634 else
00635 fprintf(fd, "%sint from = 0;\n", ctx->get());
00636
00637 fprintf(fd, "\n%s__x = %s[%d].getValue(this, from, true);\n",
00638 ctx->get(), __agritems, num, name);
00639
00640 fprintf(fd, "%s_set = (org.eyedb.CollSet)__x.sgetObject();\n", ctx->get());
00641 fprintf(fd, "%sif (_set == null) return;\n", ctx->get());
00642
00643 if (isoid)
00644 fprintf(fd, "\n%s_set.insert(_oid);\n", ctx->get());
00645 else
00646 fprintf(fd, "\n%s_set.insert(_%s);\n", ctx->get(), name);
00647
00648 ctx->pop();
00649 fprintf(fd, "%s}\n\n", ctx->get());
00650 return Success;
00651 }
00652 #endif
00653
00654 Status
00655 Attribute::generateSetMethod_Java(Class *own, GenContext *ctx,
00656 const GenCodeHints &hints)
00657 {
00658 if (cls->asCollectionClass())
00659 {
00660 (void)generateCollInsertClassMethod_Java(own, ctx, hints, False);
00661 (void)generateCollInsertClassMethod_Java(own, ctx, hints, True);
00662
00663 (void)generateCollSuppressClassMethod_Java(own, ctx, hints, False);
00664 (void)generateCollSuppressClassMethod_Java(own, ctx, hints, True);
00665 }
00666 return Success;
00667 }
00668
00669 #define NOT_BASIC() \
00670 (isIndirect() || (!cls->asBasicClass() && !cls->asEnumClass()))
00671
00672 Status
00673 Attribute::generateSetMethod_Java(Class *own, GenContext *ctx,
00674 Bool isoid,
00675 const GenCodeHints &hints)
00676 {
00677 FILE *fd = ctx->getFile();
00678 int ndims = typmod.ndims, i;
00679 int not_basic = NOT_BASIC();
00680 const char *ref = (not_basic ? "*" : "");
00681 const char *comma = (ndims ? ", " : "");
00682
00683 if (isoid)
00684 fprintf(fd, "%spublic void %s_oid(", ctx->get(),
00685 ATTRNAME(name, tSetOid, hints));
00686
00687 else
00688 fprintf(fd, "%spublic void %s(", ctx->get(),
00689 ATTRNAME_1(name, ATTRSET(cls), hints));
00690
00691
00692 dimArgsGen(fd, ndims, True);
00693
00694 if (isoid)
00695 fprintf(fd, "%sorg.eyedb.Oid _oid)\n", comma);
00696 else
00697 fprintf(fd, "%s%s _%s)\n", comma, (cls->asEnumClass() ? "int" :
00698 className(cls, False)), name);
00699
00700 fprintf(fd, "%sthrows org.eyedb.Exception {\n", ctx->get());
00701 ctx->push();
00702
00703 if (ndims)
00704 {
00705 fprintf(fd, "%sint from = a%d;\n", ctx->get(), ndims-1);
00706 for (int i = ndims - 2 ; i >= 0; i--)
00707 fprintf(fd, "%sfrom += a%d * %d;\n", ctx->get(), i, typmod.dims[i]);
00708
00709 if (isVarDim())
00710 {
00711 fprintf(fd, "%sint size = %s[%d].getSize(this);\n",
00712 ctx->get(), __agritems, num);
00713 fprintf(fd, "%sif (size <= from)\n", ctx->get());
00714 ctx->push();
00715 fprintf(fd, "%s%s[%d].setSize(this, from+1);\n",
00716 ctx->get(), __agritems, num);
00717 ctx->pop();
00718 }
00719
00720
00721
00722
00723
00724
00725 if (isoid)
00726 fprintf(fd, "%s%s[%d].setOid(this, _oid, from);\n",
00727 ctx->get(), __agritems, num);
00728 else
00729 fprintf(fd, "%s%s[%d].setValue(this, new org.eyedb.Value(_%s), from);\n",
00730 ctx->get(), __agritems, num, name);
00731 }
00732 else if (isoid)
00733 fprintf(fd, "%s%s[%d].setOid(this, _oid, 0);\n",
00734 ctx->get(), __agritems, num);
00735 else
00736 fprintf(fd, "%s%s[%d].setValue(this, new org.eyedb.Value(_%s), 0);\n",
00737 ctx->get(), __agritems, num, name);
00738
00739 ctx->pop();
00740 fprintf(fd, "%s}\n\n", ctx->get());
00741
00742 return Success;
00743 }
00744
00745 #define _GRT_WRK_
00746
00747 Status
00748 Attribute::generateGetMethod_Java(Class *own, GenContext *ctx,
00749 Bool isoid,
00750 const GenCodeHints &hints,
00751 const char *_const, const char *prefix)
00752 {
00753 FILE *fd = ctx->getFile();
00754 int ndims = typmod.ndims, i;
00755 int not_basic = NOT_BASIC();
00756 const char *ref = (not_basic ? "*" : "");
00757
00758 if (isoid)
00759 fprintf(fd, "%spublic org.eyedb.Oid %s_oid(", ctx->get(),
00760 ATTRNAME(name, tGetOid, hints));
00761
00762 else
00763 fprintf(fd, "%spublic %s %s(", ctx->get(),
00764 (cls->asEnumClass() ? "int" : className(cls, False)),
00765 ATTRNAME_1(name, ATTRGET(cls), hints));
00766
00767
00768 dimArgsGen(fd, ndims, True);
00769
00770 fprintf(fd, ")\n%sthrows org.eyedb.Exception {\n", ctx->get());
00771
00772 ctx->push();
00773 int const_obj = (!isoid && not_basic );
00774
00775 if (isoid)
00776 fprintf(fd, "%sorg.eyedb.Oid __x;\n", ctx->get());
00777 else
00778 {
00779 fprintf(fd, "%sorg.eyedb.Value __x;\n", ctx->get());
00780 fprintf(fd, "%sorg.eyedb.Object __y;\n", ctx->get());
00781 }
00782
00783 if (ndims)
00784 {
00785 fprintf(fd, "%sint from = a%d;\n", ctx->get(), ndims-1);
00786 for (int i = ndims - 2 ; i >= 0; i--)
00787 fprintf(fd, "%sfrom += a%d * %d;\n", ctx->get(), i, typmod.dims[i]);
00788
00789 if (isoid)
00790 fprintf(fd, "\n%s__x = %s[%d].getOid(this, from);\n",
00791 ctx->get(), __agritems, num);
00792 else
00793 fprintf(fd, "\n%s__x = %s[%d].getValue(this, from, true);\n",
00794 ctx->get(), __agritems, num);
00795 }
00796 else if (isoid)
00797 fprintf(fd, "\n%s__x = %s[%d].getOid(this, 0);\n",
00798 ctx->get(), __agritems, num);
00799 else
00800 {
00801 fprintf(fd, "\n%s__x = %s[%d].getValue(this, 0, true);\n",
00802 ctx->get(), __agritems, num);
00803
00804
00805
00806
00807 }
00808
00809 if (const_obj)
00810 {
00811
00812
00813 fprintf(fd, "%s__y = %sDatabase.makeObject(__x.sgetObject(), true);\n",
00814 ctx->get(), prefix);
00815 fprintf(fd, "%sif (__y != __x.sgetObject())\n", ctx->get());
00816 ctx->push();
00817 fprintf(fd, "%s%s[%d].setValue(this, new org.eyedb.Value(__y), 0);\n",
00818 ctx->get(), __agritems, num);
00819 ctx->pop();
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829 fprintf(fd, "%sreturn (%s)__y;\n", ctx->get(),
00830 className(cls, False));
00831 }
00832 else if (isoid)
00833 fprintf(fd, "%sreturn __x;\n", ctx->get(),
00834 className(cls, False));
00835 else if (cls->asEnumClass())
00836 fprintf(fd, "%sreturn __x.sgetInt();\n", ctx->get());
00837 else
00838 fprintf(fd, "%sreturn __x.sget%s();\n", ctx->get(),
00839 getstr(className(cls, False)));
00840
00841 ctx->pop();
00842
00843 fprintf(fd, "%s}\n\n", ctx->get());
00844
00845 if (isVarDim() && *_const)
00846 {
00847 fprintf(fd, "%sint %s_cnt()\n", ctx->get(),
00848 attrName(name, True, hints.attr_style));
00849 fprintf(fd, "%s{\n", ctx->get());
00850 ctx->push();
00851 fprintf(fd, "%sreturn %s[%d].getSize(this);\n", ctx->get(),
00852 __agritems, num);
00853 ctx->pop();
00854 fprintf(fd, "%s}\n\n", ctx->get());
00855 }
00856
00857 if (cls->asCollectionClass())
00858 return generateCollGetMethod_Java(own, ctx, isoid,
00859 hints, _const);
00860 return Success;
00861 }
00862
00863 Status
00864 Attribute::generateCollGetMethod_Java(Class *own, GenContext *ctx,
00865 Bool isoid,
00866 const GenCodeHints &hints,
00867 const char *_const)
00868 {
00869 FILE *fd = ctx->getFile();
00870 int ndims = typmod.ndims, i;
00871 Bool _isref;
00872 eyedblib::int16 _dim;
00873 Class *cl = const_cast<Class *>(cls->asCollectionClass()->getCollClass(&_isref, &_dim));
00874 int not_basic = _isref || (!cl->asBasicClass() && !cl->asEnumClass());
00875 const char *ref = (not_basic ? "*" : "");
00876 const char *classname = isIndirect() ?
00877 className(cls, True) : className(cls, False);
00878 const char *oclassname = _isref ?
00879 className(cl, True) : className(cl, False);
00880 const char *comma = (ndims ? ", " : "");
00881
00882 Bool ordered = (cls->asCollArrayClass() || cls->asCollListClass()) ? True : False;
00883 if (isoid)
00884 {
00885 if (!_isref)
00886 return Success;
00887
00888 fprintf(fd, " public org.eyedb.Oid %s(int ind%s",
00889 ATTRNAME_1(name, (ordered ? GenCodeHints::tRetrieveOidItemAt : GenCodeHints::tGetOidItemAt), hints), comma);
00890 dimArgsGen(fd, ndims, True);
00891 fprintf(fd, ") throws org.eyedb.Exception {\n");
00892
00893 fprintf(fd, "%sorg.eyedb.Oid tmp;\n", ctx->get());
00894 fprintf(fd, "%sorg.eyedb.Collection coll = %s(", ctx->get(),
00895 ATTRNAME(name, tGetColl, hints));
00896
00897 for (i = 0; i < ndims; i++)
00898 fprintf(fd, "a%d, ", i);
00899
00900 fprintf(fd, ");\n\n", ctx->get());
00901 fprintf(fd, "%sif (coll == null)\n", ctx->get());
00902 fprintf(fd, "%s return null;\n\n", ctx->get());
00903
00904 if (cls->asCollArrayClass() || cls->asCollListClass())
00905 fprintf(fd, "%stmp = ((org.eyedb.CollArray)coll).retrieveOidAt(ind);\n", ctx->get());
00906 else
00907 fprintf(fd, "%stmp = coll.getOidAt(ind);\n", ctx->get());
00908 fprintf(fd, "%sreturn tmp;\n", ctx->get());
00909 fprintf(fd, "}\n\n");
00910 return Success;
00911 }
00912
00913 if (!*_const && cl->asBasicClass())
00914 return Success;
00915
00916 if (!strcmp(cl->getName(), char_class_name) && _dim > 1)
00917 {
00918 fprintf(fd, "String %s(int ind%s",
00919 ATTRNAME_1(name, (ordered ? GenCodeHints::tRetrieveItemAt : GenCodeHints::tGetItemAt), hints), comma);
00920 }
00921 else if (_dim == 1)
00922 fprintf(fd, " public %s %s(int ind%s",
00923 oclassname,
00924 ATTRNAME_1(name, (ordered ? GenCodeHints::tRetrieveItemAt : GenCodeHints::tGetItemAt), hints), comma);
00925 else
00926 return Success;
00927
00928 dimArgsGen(fd, ndims, True);
00929 fprintf(fd, ")\n%sthrows org.eyedb.Exception {\n", ctx->get());
00930
00931 ctx->push();
00932 fprintf(fd, "%sorg.eyedb.Collection coll = %s(", ctx->get(),
00933 ATTRNAME(name, tGetColl, hints));
00934
00935 for (i = 0; i < ndims; i++)
00936 fprintf(fd, "a%d, ", i);
00937
00938 fprintf(fd, ");\n\n", ctx->get());
00939 fprintf(fd, "%sif (coll == null)\n", ctx->get());
00940 if (not_basic)
00941 {
00942 fprintf(fd, "%s return null;\n\n", ctx->get());
00943 fprintf(fd, "%s%s tmp;\n", ctx->get(), oclassname);
00944 if (cls->asCollArrayClass() || cls->asCollListClass())
00945 fprintf(fd, "%stmp = (%s)((org.eyedb.CollArray)coll).retrieveObjectAt(ind);\n", ctx->get(), oclassname);
00946 else
00947 fprintf(fd, "%stmp = (%s)coll.getObjectAt(ind);\n", ctx->get(),
00948 oclassname);
00949 }
00950 else
00951 {
00952 fprintf(fd, "%s return;\n\n", ctx->get(), oclassname);
00953 fprintf(fd, "%sorg.eyedb.Value tmp;\n", ctx->get());
00954 if (cls->asCollArrayClass() || cls->asCollListClass())
00955 fprintf(fd, "%stmp = ((org.eyedb.CollArray)coll).retrieveValueAt(ind);\n", ctx->get());
00956 else
00957 fprintf(fd, "%stmp = coll.getValueAt(ind);\n", ctx->get());
00958 }
00959
00960 if (not_basic)
00961 fprintf(fd, "%sreturn tmp;\n", ctx->get());
00962 else
00963 fprintf(fd, "%sreturn tmp.%s;\n", ctx->get(),
00964 Value::getAttributeName(cl, (_isref || (_dim > 1)) ?
00965 True : False));
00966 ctx->pop();
00967 fprintf(fd, "%s}\n\n", ctx->get());
00968 return Success;
00969 }
00970
00971 Status Attribute::generateBody_Java(Class *own,
00972 GenContext *ctx,
00973 const GenCodeHints &hints,
00974 const char *prefix)
00975 {
00976 FILE *fd = ctx->getFile();
00977 int ndims = typmod.ndims, i;
00978 int maxdims = typmod.maxdims;
00979 int not_basic = NOT_BASIC();
00980 const char *ref = (not_basic ? "*" : "");
00981 int is_string = (ndims == 1 && !strcmp(cls->getName(), char_class_name));
00982 int is_raw = (ndims == 1 && !strcmp(cls->getName(), "byte"));
00983 const char *typestr, *postfix, *fname;
00984
00985
00986 if (is_string)
00987 {
00988 typestr = "String";
00989 fname = typestr;
00990 postfix = "";
00991 }
00992 else if (is_raw)
00993 {
00994 typestr = "byte";
00995 fname = "Raw";
00996 postfix = "[]";
00997 }
00998
00999 if (is_string || is_raw)
01000 {
01001 fprintf(fd, "%spublic void %s(%s _%s%s)\n",
01002 ctx->get(),
01003 attrName(name, False, hints.attr_style), typestr, name, postfix);
01004
01005 fprintf(fd, "%sthrows org.eyedb.Exception {\n", ctx->get());
01006 ctx->push();
01007 if (isVarDim())
01008 {
01009 if (is_string)
01010 fprintf(fd, "%sint len = _%s.length() + 1;\n\n", ctx->get(), name);
01011 else
01012 fprintf(fd, "%sint len = _%s.length;\n\n", ctx->get(), name);
01013
01014 fprintf(fd, "%sint size = %s[%d].getSize(this);\n", ctx->get(),
01015 __agritems, num);
01016 fprintf(fd, "%sif (size < len)\n", ctx->get());
01017 ctx->push();
01018 fprintf(fd, "%s%s[%d].setSize(this, len);\n", ctx->get(),
01019 __agritems, num);
01020 ctx->pop();
01021 fprintf(fd, "%s%s[%d].set%sValue(this, _%s);\n",
01022 ctx->get(), __agritems, num, fname, name);
01023 }
01024 else
01025 fprintf(fd, "%s%s[%d].set%sValue(this, _%s);\n",
01026 ctx->get(), __agritems, num, fname, name);
01027
01028 ctx->pop();
01029 fprintf(fd, "%s}\n\n", ctx->get());
01030 }
01031
01032 generateSetMethod_Java(own, ctx, False, hints);
01033
01034
01035 if (is_string || is_raw)
01036 {
01037 fprintf(fd, "%spublic %s%s %s()\n", ctx->get(),
01038 typestr, postfix,
01039 attrName(name, True, hints.attr_style));
01040 fprintf(fd, "%sthrows org.eyedb.Exception {\n", ctx->get());
01041 ctx->push();
01042 fprintf(fd, "%sreturn %s[%d].get%sValue(this);\n",
01043 ctx->get(), __agritems, num, fname);
01044 ctx->pop();
01045 fprintf(fd, "%s}\n\n", ctx->get());
01046 }
01047 else
01048 generateGetMethod_Java(own, ctx, False, hints, "const ", prefix);
01049
01050 if (isIndirect())
01051 {
01052 generateSetMethod_Java(own, ctx, True, hints);
01053 generateGetMethod_Java(own, ctx, True, hints, "", prefix);
01054 }
01055
01056 generateSetMethod_Java(own, ctx, hints);
01057
01058 return Success;
01059 }
01060
01061
01062 Status Attribute::generateCode_Java(Class *own,
01063 GenContext *ctx,
01064 const GenCodeHints &hints,
01065 const char *prefix)
01066 {
01067 FILE *fd = ctx->getFile();
01068 int ndims = typmod.ndims, i;
01069 int not_basic = NOT_BASIC();
01070 const char *ref1 = (not_basic ? "*" : "");
01071 const char *ref2 = (not_basic ? " *" : " ");
01072 const char *comma = (ndims ? ", " : "");
01073
01074 if (cls->asCollectionClass())
01075 {
01076 fprintf(fd, "%spublic int %s(", ctx->get(),
01077 ATTRNAME(name, tGetCount, hints));
01078 dimArgsGen(fd, ndims);
01079 fprintf(fd, ") throws org.eyedb.Exception {\n");
01080 ctx->push();
01081 fprintf(fd, "%sorg.eyedb.Collection _coll = %s(", ctx->get(), ATTRNAME(name, tGetColl, hints));
01082 for (i = 0; i < ndims; i++)
01083 fprintf(fd, "a%d, ", i);
01084 fprintf(fd, ");\n");
01085 fprintf(fd, "%sreturn (_coll != null ? _coll.getCount() : 0);\n",
01086 ctx->get());
01087 ctx->pop();
01088 fprintf(fd, "%s}\n\n", ctx->get());
01089 }
01090
01091
01092 generateBody_Java(own, ctx, hints, prefix);
01093
01094 return Success;
01095 }
01096
01097 static void const_f0(FILE *fd, Class *parent, const char *var,
01098 Bool fill = False)
01099 {
01100 if (!strcmp(parent->getName(), "struct"))
01101 fprintf(fd, "super(%s);", var);
01102 else if (!strcmp(parent->getName(), "union"))
01103 fprintf(fd, "super(%s);", var);
01104 else
01105 fprintf(fd, "super(%s, 1);", var);
01106
01107 fprintf(fd, "\n");
01108 }
01109
01110 static void const_f01(FILE *fd, Class *parent, const char *var,
01111 Bool fill = False)
01112 {
01113 if (!strcmp(parent->getName(), "struct"))
01114 fprintf(fd, "super(%s, share);", var);
01115 else if (!strcmp(parent->getName(), "union"))
01116 fprintf(fd, "super(%s, share);", var);
01117 else
01118 fprintf(fd, "super(%s, share, 1);", var);
01119
01120 fprintf(fd, "\n");
01121 }
01122
01123 static void const_f1(FILE *fd, GenContext *ctx, const char *name, Bool share)
01124 {
01125 fprintf(fd, "%sheaderCode(org.eyedb.ObjectHeader._Struct_Type, "
01126 "idr_psize, org.eyedb.ObjectHeader.IDB_XINFO_LOCAL_OBJ, true);\n",
01127 ctx->get());
01128
01129 if (share)
01130 fprintf(fd, "%sif (!share)\n", ctx->get());
01131
01132 fprintf(fd, "%s%sgetClass(true).newObjRealize(getDatabase(), this);\n", ctx->get(), (share ? " " : ""));
01133 fprintf(fd, "%ssetGRTObject(true);\n", ctx->get());
01134 }
01135
01136 Status AgregatClass::generateConstructors_Java(GenContext *ctx)
01137 {
01138 FILE *fd = ctx->getFile();
01139
01140 fprintf(fd, "%spublic %s(org.eyedb.Database db) throws org.eyedb.Exception {\n", ctx->get(), name);
01141
01142 ctx->push();
01143 fprintf(fd, ctx->get());
01144 const_f0(fd, parent, "db", True);
01145
01146 fprintf(fd, "%sinitialize(db);\n", ctx->get());
01147 ctx->pop();
01148 fprintf(fd, "%s}\n\n", ctx->get());
01149
01150 fprintf(fd, "%spublic %s(org.eyedb.Database db, org.eyedb.Dataspace dataspace) throws org.eyedb.Exception {\n", ctx->get(), name);
01151
01152 ctx->push();
01153 fprintf(fd, ctx->get());
01154 const_f0(fd, parent, "db, dataspace", True);
01155
01156 fprintf(fd, "%sinitialize(db);\n", ctx->get());
01157 ctx->pop();
01158 fprintf(fd, "%s}\n\n", ctx->get());
01159
01160 fprintf(fd, "%sprivate void initialize(org.eyedb.Database db) throws org.eyedb.Exception {\n", ctx->get(),
01161 name, name);
01162 ctx->push();
01163 fprintf(fd, "%ssetClass(((db != null) ? db.getSchema().getClass(\"%s\") : %s.idbclass));\n\n", ctx->get(), getAliasName(), className(this));
01164
01165
01166
01167
01168 fprintf(fd, "%ssetIDR(new byte[idr_objsz]);\n\n",
01169 ctx->get());
01170 fprintf(fd, "%sorg.eyedb.Coder.memzero(getIDR(), org.eyedb.ObjectHeader.IDB_OBJ_HEAD_SIZE, "
01171 "idr_objsz - org.eyedb.ObjectHeader.IDB_OBJ_HEAD_SIZE);\n",
01172 ctx->get());
01173
01174 const_f1(fd, ctx, name, False);
01175 fprintf(fd, "%suserInitialize();\n", ctx->get());
01176 ctx->pop();
01177 fprintf(fd, "%s}\n\n", ctx->get());
01178
01179 fprintf(fd, "%spublic %s(org.eyedb.Struct x, boolean share) throws org.eyedb.Exception {\n", ctx->get(),
01180 name, name);
01181
01182 ctx->push();
01183 fprintf(fd, ctx->get());
01184 const_f01(fd, parent, "x", True);
01185 const_f1(fd, ctx, name, True);
01186 fprintf(fd, "%suserInitialize();\n", ctx->get());
01187 ctx->pop();
01188 fprintf(fd, "%s}\n\n", ctx->get());
01189
01190 fprintf(fd, "%spublic %s(%s x, boolean share) throws org.eyedb.Exception {\n", ctx->get(), name, name);
01191
01192 ctx->push();
01193 fprintf(fd, ctx->get());
01194 const_f01(fd, parent, "x", True);
01195 const_f1(fd, ctx, name, True);
01196 fprintf(fd, "%suserInitialize();\n", ctx->get());
01197 ctx->pop();
01198
01199 fprintf(fd, "%s}\n\n", ctx->get());
01200
01201 return Success;
01202 }
01203
01204 static int
01205 true_items_count(const Class *cls, Attribute **items, int items_cnt)
01206 {
01207 for (int i = 0; i < items_cnt; i++)
01208 if (items[i]->getClassOwner() == cls && !items[i]->isNative())
01209 return items_cnt - i;
01210
01211 return 0;
01212 }
01213
01214 Status AgregatClass::generateClassDesc_Java(GenContext *ctx,
01215 const char *prefix)
01216 {
01217 FILE *fd = ctx->getFile();
01218 Status status;
01219 const char *_type = (asStructClass() ? "org.eyedb.Struct" : "org.eyedb.Union");
01220
01221 fprintf(fd, "%sstatic %sClass make(%sClass %s_class, org.eyedb.Schema m)\n", ctx->get(), _type, _type, name);
01222 fprintf(fd, "%s throws org.eyedb.Exception {\n", ctx->get());
01223 ctx->push();
01224
01225 fprintf(fd, "%sif (%s_class == null)\n", ctx->get(), name);
01226 fprintf(fd,"%s return new %sClass(\"%s\", ((m != null) ? m.getClass(\"%s\") : %s.idbclass));\n", ctx->get(), _type, getAliasName(),
01227 className(parent, True, True), className(parent));
01228
01229 if (items_cnt)
01230 {
01231 fprintf(fd, "%sorg.eyedb.Attribute[] attr = new org.eyedb.Attribute[%d];\n",
01232 ctx->get(), items_cnt);
01233 fprintf(fd, "%sint[] dims;\n", ctx->get());
01234
01235 for (int i = 0; i < items_cnt; i++)
01236 {
01237 if (items[i]->class_owner == (void *)this)
01238 {
01239 status = items[i]->generateClassDesc_Java(ctx);
01240 if (status)
01241 return status;
01242 }
01243 }
01244
01245 int count = true_items_count(this, items, items_cnt);
01246 fprintf(fd, "\n%s%s_class.setAttributes(attr, %d, %d);\n", ctx->get(),
01247 name, items_cnt - count, count);
01248 }
01249
01250
01251
01252
01253
01254
01255
01256 fprintf(fd, "\n%sreturn %s_class;\n", ctx->get(), name);
01257
01258 ctx->pop();
01259 fprintf(fd, "%s}\n\n", ctx->get());
01260
01261 fprintf(fd, "%sstatic void init_p()\n", ctx->get());
01262 fprintf(fd, "%s throws org.eyedb.Exception {\n", ctx->get());
01263 ctx->push();
01264 fprintf(fd, "%sidbclass = make(null, null);\n", ctx->get());
01265 fprintf(fd, "%stry {\n", ctx->get());
01266 ctx->push();
01267 fprintf(fd, "%s%sDatabase.hash.put(\"%s\", %s.class.getConstructor(%sDatabase.clazz));\n",
01268 ctx->get(), prefix, getAliasName(), name, prefix);
01269 ctx->pop();
01270 fprintf(fd, "%s} catch(java.lang.Exception e) {\n", ctx->get());
01271 ctx->push();
01272 fprintf(fd, "%se.printStackTrace();\n", ctx->get());
01273
01274 ctx->pop();
01275 fprintf(fd, "%s}\n", ctx->get());
01276 ctx->pop();
01277 fprintf(fd, "%s}\n\n", ctx->get());
01278
01279 fprintf(fd, "%sstatic void init()\n", ctx->get());
01280 fprintf(fd, "%s throws org.eyedb.Exception {\n", ctx->get());
01281 ctx->push();
01282 fprintf(fd, "%smake((%sClass)idbclass, null);\n\n", ctx->get(),
01283 _type);
01284
01285
01286 fprintf(fd, "%sidr_objsz = idbclass.getObjectSize();\n",
01287 ctx->get());
01288 fprintf(fd, "%sidr_psize = idbclass.getObjectPSize();\n",
01289 ctx->get());
01290
01291
01292
01293 ctx->pop();
01294 fprintf(fd, "%s}\n\n", ctx->get());
01295 return Success;
01296 }
01297
01298 static inline void
01299 argTypeDump(GenContext *ctx, ArgType *argtype)
01300 {
01301 FILE *fd = ctx->getFile();
01302
01303 fprintf(fd, "%sargtype = new ArgType();\n", ctx->get());
01304 fprintf(fd, "%sargtype->setType(%d);\n", ctx->get(),
01305 argtype->getType());
01306
01307 if (argtype->getType() == OBJ_TYPE)
01308 fprintf(fd, "%sargtype->setClname(\"%s\");\n", ctx->get(),
01309 argtype->getClname().c_str());
01310 }
01311
01312 Status AgregatClass::generateClassComponent_Java(GenContext *ctx,
01313 GenContext *ctxMth,
01314 GenContext *ctxTrg)
01315 {
01316 FILE *fd = ctx->getFile();
01317 FILE *fdmth = ctxMth->getFile();
01318 FILE *fdtrg = ctxTrg->getFile();
01319
01320 Status status;
01321 const char *_type = (asStructClass() ? "Struct" : "Union");
01322
01323 fprintf(fd, "static Status %s_comp_realize(Database *db, Class *cls)\n{\n", name);
01324
01325 ctx->push();
01326 fprintf(fd, "%sClassComponent *comp;\n", ctx->get());
01327 fprintf(fd, "%sStatus status;\n", ctx->get());
01328 fprintf(fd, "%sSignature *sign;\n", ctx->get());
01329 fprintf(fd, "%sArgType *argtype;\n\n", ctx->get());
01330
01331 LinkedListCursor c(complist);
01332
01333 ClassComponent *comp;
01334 while (complist->getNextObject(&c, (void *&)comp))
01335 {
01336 if (comp->asTrigger())
01337 {
01338 Trigger *trig = comp->asTrigger();
01339 fprintf(fd, "%scomp = new Trigger(db, cls, %d, \"%s\", %s);\n",
01340 ctx->get(), trig->getType(), trig->getSuffix().c_str(),
01341 trig->getLight() ? "true" : "false");
01342 fprintf(fdtrg, "extern \"C\"\n");
01343 fprintf(fdtrg, "Status %s(ArgType type, Database *db, "
01344 "const Oid &oid, Object *o)\n{\n",
01345 trig->getCSym());
01346 fprintf(fdtrg, " return Success;\n}\n\n");
01347 }
01348 else if (comp->asMethod())
01349 {
01350 Method *mth = comp->asMethod();
01351 fprintf(fd, "%ssign = new Signature();\n",
01352 ctx->get());
01353 Executable *ex = mth->getEx();
01354 Signature *sign = ex->getSign();
01355 const char *prefix;
01356 const char *extref = ex->getExtrefBody().c_str();
01357
01358 if (mth->asFEMethod_C())
01359 prefix = "FE";
01360 else
01361 prefix = "BE";
01362
01363 argTypeDump(ctx, sign->getRettype());
01364 fprintf(fd, "%ssign->setRettype(argtype);\n", ctx->get());
01365 fprintf(fd, "%sdelete argtype;\n\n", ctx->get());
01366
01367 int nargs = sign->getNargs();
01368 fprintf(fd, "%ssign->setNargs(%d);\n", ctx->get(), nargs);
01369 for (int i = 0; i < nargs; i++)
01370 {
01371 argTypeDump(ctx, sign->getTypes(i));
01372 fprintf(fd, "%ssign->setTypes(%d, argtype);\n", ctx->get(),
01373 i);
01374 fprintf(fd, "%sdelete argtype;\n\n", ctx->get());
01375 }
01376
01377 fprintf(fd,
01378 "%scomp = new %sMethod_Java(db, cls, \"%s\", sign, \"%s\");\n",
01379 ctx->get(), prefix, ex->getExname().c_str(), extref);
01380 fprintf(fdmth, "extern \"C\"\n");
01381 fprintf(fdmth, "Status %s(Database *db, %sMethod_C *m, "
01382 "Object *o, ArgArray &array, Argument &retarg)\n{\n",
01383 Executable::makeInternalName(ex->getExname().c_str(),
01384 sign, False,
01385 getClass()->getName()),
01386 prefix);
01387
01388 fprintf(fdmth, " return Success;\n}\n\n");
01389 }
01390 else
01391 abort();
01392
01393 fprintf(fd, "%sif (status = comp->realize()) return status;\n\n", ctx->get());
01394 if (comp->asMethod())
01395 fprintf(fd, "%sdelete sign;\n\n", ctx->get());
01396 }
01397
01398 fprintf(fd, "%sreturn Success;\n", ctx->get());
01399
01400 ctx->pop();
01401 fprintf(fd, "}\n\n");
01402 return Success;
01403 }
01404
01405 Status AgregatClass::generateCode_Java(Schema *m,
01406 const char *prefix,
01407 const GenCodeHints &hints,
01408 FILE *fd)
01409 {
01410 GenContext ctx(fd);
01411 int i;
01412 Status status;
01413
01414 fprintf(fd, "public class %s extends %s {\n", name, className(parent));
01415
01416 ctx.push();
01417
01418
01419
01420
01421
01422
01423 fprintf(fd, "\n");
01424
01425 generateConstructors_Java(&ctx);
01426
01427 for (i = 0; i < items_cnt; i++)
01428 {
01429 if (items[i]->class_owner == (void *)this)
01430 {
01431 status = items[i]->generateCode_Java(this, &ctx, hints, prefix);
01432 if (status)
01433 return status;
01434 }
01435 }
01436
01437
01438
01439
01440
01441
01442 fprintf(fd, "\n");
01443
01444 fprintf(fd, "%sprotected %s(org.eyedb.Database db, int dummy) {\n", ctx.get(),
01445 name);
01446
01447 ctx.push();
01448 fprintf(fd, ctx.get());
01449 const_f0(fd, parent, "db");
01450
01451 ctx.pop();
01452 fprintf(fd, "%s}\n\n", ctx.get());
01453
01454 fprintf(fd, "%sprotected %s(org.eyedb.Database db, org.eyedb.Dataspace dataspace, int dummy) {\n", ctx.get(),
01455 name);
01456
01457 ctx.push();
01458 fprintf(fd, ctx.get());
01459 const_f0(fd, parent, "db, dataspace");
01460
01461 ctx.pop();
01462 fprintf(fd, "%s}\n\n", ctx.get());
01463
01464 fprintf(fd, "%sprotected %s(org.eyedb.Struct x, boolean share, int dummy) {\n ",
01465 ctx.get(), name);
01466 ctx.push();
01467 fprintf(fd, ctx.get());
01468 const_f01(fd, parent, "x");
01469 ctx.pop();
01470 fprintf(fd, "%s}\n\n", ctx.get());
01471
01472 fprintf(fd, "%sprotected %s(%s x, boolean share, int dummy) {\n ",
01473 ctx.get(), name, name);
01474
01475 ctx.push();
01476 fprintf(fd, ctx.get());
01477 const_f01(fd, parent, "x");
01478 ctx.pop();
01479
01480 fprintf(fd, "%s}\n", ctx.get());
01481
01482
01483
01484
01485
01486
01487 fprintf(fd, "\n");
01488
01489 fprintf(fd, "%sstatic int idr_psize;\n", ctx.get());
01490 fprintf(fd, "%sstatic int idr_objsz;\n", ctx.get());
01491 fprintf(fd, "%spublic static org.eyedb.Class idbclass;\n", ctx.get());
01492
01493 generateClassDesc_Java(&ctx, prefix);
01494
01495
01496
01497 if (getTiedCode())
01498 {
01499 fprintf(fd, "\n%s// ----------------------------------------------------------------------\n", ctx.get());
01500 fprintf(fd, "%s// %s User Part\n", ctx.get(), name);
01501 fprintf(fd, "%s// ----------------------------------------------------------------------\n", ctx.get());
01502 fprintf(fd, "%s\n", getTiedCode());
01503 }
01504
01505 fprintf(fd, "}\n\n");
01506
01507 ctx.pop();
01508
01509 return Success;
01510 }
01511
01512 Status EnumClass::generateClassDesc_Java(GenContext *ctx)
01513 {
01514 FILE *fd = ctx->getFile();
01515 Status status;
01516
01517 fprintf(fd, "%sstatic org.eyedb.EnumClass make(org.eyedb.EnumClass %s_class, org.eyedb.Schema m)\n", ctx->get(), name);
01518
01519 fprintf(fd, "%s{\n", ctx->get());
01520 ctx->push();
01521 fprintf(fd, "%sif (%s_class == null)\n", ctx->get(), name);
01522 fprintf(fd, "%s return new org.eyedb.EnumClass(\"%s\");\n\n", ctx->get(),
01523 getAliasName());
01524
01525 fprintf(fd, "%sorg.eyedb.EnumItem[] en = new org.eyedb.EnumItem[%d];\n", ctx->get(), items_cnt);
01526
01527 for (int i = 0; i < items_cnt; i++)
01528 fprintf(fd, "%sen[%d] = new org.eyedb.EnumItem(\"%s\", %d, %d);\n", ctx->get(),
01529 i, items[i]->getName(), items[i]->getValue(), i);
01530
01531 fprintf(fd, "\n%s%s_class.setEnumItems(en);\n", ctx->get(), name);
01532
01533
01534
01535
01536
01537
01538
01539 fprintf(fd, "\n%sreturn %s_class;\n", ctx->get(), name);
01540
01541 ctx->pop();
01542 fprintf(fd, "%s}\n\n", ctx->get());
01543
01544 fprintf(fd, "%sstatic void init_p()\n%s{\n", ctx->get(), ctx->get());
01545 ctx->push();
01546 fprintf(fd, "%sidbclass = make(null, null);\n", ctx->get());
01547 ctx->pop();
01548 fprintf(fd, "%s}\n\n", ctx->get());
01549
01550 fprintf(fd, "%sstatic void init()\n%s{\n", ctx->get(), ctx->get());
01551 ctx->push();
01552 fprintf(fd, "%smake((org.eyedb.EnumClass)idbclass, null);\n", ctx->get());
01553
01554
01555
01556 ctx->pop();
01557
01558 fprintf(fd, "%s}\n", ctx->get());
01559
01560 return Success;
01561 }
01562
01563 Status EnumClass::generateCode_Java(Schema *,
01564 const char *prefix,
01565 const GenCodeHints &hints,
01566 FILE *fd)
01567 {
01568 GenContext ctx(fd);
01569 int i;
01570
01571 fprintf(fd, "public class %s extends org.eyedb.Enum {\n\n", name);
01572
01573 ctx.push();
01574
01575 fprintf(fd, "%s%s(org.eyedb.Database db)\n", ctx.get(), name);
01576 fprintf(fd, "%s{\n", ctx.get());
01577 ctx.push();
01578 fprintf(fd, "%ssuper(db);\n", ctx.get());
01579 ctx.pop();
01580 fprintf(fd, "%s}\n\n", ctx.get());
01581
01582 fprintf(fd, "%s%s()\n", ctx.get(), name);
01583 fprintf(fd, "%s{\n", ctx.get());
01584 ctx.push();
01585 fprintf(fd, "%ssuper();\n", ctx.get());
01586 ctx.pop();
01587 fprintf(fd, "%s}\n\n", ctx.get());
01588
01589 EnumItem **it;
01590 for (i = 0, it = items; i < items_cnt; i++, it++)
01591 fprintf(fd, "%spublic static final int %s = %d;\n", ctx.get(),
01592 (*it)->getName(), (*it)->getValue());
01593
01594 fprintf(fd, "\n");
01595
01596 generateClassDesc_Java(&ctx);
01597
01598 fprintf(fd, "%spublic static org.eyedb.Class idbclass;\n", ctx.get());
01599
01600 ctx.pop();
01601
01602 fprintf(fd, "}\n\n");
01603 return Success;
01604 }
01605
01606 Status CollectionClass::generateCode_Java(Schema *,
01607 const char *prefix,
01608 const GenCodeHints &hints,
01609 FILE *fd)
01610 {
01611 GenContext ctx(fd);
01612 int i;
01613 Status status;
01614 const char *c_name = getCName();
01615
01616 const char *_type = className(this);
01617
01618 fprintf(fd, "public class %s extends org.eyedb.CollSetClass {\n\n", c_name);
01619
01620 ctx.push();
01621 fprintf(fd, "%sprivate %s(org.eyedb.Class coll_class, boolean isref) {\n",
01622 ctx.get(), c_name);
01623 ctx.push();
01624 fprintf(fd, "%ssuper(coll_class, isref);\n", ctx.get());
01625 ctx.pop();
01626 fprintf(fd, "%s}\n\n", ctx.get());
01627 fprintf(fd, "%spublic static org.eyedb.Class idbclass;\n\n", ctx.get());
01628
01629
01630 fprintf(fd, "%sstatic %sClass make(%sClass cls, "
01631 "org.eyedb.Schema m)\n", ctx.get(), _type, _type);
01632 fprintf(fd, "%s{\n", ctx.get());
01633 ctx.push();
01634 fprintf(fd, "%sif (cls == null)\n%s {\n", ctx.get(), ctx.get());
01635
01636 ctx.push();
01637 fprintf(fd, "%scls = new %sClass(((m != null) ? m.getClass(\"%s\") : %s.idbclass), ", ctx.get(), _type, coll_class->getName(),
01638 className(coll_class));
01639
01640 if (dim > 1)
01641 fprintf(fd, "%d);\n", dim);
01642 else
01643 fprintf(fd, "%s);\n", (isref ? "true" : "false"));
01644
01645
01646
01647 ctx.pop();
01648 fprintf(fd, "%s}\n", ctx.get());
01649
01650 fprintf(fd, "%sreturn cls;\n", ctx.get());
01651 ctx.pop();
01652 fprintf(fd, "%s}\n\n", ctx.get());
01653
01654 fprintf(fd, "%sstatic void init_p()\n", ctx.get());
01655 fprintf(fd, "%s{\n", ctx.get());
01656 ctx.push();
01657 fprintf(fd, "%sidbclass = make(null, null);\n", ctx.get());
01658 ctx.pop();
01659 fprintf(fd, "%s}\n", ctx.get());
01660 ctx.pop();
01661
01662 fprintf(fd, "}\n\n");
01663
01664 return Success;
01665 }
01666 }