Ejemplo n.º 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();
      }
Ejemplo n.º 2
0
      /// <summary>Loads meta model from XML.</summary>
      public static MetaPackage LoadFromXml(XElement xml) {

         MetaPackage package = new MetaPackage();
         package.Name = xml.HasAttribute("name") ? xml.Attribute("name").Value : "";
         package.CanonicName = xml.HasAttribute("canonicName") ? xml.Attribute("canonicName").Value : "";
         package.Namespace = xml.HasAttribute("namespace") ? xml.Attribute("namespace").Value : "";
         package.IsRoot = xml.HasAttribute("isRoot") ? (bool)xml.Attribute("isRoot") : false;

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

         // Load classes
         XElement xClasses = xml.Element("Classes");
         if (xClasses != null) {
            foreach (XElement xClass in xClasses.Elements("Class")) {
               MetaClass metaClass = MetaClass.LoadFromXml(xClass);
               if (metaClass != null) {
                  package.Classes.Add(metaClass);
               }
            }
         }

         // Load primitives
         XElement xPrimitives = xml.Element("Primitives");
         if (xPrimitives != null) {
            foreach (XElement xPrimitive in xPrimitives.Elements("Primitive")) {
               MetaPrimitive metaPrimitive = MetaPrimitive.LoadFromXml(xPrimitive);
               if (metaPrimitive != null) {
                  package.Primitives.Add(metaPrimitive);
               }
            }
         }

         // Load enums
         XElement xEnums = xml.Element("Enums");
         if (xEnums != null) {
            foreach (XElement xEnum in xEnums.Elements("Enum")) {
               MetaEnum mEnum = MetaEnum.LoadFromXml(xEnum);
               if (mEnum != null) {
                  package.Enums.Add(mEnum);
               }
            }
         }

         // Load sub packages
         XElement xPackages = xml.Element("Packages");
         if (xPackages != null) {
            foreach (XElement xPackage in xPackages.Elements("Package")) {
               MetaPackage subPackage = MetaPackage.LoadFromXml(xPackage);
               if (subPackage != null) {
                  package.Packages.Add(subPackage);
               }
            }
         }
         return package;
      }
Ejemplo n.º 3
0
 /// <summary>Edit meta package in the editor panel.</summary>
 private void EditMetaPackage(MetaPackage mPackage) {
    MetaPackageEditorControl ctrl = new MetaPackageEditorControl();
    ObjectPanel.Children.Add(ctrl);
    ctrl.DataContext = mPackage;
 }