Skip to content

Commit 2bd33c9

Browse files
authored
Updates for Version 2.0 beta
1 parent b5e7add commit 2bd33c9

File tree

7 files changed

+402
-74
lines changed

7 files changed

+402
-74
lines changed

Attribute.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,14 +1027,20 @@ public void saveEMF(PrintWriter out)
10271027

10281028
public void saveKM3(PrintWriter out)
10291029
{ if (isStatic())
1030-
{ out.println(" static attribute " + getName() + " : " + getType() + ";"); }
1031-
out.println(" attribute " + getName() + " : " + getType() + ";");
1030+
{ out.println(" static attribute " + getName() + " : " + getType() + ";"); }
1031+
else if (isIdentity())
1032+
{ out.println(" attribute " + getName() + " identity : " + getType() + ";"); }
1033+
else
1034+
{ out.println(" attribute " + getName() + " : " + getType() + ";"); }
10321035
}
10331036

10341037
public String getKM3()
10351038
{ if (isStatic())
10361039
{ return " static attribute " + getName() + " : " + getType() + ";"; }
1037-
return " attribute " + getName() + " : " + getType() + ";";
1040+
else if (isIdentity())
1041+
{ return " attribute " + getName() + " identity : " + getType() + ";"; }
1042+
else
1043+
{ return " attribute " + getName() + " : " + getType() + ";"; }
10381044
}
10391045

