Example #1
0
      protected override void buildXmi() {

         // Get root packages and build package hierarchy
         List<BplPackage> rootPackages = this.packages.Where<BplPackage>(pkg => (pkg.IsRoot == true)).ToList<BplPackage>();
         foreach (BplPackage bplPackage in rootPackages) {
            MetaPackage metaPackage = new MetaPackage(bplPackage);
            this.metaModel.Packages.Add(metaPackage);
         }

         // Associate classes to packages
         foreach (BplClass bplClass in this.classes) {
            MetaClass metaClass = new MetaClass(bplClass);
            MetaPackage mPackage = this.metaModel.GetPackageByName(metaClass.Namespace);
            if (mPackage == null) {
               throw new Exception(string.Format("Package {0} was not found in the model", metaClass.Namespace));
            } else {
               mPackage.Classes.Add(metaClass);
            }
         }

         // Associate classes to packages
         foreach (BplPrimitive bplPrimitive in this.primitives) {

            if (bplPrimitive.IsIntrinsic) {
               Debug.WriteLine(string.Format("Intrinsic primitive found: {0}", bplPrimitive.CanonicName));
            }
            if (bplPrimitive.IsArray) {
               Debug.WriteLine(string.Format("Array primitive found: {0}", bplPrimitive.CanonicName));
            }
            if (bplPrimitive.IsCustom) {
               Debug.WriteLine(string.Format("Custom primitive found: {0}", bplPrimitive.CanonicName));
            }
            if (bplPrimitive.IsDelegate) {
               Debug.WriteLine(string.Format("Delegate primitive found: {0}", bplPrimitive.CanonicName));
            }
            //if (bplPrimitive.SubPrimitives.) {
            //   Debug.WriteLine(string.Format("Delegate primitive found: {0}", bplPrimitive.CanonicName));
            //}

            if (bplPrimitive.IsEnum) {
               this.linkEnum(bplPrimitive);
            } else {
               this.linkPrimitive(bplPrimitive);
            }
         }

         // Serialize the model to XML
         this.XmiRoot = this.metaModel.GetXml();
      }
 /// <summary>Edit meta class in the editor panel.</summary>
 private void EditMetaClass(MetaClass mClass) {
    MetaClassEditorControl ctrl = new MetaClassEditorControl();
    ObjectPanel.Children.Add(ctrl);
    ctrl.DataContext = mClass;
 }
Example #3
0
      /// <summary>Loads meta class data from XML.</summary>
      public static MetaClass LoadFromXml(XElement xml) {
         try {
            MetaClass clazz = new MetaClass();
            clazz.Name = xml.HasAttribute("name") ? xml.Attribute("name").Value : "";
            clazz.CanonicName = xml.HasAttribute("canonicName") ? xml.Attribute("canonicName").Value : "";
            clazz.Namespace = xml.HasAttribute("namespace") ? xml.Attribute("namespace").Value : "";
            clazz.IdentityScope = xml.HasAttribute("identityScope") ? xml.Attribute("identityScope").Value : "";
            clazz.OpCode = xml.HasAttribute("opCode") ? (uint)xml.Attribute("opCode") : 0;
            clazz.OpCodeHex = xml.HasAttribute("opCodeHex") ? xml.Attribute("opCodeHex").Value : "";
            clazz.TagName = xml.HasAttribute("tagName") ? xml.Attribute("tagName").Value : "";
            clazz.IsCoreClass = xml.HasAttribute("isCore") ? (bool)xml.Attribute("isCore") : false;
            clazz.IsAbstract = xml.HasAttribute("isAbstract") ? (bool)xml.Attribute("isAbstract") : false;
            clazz.BaseClass = xml.HasAttribute("baseClass") ? xml.Attribute("baseClass").Value : "";
            clazz.Stereotype = xml.HasAttribute("stereotype") ? xml.Attribute("stereotype").Value : "";

            // Load Documentation
            clazz.Documentation = Documentation.LoadFromXml(xml.Element("Documentation"));

            // Load Properties
            XElement xProperties = xml.Element("Properties");
            if (xProperties != null) {
               foreach (XElement xProp in xProperties.Elements("Property")) {
                  MetaProperty metaProp = MetaProperty.LoadFromXml(xProp);
                  if (metaProp != null) {
                     clazz.Properties.Add(metaProp);
                  }
               }
            }
            return clazz;
         } catch (Exception) {
            return null;
         }
      }
Example #4
0
      /// <summary>Generate class file.</summary>
      private void generateClassFile(MetaClass metaClass, string templateName, string folder, string filePattern) {
         this.notifyAction("Generating class {0} ...", metaClass.Name);

         // Verify that class template exists
         StringTemplate template = this.stGroup.GetInstanceOf(templateName);
         if (template == null) return;

         // Generate class related source files
         string targetFolder = verifyDirectory(folder, metaClass.Namespace);
         template.SetAttribute("BplClass", metaClass);

         string targetFile = this.ResolveFileName(metaClass, filePattern);
         string targetPath = Path.Combine(targetFolder, targetFile);
         using (StreamWriter outfile = new StreamWriter(targetPath)) {
            outfile.Write(template.ToString());
         }
      }