Skip to content

Commit 5f19a65

Browse files
authored
Output of PlantUML
1 parent 5f3770b commit 5f19a65

File tree

6 files changed

+198
-17
lines changed

6 files changed

+198
-17
lines changed

Association.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5806,9 +5806,11 @@ else if (card2 == ONE)
58065806
String opp = "";
58075807
if (role1 != null && role1.length() > 0)
58085808
{ opp = " oppositeOf " + role1; }
5809+
else if (initialExpression != null)
5810+
{ opp = " := " + initialExpression; }
58095811

5810-
if (isQualified())
5811-
{ return " reference " + role2 + mult + " qualified " + ord + agg + ": " + entity2 + opp + ";"; }
5812+
if (isQualified())
5813+
{ return " reference " + role2 + mult + " qualified " + ord + agg + ": " + entity2 + opp + ";"; }
58125814

58135815
return " reference " + role2 + mult + " " + ord + agg + ": " + entity2 + opp + ";";
58145816
}
@@ -5850,6 +5852,36 @@ else if (card2 == ZEROONE)
58505852
out.println(res + "/>");
58515853
} // ordering?
58525854

5855+
public void saveAsPlantUML(PrintWriter out)
5856+
{ String c1 = "";
5857+
5858+
if (card1 == ONE)
5859+
{ c1 = "1"; }
5860+
else if (card1 == ZEROONE)
5861+
{ c1 = "0..1"; }
5862+
else if (card1 == MANY)
5863+
{ c1 = "*"; }
5864+
5865+
String c2 = "";
5866+
5867+
if (card2 == ONE)
5868+
{ c2 = "1"; }
5869+
else if (card2 == ZEROONE)
5870+
{ c2 = "0..1"; }
5871+
else if (card2 == MANY)
5872+
{ c2 = "*"; }
5873+
5874+
String arrow = " --> ";
5875+
if (aggregation)
5876+
{ arrow = " *--> "; }
5877+
5878+
if (ordered)
5879+
{ c2 = c2 + " {ordered}"; }
5880+
5881+
String res = " " + entity1 + " \"" + c1 + "\"" + arrow + " \"" + c2 + "\" " + entity2 + " : " + role2;
5882+
out.println(res + "\n");
5883+
} // ordering?
5884+
58535885
public String xmiSaveModel(String domain)
58545886
{ String res = "";
58555887
String e1name = entity1.getName();

BasicExpression.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3631,10 +3631,27 @@ else if (objectRef.type != null &&
36313631
objectRef.type.isEntity(entities))
36323632
{ context.add(0,objectRef.type.getEntity(entities)); }
36333633
else
3634-
{ System.err.println("! Warning: Cannot locate class of " + objectRef);
3635-
/* JOptionPane.showMessageDialog(null,
3636-
"Warning!: Cannot locate class of " + objectRef,
3637-
"Semantic error", JOptionPane.ERROR_MESSAGE); */
3634+
{ System.out.println(">>> Searching for class of " + objectRef);
3635+
3636+
// Search for a class with data.
3637+
3638+
for (int i = 0; i < entities.size(); i++)
3639+
{ Entity ex = (Entity) entities.get(i);
3640+
if (ex.hasAttribute(data))
3641+
{ JOptionPane.showMessageDialog(null,
3642+
"Located possible class " + ex + " of " + objectRef,
3643+
"", JOptionPane.INFORMATION_MESSAGE);
3644+
objectRef.type = new Type(ex);
3645+
3646+
vartypes.put("" + objectRef, objectRef.type);
3647+
3648+
Attribute attx = ex.getAttribute(data);
3649+
type = attx.getType();
3650+
elementType = attx.getElementType();
3651+
3652+
vartypes.put(data, type);
3653+
}
3654+
}
36383655
}
36393656
}
36403657
else // objectRef == null

BehaviouralFeature.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5120,6 +5120,61 @@ public String saveAsUSEData()
51205120
return res;
51215121
} // multiple pre, post, and stereotypes
51225122

