Skip to content

Commit b7a7d20

Browse files
authored
Latest updates and manual
1 parent 0476fd5 commit b7a7d20

14 files changed

+2591
-351
lines changed

Attribute.java

Lines changed: 274 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -897,9 +897,9 @@ public boolean isPrimaryAttribute()
897897
public void setFrozen(boolean fr)
898898
{ frozen = fr;
899899
if (fr)
900-
{ addStereotype("readOnly"); }
901-
else
902-
{ removeStereotype("readOnly"); }
900+
{ addStereotype("readOnly"); }
901+
else
902+
{ removeStereotype("readOnly"); }
903903
}
904904

905905
public boolean isInteger()
@@ -938,6 +938,9 @@ public void setStatic(boolean stat)
938938
public boolean isStatic()
939939
{ return instanceScope == false; }
940940

941+
public boolean isDerived()
942+
{ return kind == ModelElement.DERIVED; }
943+
941944
public void setVisibility(int visib)
942945
{ visibility = visib; }
943946

@@ -3512,8 +3515,17 @@ public String getHtmlGen()
35123515

35133516
public String getFormInput()
35143517
{ String nme = getName();
3518+
String label = nme;
3519+
3520+
if (type != null && type.isEntity())
3521+
{ Entity etype = type.getEntity();
3522+
Attribute pk = etype.getPrincipalPrimaryKey();
3523+
if (pk != null)
3524+
{ label = nme + " (" + pk.getName() + ")"; }
3525+
}
3526+
35153527
String res =
3516-
"<p><strong>" + nme + "</strong>\n" +
3528+
"<p><strong>" + label + "</strong>\n" +
35173529
"<input type = \"text\" name = \"" + nme + "\"/></p>\n";
35183530
return res;
35193531
}
@@ -3568,6 +3580,32 @@ else if (tname.equals("double"))
35683580
attname + " + \" is not a double\"); }\n";
35693581
return res;
35703582
}
3583+
else if (type.isEnumerated())
3584+
{ String eatt = "e" + attname;
3585+
Vector vals = type.getValues();
3586+
3587+
for (int i = 0; i < vals.size(); i++)
3588+
{ String val = (String) vals.get(i);
3589+
3590+
res = res + " if (" + attname + ".equals(\"" + val + "\"))\n" +
3591+
" { " + eatt + " = " + tname + "." + val + "; } else\n";
3592+
}
3593+
res = res + " { errorPage.addMessage(\"" + attname + " is not in type " + type + "\"); }\n";
3594+
}
3595+
else if (type.isEntity())
3596+
{ res = res +
3597+
" instance_" + attname + " = model.get" + tname + "ByPK(" + attname + ");\n" +
3598+
" if (instance_" + attname + " == null)\n" +
3599+
" { errorPage.addMessage(\"" + attname + " must be a valid " + tname + " id\"); }\n";
3600+
}
3601+
else if (type.isCollection())
3602+
{ res = res +
3603+
" String[] split_" + attname + " = " + attname + ".split(\" \");\n" +
3604+
" for (int _i = 0; _i < split_" + attname + ".length; _i++)\n" +
3605+
" { s" + attname + ".add(split_" + attname + "[_i]); }\n" +
3606+
" if (s" + attname + ".size() == 0)\n" +
3607+
" { errorPage.addMessage(\"" + attname + " must have one or more values\"); }\n";
3608+
}
35713609
// enumerations
35723610

35733611
if (hasStereotype("email"))
@@ -4497,7 +4535,8 @@ else if (Type.isSubType(typetatt,type,mm,entities))
44974535
return Type.typeSimilarity(type,typetatt,mm,entities);
44984536
} // int does not match to enum, but boolean can match to an enum of size 2
44994537