10401046
public void saveEcore(PrintWriter out)
@@ -3516,6 +3522,19 @@ public String getHtmlGen()
35163522
public String getFormInput()
35173523
{ String nme = getName();
35183524
String label = nme;
3525+
String res = "";
3526+
3527+
if (type != null && type.isEnumerated())
3528+
{ Vector vals = type.getValues();
3529+
res = "<p><strong>" + label + "</strong>\n" +
3530+
"<select name=\"" + nme + "\">\n";
3531+
for (int i = 0; i < vals.size(); i++)
3532+
{ String val = (String) vals.get(i);
3533+
res = res + " <option value=\"" + val + "\">" + val + "</option>\n";
3534+
}
3535+
res = res + "</select>\n";
3536+
return res;
3537+
}
35193538

35203539
if (type != null && type.isEntity())
35213540
{ Entity etype = type.getEntity();
@@ -3524,7 +3543,7 @@ public String getFormInput()
35243543
{ label = nme + " (" + pk.getName() + ")"; }
35253544
}
35263545

3527-
String res =
3546+
res =
35283547
"<p><strong>" + label + "</strong>\n" +
35293548
"<input type = \"text\" name = \"" + nme + "\"/></p>\n";
35303549
return res;

Compiler2.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3767,7 +3767,7 @@ else if ("\"".equals(ss) && instring)
37673767

37683768

37693769

3770-
public Vector parseKM3(Vector entities, Vector types, Vector gens, Vector pasts)
3770+
public Vector parseKM3(Vector entities, Vector types, Vector gens, Vector pasts, Vector pnames)
37713771
{ Vector res = new Vector();
37723772
int en = lexicals.size()-1;
37733773

@@ -3787,13 +3787,13 @@ public Vector parseKM3(Vector entities, Vector types, Vector gens, Vector pasts)
37873787
{ String lex = lexicals.get(i) + "";
37883788
if ("package".equals(lex))
37893789
{ // parse contents of previous package:
3790-
Vector resp = parseKM3package(prevstart,i-1,entities,types,gens,pasts);
3790+
Vector resp = parseKM3package(prevstart,i-1,entities,types,gens,pasts,pnames);
37913791
res.addAll(resp);
37923792
prevstart = i;
37933793
}
37943794
}
37953795

3796-
Vector resp = parseKM3package(prevstart,en-1,entities,types,gens,pasts);
3796+
Vector resp = parseKM3package(prevstart,en-1,entities,types,gens,pasts,pnames);
37973797
res.addAll(resp);
37983798
return res;
37993799
}
@@ -3806,12 +3806,13 @@ public UseCase parseKM3UseCase(Vector entities, Vector types,
38063806

38073807

38083808
public Vector parseKM3package(int st, int en,
3809-
Vector entities, Vector types, Vector gens, Vector pasts)
3809+
Vector entities, Vector types, Vector gens, Vector pasts, Vector pnames)
38103810
{ Vector res = new Vector();
38113811
if ("package".equals(lexicals.get(st) + "") &&
38123812
"{".equals(lexicals.get(st+2) + ""))
38133813
{ String pname = lexicals.get(st+1) + "";
38143814
System.out.println(">> Parsing package " + pname);
3815+
pnames.add(pname);
38153816

38163817
for (int i = st+3; i < en; i++)
38173818
{ String lx = lexicals.get(i) + "";

Entity.java

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11222,9 +11222,9 @@ guard sqlite3_step(insertStatement) == SQLITE_DONE
1122211222
}
1122311223

1122411224
public String generateBean(Vector useCases, Vector cons, Vector entities,
11225-
Vector types)
11225+
Vector types, String appName)
1122611226
{ String ename = getName();
11227-
String res = "package beans;\n\n" +
11227+
String res = "package " + appName + ";\n\n" +
1122811228
"import java.util.*;\n" +
1122911229
"import java.sql.*;\n\n" +
1123011230
"public class " + ename + "Bean\n{ Dbi dbi = new Dbi();\n";
@@ -11348,6 +11348,134 @@ else if (tname.equals("double"))
1134811348
return res + "}\n";
1134911349
}
1135011350

11351+
public String generateJSPBean(String packageName, Vector useCases,
11352+
Vector cons, Vector entities, Vector types, CGSpec cgs)
11353+
{ String ename = getName();
11354+
String res = "package " + packageName + ";\n\n" +
11355+
"import java.util.Vector;\n" +
11356+
"import java.util.List;\n" +
11357+
"import java.util.Iterator;\n\n" +
11358+
11359+
"public class " + ename + "Bean\n{ ModelFacade model;\n";
11360+
for (int i = 0; i < attributes.size(); i++)
11361+
{ Attribute att = (Attribute) attributes.get(i);
11362+
String attnme = att.getName();
11363+
Type atttype = att.getType();
11364+
String tname = atttype.getName();
11365+
res = res + " private String " + attnme + " = \"\";\n";
11366+
if (tname.equals("int") || tname.equals("long"))
11367+
{ res = res + " private int i" + attnme + " = 0;\n"; }
11368+
else if (tname.equals("double"))
11369+
{ res = res + " private double d" + attnme + " = 0;\n"; }
11370+
else if (att.isEnumeration())
11371+
{ Vector vals = atttype.getValues();
11372+
res = res + " private " + tname + " e" + attnme + " = " + tname + "." + vals.get(0) + ";\n";
11373+
}
11374+
// booleans are treated as strings.
11375+
}
11376+
res = res + " private Vector errors = new Vector();\n\n" +
11377+
" public " + ename + "Bean()\n" +
11378+
" { model = ModelFacade.getInstance(); }\n\n";
11379+
for (int i = 0; i < attributes.size(); i++)
11380+
{ Attribute att = (Attribute) attributes.get(i);
11381+
String attnme = att.getName();
11382+
res = res + " public void set" + attnme + "(String " + attnme + "x)\n { " +
11383+
attnme + " = " + attnme + "x; }\n\n";
11384+
}
11385+
11386+
res = res + " public void resetData()\n { ";
11387+
for (int i = 0; i < attributes.size(); i++)
11388+
{ Attribute att = (Attribute) attributes.get(i);
11389+
String attname = att.getName();
11390+
res = res + attname + " = \"\";\n ";
11391+
}
11392+
res = res + "}\n\n";
11393+
11394+
for (int j = 0; j < useCases.size(); j++)
11395+
{ if (!(useCases.get(j) instanceof OperationDescription)) { continue; }
11396+
11397+
OperationDescription od = (OperationDescription) useCases.get(j);
11398+
if (this != od.getEntity()) { continue; }
11399+
11400+
Vector pars = od.getParameters();
11401+
String odname = od.getODName();
11402+
String action = od.getStereotype(0);
11403+
// build op that checks if parameters are correct, and does data conversions:
11404+
res = res + " public boolean is" + odname + "error()\n" +
11405+
" { errors.clear(); \n";
11406+
for (int k = 0; k < pars.size(); k++)
11407+
{ Attribute att = (Attribute) pars.get(k);
11408+
String check = att.getBeanCheckCode();
11409+
res = res + check;
11410+
}
11411+
11412+
if (action.equals("create") || action.equals("edit") || action.equals("set"))
11413+
{ Vector tests = getInvariantCheckTests(types,entities,pars,cgs);
11414+
for (int p = 0; p < tests.size(); p++)
11415+
{ String test = (String) tests.get(p);
11416+
res = res +
11417+
" if (" + test + ") { }\n" +
11418+
" else { errors.add(\"" + ename + " constraint " + (p+1) + " failed\"); }\n";
11419+
}
11420+
}
11421+
res = res + " return errors.size() > 0; }\n\n";
11422+
}
11423+
11424+
res = res + " public String errors() { return errors.toString(); }\n\n";
11425+
11426+
for (int j = 0; j < useCases.size(); j++)
11427+
{ if (!(useCases.get(j) instanceof OperationDescription)) { continue; }
11428+
OperationDescription od = (OperationDescription) useCases.get(j);
11429+
// and is responsibility of this bean
11430+
if (this != od.getEntity()) { continue; }
11431+
11432+
Vector pars = od.getParameters();
11433+
String odname = od.getODName();
11434+
String action = od.getStereotype(0);
11435+
String dbiop = od.getAndroidModelOpCall();
11436+
Vector correc = new Vector();
11437+
11438+
if (action.equals("create") || action.equals("delete") ||
11439+
action.equals("add") || action.equals("remove") ||
11440+
action.equals("edit") || action.equals("set"))
11441+
{ res = res + " public void " + odname + "()\n" + " { ";
11442+
res = res + dbiop + "\n ";
11443+
/* if (action.equals("set"))
11444+
{ Attribute att = (Attribute) pars.get(0);
11445+
Vector allinvs = new Vector();
11446+
allinvs.addAll(invariants);
11447+
allinvs.addAll(cons);
11448+
11449+
correc = att.sqlSetOperations(this,allinvs,entities,types);
11450+
res = res + odname + "(" + att.getBeanForm() +
11451+
", i" + ename.toLowerCase() + "Id);\n ";
11452+
} */
11453+
res = res + "resetData(); }\n\n";
11454+
11455+
/* if (correc.size() > 0)
11456+
{ res = res + correc.get(0) + "\n\n";
11457+
correc.remove(0);
11458+
od.addDbiMaintainOps(correc);
11459+
} */
11460+
} // for set, correcting code goes here as well.
11461+
else
11462+
{ Entity ent2 = this;
11463+
11464+
if (action.equals("get"))
11465+
{ String role = od.getStereotype(1);
11466+
Association ast = getRole(role);
11467+
if (ast != null)
11468+
{ ent2 = ast.getEntity2(); }
11469+
}
11470+
11471+
res = res + " public Iterator " + odname + "()\n" + " { ";
11472+
res = res + "List<" + ename + "VO> rs = " + dbiop + "\n" +
11473+
" return rs.iterator();\n }\n";
11474+
} // for getrole it is the TARGET entities fields
11475+
}
11476+
return res + "}\n";
11477+
}
11478+
1135111479
public String generateAndroidBean(String packageName, Vector useCases,
1135211480
Vector cons, Vector entities, Vector types, CGSpec cgs)
1135311481
{ String ename = getName();

KM3Editor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,12 @@ public void actionPerformed(ActionEvent e)
465465
Vector typs = new Vector();
466466
Vector pregens = new Vector();
467467
Vector preassocs = new Vector();
468+
Vector pnames = new Vector();
468469

469-
Vector items = comp.parseKM3(ents,typs,pregens,preassocs);
470+
Vector items = comp.parseKM3(ents,typs,pregens,preassocs,pnames);
470471
classArea.processKM3(ents,typs,pregens,preassocs,items);
472+
if (pnames.size() > 0)
473+
{ classArea.setSystemName((String) pnames.get(0)); }
471474

472475
File file = new File("output/mm.km3"); /* default */
473476
try

OperationDescription.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -752,11 +752,11 @@ public String getServletCode()
752752
return res;
753753
}
754754

755-
public String jspUpdateDeclarations(String ename)
755+
public String jspUpdateDeclarations(String ename, String appName)
756756
{ String bean = ename.toLowerCase();
757-
String beanclass = "beans." + ename + "Bean";
757+
String beanclass = appName + "." + ename + "Bean";
758758
return "<jsp:useBean id=\"" + bean +
759-
"\" scope=\"session\" \n " +
759+
"\" scope=\"request\" \n " +
760760
"class=\"" + beanclass + "\"/>";
761761
}
762762

@@ -775,9 +775,9 @@ public String jspParamTransfers(String ename, Vector atts)
775775
}
776776

777777

778-
public String jspUpdateText(String op, String ename, Vector atts)
778+
public String jspUpdateText(String op, String ename, Vector atts, String appName)
779779
{ String bean = ename.toLowerCase();
780-
String dec = jspUpdateDeclarations(ename);
780+
String dec = jspUpdateDeclarations(ename,appName);
781781
String sets = jspParamTransfers(ename, atts);
782782
String res = dec + "\n\r" + sets + "\n\r" +
783783
"<html>\n\r" +
@@ -792,26 +792,26 @@ public String jspUpdateText(String op, String ename, Vector atts)
792792
"<h2>" + op + " performed</h2>\n\r" +
793793
"<% } %>\n\r\n\r" +
794794
"<hr>\n\r\n\r" +
795-
"<%@ include file=\"commands.html\" %>\n\r" +
795+
"<%@ include file=\"index.html\" %>\n\r" +
796796
"</body>\n\r</html>\n\r";
797797
return res;
798798
}
799799

800-
public String jspQueryDeclarations(String ename)
800+
public String jspQueryDeclarations(String ename, String appName)
801801
{ String bean = ename.toLowerCase();
802-
String beanclass = "beans." + ename + "Bean";
802+
String beanclass = appName + "." + ename + "Bean";
803803
String res = "<%@ page import = \"java.util.*\" %>\n\r" +
804-
"<%@ page import = \"beans.*\" %>\n\r" +
804+
"<%@ page import = \"" + appName + ".*\" %>\n\r" +
805805
"<jsp:useBean id=\"" + bean +
806-
"\" scope=\"session\" \n\r " +
806+
"\" scope=\"request\" \n\r " +
807807
"class=\"" + beanclass + "\"/>";
808808
return res;
809809
}
810810

811811
public String jspQueryText(String op,
812-
String ename, Vector atts, Entity ent)
812+
String ename, Vector atts, Entity ent, String appName)
813813
{ String bean = ename.toLowerCase();
814-
String dec = jspQueryDeclarations(ename);
814+
String dec = jspQueryDeclarations(ename,appName);
815815
String sets = jspParamTransfers(ename, atts);
816816
Entity ent2 = ent;
817817
String action = getStereotype(0);
@@ -838,21 +838,21 @@ public String jspQueryText(String op,
838838
e2name + "VO) " + bean + "s.next(); %>\n\r" +
839839
ent2.getTableRow() + "\n\r" +
840840
"<% } %>\n\r</table>\n\r\n\r<hr>\n\r\n\r" +
841-
"<%@ include file=\"commands.html\" %>\n\r" +
841+
"<%@ include file=\"index.html\" %>\n\r" +
842842
"</body>\n\r</html>\n\r";
843843
return res;
844844
}
845845

846-
public String getJsp()
846+
public String getJsp(String appName)
847847
{ String action = getODName();
848848
String op = getStereotype(0);
849849
String ename = entity.getName();
850850
Vector pars = getParameters();
851851
if (op.equals("create") || op.equals("delete") ||
852852
op.equals("edit") || op.equals("add") ||
853853
op.equals("set") || op.equals("remove"))
854-
{ return jspUpdateText(action,ename,pars); }
855-
return jspQueryText(action,ename,pars,entity);
854+
{ return jspUpdateText(action,ename,pars,appName); }
855+
return jspQueryText(action,ename,pars,entity,appName);
856856
}
857857

858858
public String getRESTJsp(String appname)
@@ -960,8 +960,8 @@ public String jspRESTParamTransfers(Vector atts)
960960
}
961961

962962

963-
public String getInputPage()
964-
{ String codebase = "http://127.0.0.1:8080/servlets/";
963+
public String getInputPage(String appName)
964+
{ String codebase = "http://127.0.0.1:8080/examples/jsp/" + appName + "/";
965965
String op = getODName();
966966
String action = getStereotype(0);
967967
String jsp = codebase + op + ".jsp";
@@ -986,7 +986,7 @@ public String getInputPage()
986986
return res;
987987
}
988988

989-
public String getInputPage(String appname)
989+
/* public String getInputPage(String appname)
990990
{ String codebase = "http://127.0.0.1:8080/" + appname + "/servlets/";
991991
String op = getODName();
992992
String action = getStereotype(0);
@@ -1011,7 +1011,7 @@ public String getInputPage(String appname)
10111011
res = res + "<input type=\"submit\" value = \"" +
10121012
op + "\"/>\n\r</form>\n\r</body>\n\r</html>";
10131013
return res;
1014-
}
1014+
} */
10151015

10161016
public String getGenerationClass()
10171017
{ String nme = getName();

0 commit comments

Comments
 (0)