/// <summary>Add tool extentions for class.</summary>
      private void AddToolExtensions(BplClass bplClass) {

         string stereotype = string.Empty;

         // Class stereotypes and tags
         XElement xTags = new XElement("tags");

         if (bplClass.IsA<BplMessage>()) {
            stereotype = "bplMessage";
            string kind = (bplClass.Protocol.IsRequest) ? "request" :
                          (bplClass.Protocol.IsResponse) ? "response" :
                          (bplClass.Protocol.IsNotification) ? "notification" : "unknown";

            xTags.AddTags(
               new Pair("opCode", bplClass.Protocol.Opcode),
               new Pair("serviceOperationKind", kind)
               );

         } else if (bplClass.IsA<BplEntity>()) {
            stereotype = "bplEntity";
            xTags.AddTags(new Pair("opCode", bplClass.Protocol.Opcode));

         } else {
            stereotype = "bplPrimitive";
         }

         // Add the element extensions
         XElement xElementExt = new XElement("element",
             new XAttribute(xmiNs + "idref", bplClass.GetID()),
             new XAttribute(xmiNs + "type", "uml:Class"),
             new XAttribute("name", bplClass.Name),
             new XAttribute("scope", "public"));

         var documentation = BplLanguage.Documentation[bplClass].Content;
         xElementExt.Add(new XElement("properties",
            new XAttribute("documentation", (documentation != null ? documentation.Value : "")),
            new XAttribute("isSpecification", "false"),
            new XAttribute("sType", "Class"),
            new XAttribute("alias", bplClass.CanonicName),
            new XAttribute("scope", "public"),
            new XAttribute("stereotype", stereotype),
            new XAttribute("isAbstract", bplClass.IsConcrete ? "false" : "true"),
            new XAttribute("isRoot", (bplClass.BaseClass == null) ? "true" : "false"),
            new XAttribute("isActive", "true")
            ));

         // Add tags
         xElementExt.Add(xTags);


         // Add Links
         XElement xLinks = new XElement("links");

         // Add generalization link to the parent class
         if (bplClass.BaseClass != null) {
            string genId = string.Format("EAID_{0}_ISA_{1}", bplClass.GetID(), bplClass.BaseClass.GetID());
            XElement xGeneralization = new XElement("generalization",
                new XAttribute(xmiNs + "id", genId),
                new XAttribute("start", bplClass.GetID()),
                new XAttribute("end", bplClass.BaseClass.GetID()));
            xLinks.Add(xGeneralization);
         }

         // Add generalization link to all derived classes
         bplClass.DerivedClasses.Apply<BplClass>(cls => {
            string genId = string.Format("EAID_{0}_ISA_{1}", cls.GetID(), bplClass.GetID());
            XElement xGeneralization = new XElement("generalization",
                new XAttribute(xmiNs + "id", genId),
                new XAttribute("start", cls.GetID()),
                new XAttribute("end", bplClass.GetID()));
            xLinks.Add(xGeneralization);
         });

         xElementExt.Add(xLinks);

         // Add Properties Extensions
         XElement xAttributes = new XElement("attributes");
         xElementExt.Add(xAttributes);
         bplClass.OwnProperties.Apply<BplProperty>(pr => AddToolExtensions(pr, xAttributes));
         XmiElements.Add(xElementExt);
      }
      /// <summary>Add uml extentions for class.</summary>
      private void AddUmlExtensions(BplClass bplClass) {

         ulong opCode = (ulong)bplClass.Protocol.Opcode;
         if (bplClass.IsA<BplMessage>()) {
            string kind = (bplClass.Protocol.IsRequest) ? "request" :
                          (bplClass.Protocol.IsResponse) ? "response" :
                          (bplClass.Protocol.IsNotification) ? "notification" : "unknown";

            AddUmlExtentions("bplMessage", BASE_CLASS, bplClass.GetID(),
               new Pair("opCode", bplClass.Protocol.Opcode),
               new Pair("serviceOperationKind", kind)
               );
         } else if (bplClass.IsA<BplEntity>()) {
            AddUmlExtentions("bplEntity", BASE_CLASS, bplClass.GetID(), new Pair("opCode", opCode));
         } else if (bplClass.IsA<BplStructure>()) {
            AddUmlExtentions("bplStructure", BASE_CLASS, bplClass.GetID(), new Pair("opCode", opCode));
         } else {
            AddUmlExtentions("bplPrimitive", BASE_CLASS, bplClass.GetID(), new Pair("opCode", opCode));
         }

         // Add the profile extension for the class properties
         bplClass.OwnProperties.Apply<BplProperty>(prop => AddUmlExtensions(prop));
      }