5123+
public String saveAsPlantUML()
5124+
{ if (derived) { return ""; }
5125+
5126+
String res = "";
5127+
5128+
if (instanceScope)
5129+
{ if (isAbstract())
5130+
{ res = res + "{abstract} "; }
5131+
}
5132+
else
5133+
{ res = res + "{static} "; }
5134+
5135+
res = res + getName() + "(";
5136+
5137+
for (int i = 0; i < parameters.size(); i++)
5138+
{ Attribute par = (Attribute) parameters.get(i);
5139+
String pnme = par.getName();
5140+
String tnme = par.getType().getUMLName();
5141+
String elemt = "";
5142+
if ("Set".equals(tnme) || "Sequence".equals(tnme))
5143+
{ if (par.getElementType() != null)
5144+
{ elemt = "(" + par.getElementType().getUMLName() + ")"; }
5145+
}
5146+
res = res + pnme + " : " + tnme + elemt;
5147+
if (i < parameters.size() - 1) { res = res + ", "; }
5148+
}
5149+
res = res + ") ";
5150+
5151+
if (resultType != null)
5152+
{ String rtname = resultType.getName();
5153+
if (rtname.equals("Set") || rtname.equals("Sequence"))
5154+
{ if (elementType != null)
5155+
{ res = res + " : " + resultType.getUMLName() + "(" + elementType.getUMLName() + ")"; }
5156+
else
5157+
{ res = res + " : " + resultType.getUMLName() + "()"; }
5158+
}
5159+
else
5160+
{ res = res + " : " + resultType.getUMLName(); }
5161+
}
5162+
res = res + "\n";
5163+
5164+
/* java.util.Map env = new java.util.HashMap();
5165+
5166+
if (pre == null)
5167+
{ pre = new BasicExpression("true"); }
5168+
5169+
if (post == null)
5170+
{ post = new BasicExpression("true"); }
5171+
5172+
res = res + "pre pre1:\n " + pre.toOcl(env,true) + "\n";
5173+
res = res + "post post1:\n " + post.toOcl(env,true);
5174+
res = res + "\n\n"; */
5175+
5176+
return res;
5177+
} // multiple pre, post, and stereotypes
51235178

51245179
public static Expression wpc(Expression pst, String op, String feat,
51255180
String val)

Entity.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11794,6 +11794,39 @@ public String saveAsUSEData()
1179411794
return res + "end\n\n";
1179511795
} // for each op, save name, type, parameters, pre, post
1179611796

11797+
public String saveAsPlantUML()
11798+
{ String nme = getName();
11799+
11800+
String inheritstring = "";
11801+
11802+
if (superclass != null)
11803+
{ inheritstring = superclass.getName() + " <|-- " + nme + "\n\n"; }
11804+
11805+
for (int i = 0; i < interfaces.size(); i++)
11806+
{ Entity intf = (Entity) interfaces.get(i);
11807+
11808+
inheritstring = inheritstring +
11809+
intf.getName() + " <|.. " + nme + "\n\n";
11810+
}
11811+
11812+
String res = inheritstring +
11813+
"class " + nme + " {\n";
11814+
11815+
for (int i = 0; i < attributes.size(); i++)
11816+
{ Attribute att = (Attribute) attributes.get(i);
11817+
String aname = att.getName();
11818+
Type t = att.getType();
11819+
res = res + aname + " : " + t.getUMLName() + "\n";
11820+
}
11821+
11822+
for (int i = 0; i < operations.size(); i++)
11823+
{ BehaviouralFeature op = (BehaviouralFeature) operations.get(i);
11824+
res = res + op.saveAsPlantUML();
11825+
}
11826+
11827+
return res + "}\n\n";
11828+
} // for each op, save name, type, parameters, pre, post
11829+
1179711830
public String saveAsZ3Data()
1179811831
{ String ename = getName();
1179911832
String res = "(declare-sort " + ename + ")\n";

UCDArea.java

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12880,7 +12880,7 @@ public void generateRESTWebService()
1288012880
out.close();
1288112881
}
1288212882
catch (IOException e)
12883-
{ System.out.println("!!! Error saving data"); }
12883+
{ System.err.println("!!! Error saving data"); }
1288412884

1288512885
for (int i = 0; i < useCases.size(); i++)
1288612886
{ Object obj = useCases.get(i);
@@ -12919,7 +12919,7 @@ public void generateSOAPWebService()
1291912919
out.close();
1292012920
}
1292112921
catch (IOException e)
12922-
{ System.out.println("Error saving data"); }
12922+
{ System.err.println("!! Error saving data"); }
1292312923
}
1292412924

1292512925

@@ -12963,7 +12963,7 @@ public void saveDataToFile()
1296312963
out.close();
1296412964
}
1296512965
catch (IOException e)
12966-
{ System.out.println("Error saving data"); }
12966+
{ System.err.println("!! Error saving data"); }
1296712967
}
1296812968
}
1296912969

@@ -13002,7 +13002,7 @@ public void saveDataToFile(String f)
1300213002
out.close();
1300313003
}
1300413004
catch (IOException e)
13005-
{ System.out.println("Error saving data"); }
13005+
{ System.err.println("!! Error saving data"); }
1300613006
}
1300713007

