【问题标题】:Is there a way to fetch all the use case diagrams from an enterprise architect model using Java API?有没有办法使用 Java API 从企业架构模型中获取所有用例图?
【发布时间】:2020-11-19 13:46:43
【问题描述】:

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

【问题讨论】:

    标签: enterprise-architect


    【解决方案1】:

    Java API 只不过是围绕常规 API 的一层,所以我是笼统地回答。

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

    所以你想做的是

    1. 使用EA.Repository.SQLQuery()查询模型以获取所有图表guid
    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
    

    【讨论】:

      猜你喜欢
      • 2018-04-12
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-12
      • 2015-07-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多