Enterprise Architecture, Information Architecture, Sparx EA

Extending Sparx EA Schema Composer

Written by Rodrigo Nascimento · 3 min read >
Extending Sparx EA Schema Composer

In my previous post, I presented an overview of the new Sparx EA Schema Composer. I have also highlighted few points for discussion. Well… I believe that I will cover all of them in this article.

Sparx EA extensions

If you have used Sparx EA for a while, you probably know that you of the main benefits of this tool is its extensibility capabilities. Its automation interface allows us to extend functionalities by using Scripts or Add-Ins.

Add-in? Script?

This is a topic that I will not discuss here, but I will point you to one of the main authorities in this area, Mr Bellekens. You will find a lot of interesting articles in his website, but these are the most relevant to my discussion here:

Schema Composer Add-in Sample Code

Sparx EA comes with a sample code to create an Add-In for Schema Composer. It is located under the Code Samples directory of your Sparx EA install (i.e. C:\Program Files (x86)\Sparx Systems\EA\Code Samples\SchemaComposer).

Unfortunately, I couldn’t find a decent documentation about the Schema Composer (well… new beta version 12.1 has some now: http://goo.gl/ezGQoP), but it wasn’t that hard to figure out how it works after some debugging exercise.

The example code does not contain the generation any of the formats provided by the standard Schema Sets (CIM, NIEM, Generic…), but it generates a text file with a structure that aims to explain how the Schema Composer works.

What I have done so far…

As I have mentioned in my previous post (…), I had two main issues that were preventing me to generate physical XSD files for my service contracts:

  • Inconsistencies with UML XSD profile – The Schema Composer (at the date of publishing this post) does not recognise all the element types defined in the UML profile for XSD. Apparently, the Schema Composer does not check the class stereotypes defined in the UML profile for XSD. I’ve posted something about this issue in the Sparx EA forum, and you can see it following this link: http://goo.gl/RQbyMd
  • Namespace prefix – For some reason, you can define the schema namespace, but you can’t define the prefix for it (by default, the Schema Composer defines the prefix as ‘m’).

Apart from the issues listed above, I also had some other formatting requirements that I usually get from clients (i.e. use venetian blind as the XSD style, custom validations…), so I have used the add-in sample code for schema composer as a starting point to generate the XSD files the way I wanted.

Below are the main changes that I’ve done to the Sample Code in order to get my customisations to work.

1. Setting the Display Name for the Schema Set

As described in the new v12.1 (beta) guide, the EA_IsSchemaExporter function must be implemented by the Addin in order to be listed in the Schema Composer. So I’ve changed the ‘displayName’ to my model’s name:

public bool EA_IsSchemaExporter(EA.Repository Repository, ref string displayName) 
{ 
   displayName = "Rod Canonical Model"; 
   return true; 
}

If I go to the Schema Composer and create a new Schema Definition, I will be able to see my Add-in’s schema set:

2. List the formats supported by the Add-in

The EA_GetProfileInfo function enables us to manipulate the Schema Composer’s capabilities. One of these capabilities is to list the export formats that the Add-in support. I’ve set two formats to test this functionality (but just implemented the first):

profile.AddExportFormat(“Rod XML Schema”);
profile.AddExportFormat(“Rod JSON Schema”);

With this configuration, the following list appears on our screen when clicking the ‘Generate’ button.

3. Implement the schema generation

Now it is time to implement the code that will generate the file for the formats we have specified in the previous step. The function responsible for receiving the Schema Composer automation interface is EA_GenerateFromSchema. Below is my example where I’ve modified the EA_GenerateFromSchema function from the Sample Code to implement (only) the XML Schema generation.

public bool EA_GenerateFromSchema(EA.Repository Repository, EA.SchemaComposer composer, string exports)
 {
     // Build a String Array containing the export methods selected by the user
     string[] exportsArray = { };
     exportsArray = exports.Split(',');
     // Loop over the selected export methods
     foreach (string exportMethod in exportsArray)
     {
         switch (exportMethod)
         {
             case "Rod XML Schema":
                 ManageSchemaComposerXSD composerExportXSD = new ManageSchemaComposerXSD();
                 composerExportXSD.CreateXmlSchemaFromComposer(Repository, composer, true);
                 break;
             default:
                 MessageBox.Show("This format has not bee implemented yet. Please come back later!");
                 break;
         }
     }
     return true;
 }

Example Code

The compressed file below contains the modified Sample Code with the changes I’ve done to generate a XSD file. I’ve used the .NET XML Schema Object Model (SOM) to build the XML Schema and generate the respective file.

Rod_SchemaAddin

If you are using this as part of your solution, I would appreciate if you include a reference to my name!

Written by Rodrigo Nascimento
Rodrigo Nascimento is an experienced consultant with 30+ years of experience in IT. He has been working from the strategy definition down to the technical implementation, ensuring that deliverables can be traced to the promised business values. The combination of his passion for technology (which started when he was 10 years old with his first ZX Spectrum) and his strong academic business background (bachelor's degree in Marketing and MBA) have been used in many organisations to optimise the utilisation of IT resources and capabilities to leverage competitive advantage. Profile

6 Replies to “Extending Sparx EA Schema Composer”

  1. Hi Rodrigo,

    Nice article; and just in time.
    I’ll be working on a project doing very similar things the next few months. I’m hoping to get clearance to open source the add-in so I can share it as well.
    The version 12.1 just got out of beta this week. I hope they have added some more documentation as well.

    One small typo: My name is spelled Bellekens, not Bellikins 🙂

    1. Name updated! Sorry about the typo! At least I know that I’m not the only one that got your name wrong! 😉

      I wouldn’t use 12.1 yet… I’ve reported a few bugs related to SC Addin integration, generic schema profile configuration and the new schema transformation function. As soon as they fix everything I will post another article giving an overview of SC in v12.1.

      BTW, the documentation mentioned in this article is related to 12.1. The previous version (12) didn’t have any documentation.

  2. Hi Really Helpful Blog . Can you please tell me where does the Message Profiles of the schema composer datas are stored..?

  3. Arshad,

    Message Profiles can be stored as a model artifact in the repository (.eap file or database) or saved in the file system. For the later, the path to the folder is usually:

    C:\Users\\AppData\Roaming\Sparx Systems\EA\Message Profiles

    Hope it helps

  4. Hi Rodrigo
    Thanks for the reply.

    Is it possible to load our custom profile under the default schema set GENERIC ..?

    Thanks
    Arshad

  5. Hi Rodrigo
    Thanks for the reply.

    Is it possible to load our custom profile under the default schema set GENERIC ..? Instead of loading it under new display name .?

    Thanks
    Arshad

Leave a Reply

Your email address will not be published. Required fields are marked *