0

我在 Enterprise Architect 的模型中定义了许多用例图。这些图表位于层次结构中的不同级别。无论图表位于何处,是否有任何方法可以使用 Enterprise Architect Java API 访问模型中存在的所有用例图表(任何图表)?

4

1 回答 1

1

Java API 只不过是围绕常规 API 的一层,所以我一般都在回答。

您当然可以在代码中遍历整个模型以获取图表,但这在任何非平凡模型中都需要很长时间。

所以你想做的是

  1. 查询模型以获取所有图表 guid 的使用EA.Repository.SQLQuery()
  2. 循环图表 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
于 2020-11-19T05:46:43.127 回答