Prev | Next |
Schema Composer Scripting Integration
Although the Schema Composer provides out-of-the-box schema composition based on a variety of popular technologies, its scripting integration provides you with some flexibility in how you might go about implementing your own requirements. There are three ways in which you might leverage scripting within the Schema Composer:
- Provide custom schema generation using a scripting language
- Provide custom model transformation using a scripting language
- Provide custom stereotype mapping to any standard model transform (such as UPCC)
Model Transformation by script
While the Schema Composer provides in-built transforms for various frameworks, you can always write your own, using the composition tools of the Composer to design the schema, then performing a custom transform with a hand crafted script.
Schema Generation by script
When you select a message in the Schema Composer and click generate, you are presented with a number of export formats. One of those choices is 'Execute custom script'
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: 2019
*/
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();
Intelli-sense help in scripting
The Scripting editor in Enterprise Architect will help you write script that interacts with the Schema Composer, by providing Intelli-sense on the properties and methods of its Automation Interface.
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.
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;
}