@@ -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 ();
0 commit comments