我在Enterprise Architect中的模型中定义了许多用例图。这些图表在层次结构中处于不同的级别。无论关系图位于何处,是否有任何方法可以使用Enterprise Architect Java API访问模型中的所有用例关系图(任何关系图(?
Java API只不过是普通API的一层,所以我一般都会回答。
当然,您可以在代码中遍历整个模型来获得图表,但这在任何非平凡的模型中都需要很长时间。
所以你想做的是
- 使用
EA.Repository.SQLQuery()
查询模型以获取所有图guid - 循环图guid并使用
EA.Repository.GetDiagramByGUID()
获取每个图
SQL查询
获取所有用例图guid所需的SQL查询如下
select d.ea_guid from t_diagram d
where d.Diagram_Type = 'Use Case'
从查询中获取值列表
EA.Repository.SQLQuery()
返回一个XML字符串,因此需要对其进行解析以获得一个值列表。这个例子是VBScript中的一个操作,它正是这样做的:
function getArrayFromQuery(sqlQuery)
dim xmlResult
xmlResult = Repository.SQLQuery(sqlQuery)
getArrayFromQuery = convertQueryResultToArray(xmlResult)
end function
'converts the query results from Repository.SQLQuery from xml format to a two dimensional array of strings
Public Function convertQueryResultToArray(xmlQueryResult)
Dim arrayCreated
Dim i
i = 0
Dim j
j = 0
Dim result()
Dim xDoc
Set xDoc = CreateObject( "MSXML2.DOMDocument" )
'load the resultset in the xml document
If xDoc.LoadXML(xmlQueryResult) Then
'select the rows
Dim rowList
Set rowList = xDoc.SelectNodes("//Row")
Dim rowNode
Dim fieldNode
arrayCreated = False
'loop rows and find fields
For Each rowNode In rowList
j = 0
If (rowNode.HasChildNodes) Then
'redim array (only once)
If Not arrayCreated Then
ReDim result(rowList.Length, rowNode.ChildNodes.Length)
arrayCreated = True
End If
For Each fieldNode In rowNode.ChildNodes
'write f
result(i, j) = fieldNode.Text
j = j + 1
Next
End If
i = i + 1
Next
'make sure the array has a dimension even is we don't have any results
if not arrayCreated then
ReDim result(0, 0)
end if
end if
convertQueryResultToArray = result
End Function
基于guid获取关系图
循环生成的查询并使用Repository.GetDiagramByGUID()
在VBScript中,它可能是这样的(假设查询结果存储在变量guidResults
中(
dim diagram as EA.Diagram
dim diagrams
set diagrams = CreateObject("System.Collections.Arraylist")
dim guid
for each guid in guidResults
set diagram = Repository.GetDiagramByGuid(guid)
diagrams.Add diagram
next