预订演示
前页 后页

Schema 编辑器脚本集成

尽管Schema 编辑器提供了基于各种流行技术的开箱即用的模式组合,但它的脚本集成为您提供了一些灵活性,让您可以实现自己的需求。您可以通过三种方式在Schema 编辑器中利用脚本:

  • 使用脚本语言提供自定义模式生成
  • 使用脚本语言提供自定义模型转换
  • 提供自定义原型映射到任何标准模型转换(例如 UPCC)

脚本模型变换

虽然Schema 编辑器为各种框架提供内置转换,但您始终可以编写自己的转换,使用 Composer 的组合工具设计模式,然后使用手工制作的脚本执行自定义转换。

架构脚本生成

当您在Schema 编辑器中选择一条消息并单击生成时,您会看到多种导出格式。这些选择之一是“执行自定义脚本”

Schema Iteration Scripting Example

This example demonstrates accessing the Schema Composer in an Enterprise Architect script written in JavaScript. The script first obtains an interface to the Schema Composer and then traverses the schema, printing out the types and each of its properties.

/*

* Script Name: Example Schema Composer Script

* Author:  Sparx Systems

* Purpose: Demonstrate access to Schema Composer using automation and JavaScript

* Language: JavaScript

* Date:  2020

*/

function printType( xmlType, xmlns, uri)

{

var xmlProp as EA.SchemaProperty;

var xmlPropEnum as EA.SchemaPropEnum;

var xmlChoiceEnum1 as EA.SchemaTypeEnum;

var xmlChoiceEnum2 as EA.SchemaTypeEnum;

Session.Output("Type: " + xmlType.TypeName + " in namespace: "  + xmlns + ":" + uri);

xmlPropEnum = xmlType.Properties;

if(xmlPropEnum)

{

xmlProp = xmlPropEnum.GetFirst();

while(xmlProp)

{

if(xmlType.IsEnumeration())

{

Session.Output("   " + xmlProp.Name);

}

else

{

var sPropDesc = xmlProp.Name;

sPropDesc += "::"

if(xmlProp.IsPrimitive())

sPropDesc += xmlProp.PrimitiveType;

else

sPropDesc += xmlProp.TypeName;

if(xmlProp.IsByReference())

{

sPropDesc += "(by reference)";

}

if(xmlProp.IsInline())

{

sPropDesc += "(inline)";

}

Session.Output("   " + sPropDesc + ", cardinality: " + xmlProp.Cardinality);

xmlChoiceEnum1 = xmlProp.Choices;

xmlChoiceEnum2 = xmlProp.SchemaChoices;

var count = xmlChoiceEnum1.GetCount() + xmlChoiceEnum2.GetCount();

if(count>1)

{

Session.Output("   choice of: ");

xmlChoice = xmlChoiceEnum1.GetFirst();

while(xmlChoice)

{

Session.Output("     " + xmlChoice.TypeName);

xmlChoice = xmlChoiceEnum1.GetNext();

}

xmlChoice = xmlChoiceEnum2.GetFirst();

while(xmlChoice)

{

Session.Output("     " + xmlChoice.TypeName);

xmlChoice = xmlChoiceEnum2.GetNext();

}

}

}

xmlProp = xmlPropEnum.GetNext();

}

}

}

function main()

{

var schema as EA.SchemaComposer;

var xmlType as EA.SchemaType;

var xmlTypeEnum as EA.SchemaTypeEnum;

var xmlNamespaceEnum as EA.SchemaNamespaceEnum;

var xmlNS as EA.SchemaNamespace;

// Get SchemaComposer

schema = Repository.SchemaComposer;

// print the namespace references

xmlNamespaceEnum = schema.Namespaces;

if(xmlNamespaceEnum)

{

xmlNS = xmlNamespaceEnum.GetFirst();

while(xmlNS)

{

Session.Output( "xmlns:" + xmlNS.Name + " URI=" + xmlNS.URI);

xmlNS = xmlNamespaceEnum.GetNext();

}

}

// Get Schema Types Enumerator

xmlTypeEnum = schema.SchemaTypes;

xmlType = xmlTypeEnum.GetFirst();

while(xmlType)

{

var xmlns = schema.GetNamespacePrefixForType( xmlType.TypeID );

uri = schema.GetNamespaceForPrefix(xmlns);

printType(xmlType, xmlns, uri);

xmlType = xmlTypeEnum.GetNext();

}

}

main();

智能感知帮助脚本

编辑Enterprise Architect脚本帮助您使用Schema 编辑器属性编写脚本,方法是在智能感知脚本中提供编辑脚本或其自动化接口的交互和方法。

Intellisense is presented when using Schema Composer automation interfaces in scripts

Stereotype mapping in Model Transformation

Stereotyping forms a large part of the MDG Technology approach. Individual UML profiles for an MDG Technology define stereotypes to offer useful classifications for its elements. It is a common requirement when going from a core framework to a business model or sub-domain to reassign the stereotype. When you work with a CCTS framework the business components you generate have their stereotype automatically generated by Enterprise Architect according to a mapping defined by the CCTS specification (ACC to ABIE, for example).

When you open or create a model transform profile in the Schema Composer you can specify a script to perform this mapping for you. The script can be selected from the Properties window.

Why not write a script to customized tjhose elements produced during the transform operation

The script can be written in either JavaScript, JScript or VBScript, and only has to implement this function (described here in JavaScript notation):

function TranslateStereotype(srcStereo)

{

     var destStereo = srcStereo

     if (srcStereo == "BDT")

     {

          destStereo = "My_BDT"

     }

     return destStereo;

}

了解更多