4500-
public Vector testCases(String x)
4538+
4539+
public Vector testCases(String x, java.util.Map lowerBnds, java.util.Map upperBnds)
45014540
{ Vector res = new Vector();
45024541
if (type == null)
45034542
{ return res; }
@@ -4506,26 +4545,106 @@ public Vector testCases(String x)
45064545
String t = type.getName();
45074546
Vector vs = type.getValues();
45084547

4548+
String nmx = getName();
4549+
Expression lbnd = (Expression) lowerBnds.get(nmx);
4550+
Expression ubnd = (Expression) upperBnds.get(nmx);
4551+
45094552
if ("int".equals(t))
45104553
{ res.add(nme + " = 0");
45114554
res.add(nme + " = -1");
45124555
res.add(nme + " = 1");
4513-
res.add(nme + " = 2147483647"); // Integer.MAX_VALUE);
4514-
res.add(nme + " = -2147483648"); // Integer.MIN_VALUE);
4556+
4557+
if (ubnd != null && lbnd != null)
4558+
{ try
4559+
{ double ud = Double.parseDouble(ubnd + "");
4560+
double ld = Double.parseDouble(lbnd + "");
4561+
int midd = (int) Math.floor((ud + ld)/2);
4562+
res.add(nme + " = " + midd);
4563+
} catch (Exception _e) { }
4564+
}
4565+
4566+
if (ubnd != null)
4567+
{ String upperval = ubnd + "";
4568+
if ("0".equals(upperval) || "1".equals(upperval) || "-1".equals(upperval)) { }
4569+
else
4570+
{ res.add(nme + " = " + upperval); }
4571+
}
4572+
else
4573+
{ res.add(nme + " = 2147483647"); } // Integer.MAX_VALUE);
4574+
4575+
if (lbnd != null)
4576+
{ String lowerval = lbnd + "";
4577+
if ("0".equals(lowerval) || "1".equals(lowerval) || "-1".equals(lowerval)) { }
4578+
else
4579+
{ res.add(nme + " = " + lowerval); }
4580+
}
4581+
else
4582+
{ res.add(nme + " = -2147483648"); } // Integer.MIN_VALUE);
45154583
}
45164584
else if ("long".equals(t))
45174585
{ res.add(nme + " = 0");
45184586
res.add(nme + " = -1");
45194587
res.add(nme + " = 1");
4520-
res.add(nme + " = " + Long.MAX_VALUE);
4521-
res.add(nme + " = " + Long.MIN_VALUE);
4588+
4589+
if (ubnd != null && lbnd != null)
4590+
{ try
4591+
{ double ud = Double.parseDouble(ubnd + "");
4592+
double ld = Double.parseDouble(lbnd + "");
4593+
long midd = (long) Math.floor((ud + ld)/2);
4594+
res.add(nme + " = " + midd);
4595+
} catch (Exception _e) { }
4596+
}
4597+
4598+
if (ubnd != null)
4599+
{ String upperval = ubnd + "";
4600+
if ("0".equals(upperval) || "1".equals(upperval) || "-1".equals(upperval)) { }
4601+
else
4602+
{ res.add(nme + " = " + upperval); }
4603+
}
4604+
else
4605+
{ res.add(nme + " = " + Long.MAX_VALUE); }
4606+
4607+
if (lbnd != null)
4608+
{ String lowerval = lbnd + "";
4609+
if ("0".equals(lowerval) || "1".equals(lowerval) || "-1".equals(lowerval)) { }
4610+
else
4611+
{ res.add(nme + " = " + lowerval); }
4612+
}
4613+
else
4614+
{ res.add(nme + " = " + Long.MIN_VALUE); }
45224615
}
45234616
else if ("double".equals(t))
45244617
{ res.add(nme + " = 0");
45254618
res.add(nme + " = -1");
45264619
res.add(nme + " = 1");
4527-
res.add(nme + " = " + Double.MAX_VALUE);
4528-
res.add(nme + " = " + Double.MIN_VALUE);
4620+
4621+
if (ubnd != null && lbnd != null)
4622+
{ try
4623+
{ double ud = Double.parseDouble(ubnd + "");
4624+
double ld = Double.parseDouble(lbnd + "");
4625+
double midd = (ud + ld)/2;
4626+
res.add(nme + " = " + midd);
4627+
} catch (Exception _e) { }
4628+
}
4629+
4630+
if (ubnd != null)
4631+
{ String upperval = ubnd + "";
4632+
if ("0".equals(upperval) || "1".equals(upperval) || "-1".equals(upperval)) { }
4633+
else
4634+
{ res.add(nme + " = " + upperval); }
4635+
}
4636+
else
4637+
{ res.add(nme + " = " + Double.MAX_VALUE); }
4638+
4639+
if (lbnd != null)
4640+
{ String lowerval = lbnd + "";
4641+
if ("0".equals(lowerval) || "1".equals(lowerval) || "-1".equals(lowerval)) { }
4642+
else
4643+
{ res.add(nme + " = " + lowerval); }
4644+
}
4645+
else
4646+
{ res.add(nme + " = " + Double.MIN_VALUE); }
4647+
45294648
}
45304649
else if ("boolean".equals(t))
45314650
{ res.add(nme + " = true");
@@ -4561,6 +4680,150 @@ else if (type.isCollection() && elementType != null)
45614680
return res;
45624681
}
45634682

4683+
public Vector testValues(String x, java.util.Map lowerBnds, java.util.Map upperBnds)
4684+
{ Vector res = new Vector();
4685+
if (type == null)
4686+
{ return res; }
4687+
4688+
String nme = x + "." + getName();
4689+
String t = type.getName();
4690+
Vector vs = type.getValues();
4691+
4692+
String nmx = getName();
4693+
Expression lbnd = (Expression) lowerBnds.get(nmx);
4694+
Expression ubnd = (Expression) upperBnds.get(nmx);
4695+
4696+
if ("int".equals(t))
4697+
{ res.add("0");
4698+
res.add("-1");
4699+
res.add("1");
4700+
4701+
if (ubnd != null && lbnd != null)
4702+
{ try
4703+
{ double ud = Double.parseDouble(ubnd + "");
4704+
double ld = Double.parseDouble(lbnd + "");
4705+
int midd = (int) Math.floor((ud + ld)/2);
4706+
res.add("" + midd);
4707+
} catch (Exception _e) { }
4708+
}
4709+
4710+
if (ubnd != null)
4711+
{ String upperval = ubnd + "";
4712+
if ("0".equals(upperval) || "1".equals(upperval) || "-1".equals(upperval)) { }
4713+
else
4714+
{ res.add(upperval); }
4715+
}
4716+
else
4717+
{ res.add("2147483647"); } // Integer.MAX_VALUE);
4718+
4719+
if (lbnd != null)
4720+
{ String lowerval = lbnd + "";
4721+
if ("0".equals(lowerval) || "1".equals(lowerval) || "-1".equals(lowerval)) { }
4722+
else
4723+
{ res.add(lowerval); }
4724+
}
4725+
else
4726+
{ res.add("-2147483648"); } // Integer.MIN_VALUE);
4727+
}
4728+
else if ("long".equals(t))
4729+
{ res.add("0");
4730+
res.add("-1");
4731+
res.add("1");
4732+
4733+
if (ubnd != null && lbnd != null)
4734+
{ try
4735+
{ double ud = Double.parseDouble(ubnd + "");
4736+
double ld = Double.parseDouble(lbnd + "");
4737+
long midd = (long) Math.floor((ud + ld)/2);
4738+
res.add("" + midd);
4739+
} catch (Exception _e) { }
4740+
}
4741+
4742+
if (ubnd != null)
4743+
{ String upperval = ubnd + "";
4744+
if ("0".equals(upperval) || "1".equals(upperval) || "-1".equals(upperval)) { }
4745+
else
4746+
{ res.add(upperval); }
4747+
}
4748+
else
4749+
{ res.add(Long.MAX_VALUE + "L"); }
4750+
4751+
if (lbnd != null)
4752+
{ String lowerval = lbnd + "";
4753+
if ("0".equals(lowerval) || "1".equals(lowerval) || "-1".equals(lowerval)) { }
4754+
else
4755+
{ res.add(lowerval); }
4756+
}
4757+
else
4758+
{ res.add(Long.MIN_VALUE + "L"); }
4759+
}
4760+
else if ("double".equals(t))
4761+
{ res.add("0");
4762+
res.add("-1");
4763+
res.add("1");
4764+
4765+
if (ubnd != null && lbnd != null)
4766+
{ try
4767+
{ double ud = Double.parseDouble(ubnd + "");
4768+
double ld = Double.parseDouble(lbnd + "");
4769+
double midd = (ud + ld)/2;
4770+
res.add("" + midd);
4771+
} catch (Exception _e) { }
4772+
}
4773+
4774+
if (ubnd != null)
4775+
{ String upperval = ubnd + "";
4776+
if ("0".equals(upperval) || "1".equals(upperval) || "-1".equals(upperval)) { }
4777+
else
4778+
{ res.add(upperval); }
4779+
}
4780+
else
4781+
{ res.add("" + Double.MAX_VALUE); }
4782+
4783+
if (lbnd != null)
4784+
{ String lowerval = lbnd + "";
4785+
if ("0".equals(lowerval) || "1".equals(lowerval) || "-1".equals(lowerval)) { }
4786+
else
4787+
{ res.add(lowerval); }
4788+
}
4789+
else
4790+
{ res.add("" + Double.MIN_VALUE); }
4791+
4792+
}
4793+
else if ("boolean".equals(t))
4794+
{ res.add("true");
4795+
res.add("false");
4796+
}
4797+
else if ("String".equals(t))
4798+
{ res.add("\"\"");
4799+
res.add("\" abc_XZ \"");
4800+
res.add("\"#�$* &~@':\"");
4801+
}
4802+
else if (vs != null && vs.size() > 0)
4803+
{ for (int j = 0; j < vs.size(); j++)
4804+
{ String v0 = (String) vs.get(j);
4805+
res.add(v0);
4806+
}
4807+
}
4808+
else if (type.isEntity())
4809+
{ String obj = t.toLowerCase() + "x_0";
4810+
// Identifier.nextIdentifier(t.toLowerCase());
4811+
String decl = obj;
4812+
res.add(decl);
4813+
}
4814+
/* else if (type.isCollection() && elementType != null)
4815+
{ Type elemT = getElementType();
4816+
Vector testVals = elemT.testValues();
4817+
res.add("");
4818+
for (int p = 0; p < testVals.size(); p++)
4819+
{ String tv = (String) testVals.get(p);
4820+
res.add(tv + " : " + nme);
4821+
}
4822+
} */
4823+
4824+
return res;
4825+
}
4826+
45644827
public String androidEntryField(String op, String previous, String ent)
45654828
{ String nme = getName();
45664829
String label = Named.capitalise(nme);

0 commit comments

Comments
 (0)