1300813008
public void saveEMFToFile()
@@ -13021,7 +13021,7 @@ public void saveEMFToFile()
1302113021
out.close();
1302213022
}
1302313023
catch (IOException e)
13024-
{ System.out.println("Error saving EMF"); }
13024+
{ System.err.println("!! Error saving EMF"); }
1302513025
}
1302613026
}
1302713027

@@ -13041,7 +13041,7 @@ public void saveKM3ToFile()
1304113041
out.close();
1304213042
}
1304313043
catch (IOException e)
13044-
{ System.out.println("Error saving KM3"); }
13044+
{ System.err.println("!! Error saving KM3"); }
1304513045
}
1304613046
}
1304713047

@@ -13061,7 +13061,7 @@ public void saveSimpleKM3ToFile()
1306113061
out.close();
1306213062
}
1306313063
catch (IOException e)
13064-
{ System.out.println("Error saving KM3"); }
13064+
{ System.err.println("!! Error saving KM3"); }
1306513065
}
1306613066
}
1306713067

@@ -13082,7 +13082,7 @@ public void saveEcoreToFile()
1308213082
out.close();
1308313083
}
1308413084
catch (IOException e)
13085-
{ System.out.println("Error saving Ecore"); }
13085+
{ System.err.println("!! Error saving Ecore"); }
1308613086
}
1308713087
}
1308813088

@@ -13104,7 +13104,7 @@ public void saveInterfaceDescription(String f)
1310413104
out.close();
1310513105
}
1310613106
catch (IOException e)
13107-
{ System.out.println("Error saving model"); }
13107+
{ System.err.println("!! Error saving model"); }
1310813108
}
1310913109

1311013110

@@ -13143,7 +13143,7 @@ else if (uc instanceof UseCase)
1314313143
out.close();
1314413144
}
1314513145
catch (IOException e)
13146-
{ System.out.println("Error saving model"); }
13146+
{ System.err.println("!! Error saving model"); }
1314713147
}
1314813148
}
1314913149

@@ -13176,7 +13176,43 @@ public void saveUSEDataToFile(String f)
1317613176
out.close();
1317713177
}
1317813178
catch (IOException e)
13179-
{ System.out.println("Error saving data"); }
13179+
{ System.err.println("!! Error saving data"); }
13180+
}
13181+
13182+
public void savePlantUMLToFile(String f)
13183+
{ File file = new File("output/" + f);
13184+
// Vector locals = new Vector();
13185+
13186+
try
13187+
{ PrintWriter out =
13188+
new PrintWriter(
13189+
new BufferedWriter(new FileWriter(file)));
13190+
out.println("@startuml");
13191+
13192+
for (int p = 0; p < entities.size(); p++)
13193+
{ Entity ent = (Entity) entities.get(p);
13194+
out.println(ent.saveAsPlantUML());
13195+
// locals.addAll(ent.getInvariants());
13196+
}
13197+
13198+
for (int i = 0; i < associations.size(); i++)
13199+
{ Association ast = (Association) associations.get(i);
13200+
ast.saveAsPlantUML(out);
13201+
}
13202+
13203+
/* if (locals.size() > 0)
13204+
{ out.println("constraints\n\n"); }
13205+
13206+
for (int q = 0; q < locals.size(); q++)
13207+
{ Constraint cc = (Constraint) locals.get(q);
13208+
out.println(cc.saveAsUSEData());
13209+
} */
13210+
13211+
out.println("@enduml");
13212+
out.close();
13213+
}
13214+
catch (IOException e)
13215+
{ System.err.println("!! Error saving data"); }
1318013216
}
1318113217

1318213218

UmlTool.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ public UmlTool()
459459
saveUSEMI.addActionListener(this);
460460
saveMenu.add(saveUSEMI);
461461

462+
JMenuItem saveplantMI = new JMenuItem("Save as PlantUML");
463+
saveplantMI.addActionListener(this);
464+
saveMenu.add(saveplantMI);
465+
462466

463467
JMenuItem saveCSVMI = new JMenuItem("Save as CSV");
464468
saveCSVMI.addActionListener(this);
@@ -1706,6 +1710,10 @@ else if (label.equals("Save as USE"))
17061710
{ ucdArea.saveUSEDataToFile("mm.use");
17071711
thisLabel.setText("Model saved to output/mm.use");
17081712
}
1713+
else if (label.equals("Save as PlantUML"))
1714+
{ ucdArea.savePlantUMLToFile("mm.plantuml");
1715+
thisLabel.setText("Model saved to output/mm.plantuml");
1716+
}
17091717
else if (label.equals("Save as CSV"))
17101718
{ ucdArea.saveCSV(); }
17111719
else if (label.equals("Map TL to CSTL"))

0 commit comments

Comments
 (0)