如何在Sparx EA中修改ad-hoc Stereotype的名称

时间:2015-11-06 20:30:26

标签: uml enterprise-architect stereotype

我有一些" ad-hoc" Sparx EA模型中的刻板印象。也就是说,我只是在元素属性中键入了一个构造型名称,然后在其应用的其他元素中使用相同的名称...而不使用配置文件。

然后每个都出现在Project --> Settings --> UML Types --> Stereotypes

最后,我添加了Shape Script图标等。

但是,我用一个刻板印象名称造成了一些混淆。我使用" Tablespace"作为一个设计概念来表示"一组相关的数据库表"。由于"表空间"的物理概念,我们的数据库团队发现这令人困惑。在Oracle中。

所以,我想重命名。

如果我从UML Types --> Stereotypes执行此操作,则所有现有元素都保留原始名称(例如,表空间)并恢复其Shape Script-less外观。如果我访问元素并更改为新名称,则会出现形状脚本等。

我并不热衷于找到具有刻板印象的每个元素并手动应用新名称。

是时候学习EA Scripting了还是有其他方式?

3 个答案:

答案 0 :(得分:3)

您唯一的逃脱是使用自动化(或本机数据库访问)。如果您的构造型仅用于对象,则可以迭代

的结果

Repository.SQLQuery("SELECT object_id FROM t_object WHERE stereotype='oldStereo'")

获取所有对象ID。那你需要

elem = Repository.GetElementByID(theId)

检索单个元素。最后,您可以使用

更改构造型
elem.stereotype = "newStereo"
elem.update()

您还可以使用

运行直接SQL
Repository.Execute("UPDATE t_object SET stereotype='new' WHERE stereotype='old'")

请注意,后者使用了一种官方不支持的地雷功能。

编辑:您还可以在本机RDBMS客​​户端中运行最后一个SQL。使用EAP时,您可能需要暂时将其重命名为.mdb,以假装它是MS Access数据库(实际上是它)。

答案 1 :(得分:2)

您可以使用此VBScript重命名EA中的构造型。

它已在.eap文件上进行了测试,由于MS Access SQL语法中缺少replace(),因此这很复杂。

只需转到Scripting视图,添加新的VBScript并将此代码粘贴到新脚本中。然后修改它以指示from和to-stereotypes。

option explicit

!INC Local Scripts.EAConstants-VBScript

'
' Script Name: Rename Stereotypes
' Author: Geert Bellekens
' Purpose: Rename stereotypes on all types of elements 
' Environment: Tested on .eap file.
' Date: 13/10/2015
'
sub main
    renameElementStereotypes "FromStereo", "ToStereo"
    renameAttributeStereotypes "FromStereo", "ToStereo"
    renameConnectorStereotypes "FromStereo", "ToStereo"
    renameOperationStereotypes "FromStereo", "ToStereo"
    renameDiagramStereotypes "FromStereo", "ToStereo"
    Repository.RefreshModelView(0)
    msgbox "Finished renaming stereotypes"
end sub

sub renameElementStereotypes(fromStereo, toStereo)
    renameStereotypes "t_object", fromStereo, toStereo
end sub
sub renameAttributeStereotypes(fromStereo, toStereo)
    renameStereotypes "t_attribute", fromStereo, toStereo
end sub
sub renameConnectorStereotypes(fromStereo, toStereo)
    renameStereotypes "t_connector", fromStereo, toStereo
end sub
sub renameOperationStereotypes(fromStereo, toStereo)
    renameStereotypes "t_operation", fromStereo, toStereo
end sub
sub renameDiagramStereotypes(fromStereo, toStereo)
    renameStereotypes "t_diagram", fromStereo, toStereo
end sub

sub renameStereotypes (baseTable, fromStereo, toStereo)
    dim updateSQL
    'first the second part of of t_xref description
    updateSQL = "update (" & baseTable & " o inner join t_xref x on o.[ea_guid] = x.[Client]) "&_
               " set x.Description = MID( x.Description, 1, INSTR(  x.Description, ':" & fromStereo & "') - 1) "&_
                         " + ':" & toStereo & "' "&_
                         " + MID(x.Description,INSTR(  x.Description, ':" & fromStereo & "') "&_ 
                              " + LEN(':" & fromStereo & "'), LEN(x.Description)  "&_
                              " - INSTR(  x.Description, ':" & fromStereo & "') "&_
                              " - LEN(':" & fromStereo & "')+ 1) "&_
               " where o.Stereotype = '" & fromStereo & "' "&_
               "  and x.Name = 'Stereotypes' "&_
               " and INSTR(  x.Description, ':" & fromStereo & "') > 0  "              
    Repository.Execute updateSQL
    'then the first part of t_xref description
    updateSQL = "update (" & baseTable & " o inner join t_xref x on o.[ea_guid] = x.[Client]) "&_
               " set x.Description = MID( x.Description, 1, INSTR(  x.Description, '=" & fromStereo & "') - 1) "&_
                         " + '=" & toStereo & "' "&_
                         " + MID(x.Description,INSTR(  x.Description, '=" & fromStereo & "') "&_ 
                              " + LEN('=" & fromStereo & "'), LEN(x.Description)  "&_
                              " - INSTR(  x.Description, '=" & fromStereo & "') "&_
                              " - LEN('=" & fromStereo & "')+ 1) "&_
               " where o.Stereotype = '" & fromStereo & "' "&_
               "  and x.Name = 'Stereotypes' "&_               
               " and INSTR(  x.Description, '=" & fromStereo & "') > 0  "
    Repository.Execute updateSQL                
    'then the stereotype itself
    updateSQL = " update " & baseTable & " o "&_
                " set o.[Stereotype] = '" & toStereo & "' "&_
                " where o.Stereotype = '" & fromStereo & "' "
    Repository.Execute updateSQL
end sub

main

答案 2 :(得分:1)

这是我创建的剧本,基于@Thomas Killian的答案。

改进:

  1. 使用EAScriptLib数据库函数获取结果。
  2. 关于Update()方法的正确案例(但似乎并不重要)
  3. 还在Object / Element上设置StereotypeEx属性。 这似乎很关键......否则,要么忽略更改,要么将新的构造型简单地添加到对象的构造型列表中
  4. 此外,不确定它有多重要,但在最终测试期间运行脚本之前没有通过项目浏览器打开组件。这感觉就像伏都教。

    !INC Local Scripts.EAConstants-JScript
    !INC EAScriptLib.JScript-Database
    
    function RenameStereotypes()
    {
        Repository.EnsureOutputVisible( "Script" );
    
        var objectIDs = DBGetFieldValueArrayString( "object_id" /* : String */, "t_object" /* : String */,  "stereotype='DBTables'" /* : String */ ); /* : Array */
    
        Session.Output( objectIDs );
    
        for ( var i = 0; i < objectIDs.length; i++ ) {
            var theId = objectIDs[i];
            var elem = Repository.GetElementByID(theId);
            Session.Output( "Id: " + theId + " Name: " + elem.name + " Stereotype: " + elem.stereotype );
            elem.stereotype = "DBTables";    /* FIRST VISIBLE STEREOTYPE */
            elem.stereotypeEx = "DBTables";  /* CRITICAL - DEEPER LIST OF STEREOTYPES */
            elem.Update();  /* CASE CHANGED, NOT SURE IT MATTERS */
            elem.Refresh(); /* JUST IN CASE */
        }
    }
    
    RenameStereotypes();