问题描述
在 Enterprise Architect 的序列图中,我将 Actor 和序列作为生命线。
。这个图也有一个片段。我试图通过 java API 获取图表对象。
我能够从 API 获取所有 Actor、序列和片段信息。但我无法区分其中哪些是生命线。
有没有办法通过 API 或 EA 数据库来区分 Lifelines 和其他元素?
我使用的代码片段如下 . .
Diagram sequenceDiagram = rep.GetDiagramByGuid(seqdiagGuid);
Collection<DiagramObject> diagObjs = sequenceDiagram.GetDiagramObjects();
for (DiagramObject obj : diagObjs) {
Element el = rep.GetElementByID(obj.GetElementID());
// How to differenciate whether this el is a lifeline?
}
编辑了更多信息和屏幕截图,以提供更多清晰度
我从工具箱中删除了一个类。复制时,我选择了“生命线”选项。对于这个新添加的类,我希望 el.type 会给出“LifeLine”的值,但不幸的是它只给出了“Object”。现在我的问题是如何将这个对象识别为 Class 类型的 Lifeline?
希望这能让你更清楚。
解决方法
如果您将一个类放到序列图中作为生命线,您将有效地获得一个 Object 类型的元素,即您的类的一个实例。
使用 ClassifierID
可以得到 Classifier 元素
所以从你的样品开始
Diagram sequenceDiagram = rep.GetDiagramByGuid(seqdiagGuid);
Collection<DiagramObject> diagObjs = sequenceDiagram.GetDiagramObjects();
for (DiagramObject obj : diagObjs) {
Element el = rep.GetElementByID(obj.GetElementID());
// How to differenciate whether this el is a lifeline?
String elementType = el.GetType(); //this will be "Object" if you drop a class as a lifeline,and "Sequence" if you choose a lifeline from the toolbox
if (el.GetClassifierID > 0) {
Element classifier = rep.GetElementByID(el.GetClassifierID);
}
}