Beispiel #1
0
      /// <summary>Initializes a new instance of the <see cref="MetaPackage"/> class. with BplPackage parameter</summary>
      public MetaPackage(BplPackage package) : this() {
         
         // Set package properties
         this.Name = package.Name;
         this.Namespace = package.Parent;
         this.CanonicName = package.CanonicName;
         this.IsRoot = package.IsRoot;
         this.Documentation = getPackageDocumentation();

         // Add sub packages
         package.Packages.Apply<BplPackage>(pkg => this.addSubPackage(pkg));
      }
Beispiel #2
0
 /// <summary>Add sub package.</summary>
 private void addSubPackage(BplPackage package) {
    this.Packages.Add(new MetaPackage(package));
 }
Beispiel #3
0
      /// <summary>Create package tree from canonic name.</summary>
      private BplPackage getPackage(string packageName) {

         // If package exists, return it
         if (packages.Contains(packageName)) {
            return packages[packageName];
         }
         
         // If package does not exist, create it in the right hierarchy
         List<string> packageTree = new List<string>();
         string[] segments = packageName.Split('.');
         string tree = string.Empty;
         foreach (string segment in segments) {
            tree = tree.IsEmpty() ? segment : string.Format("{0}.{1}", tree, segment);
            packageTree.Add(tree);
         }

         BplPackage lastPackage = null;

         foreach (string p in packageTree) {
            if (packages.Contains(p)) {
               lastPackage = packages[p];
            } else {
               BplPackage newPackage = new BplPackage(p, this.usePackageFullNameAsId);
               packages.Add(newPackage);

               if (lastPackage != null) {
                  lastPackage.Packages.Add(newPackage);
               }
               lastPackage = newPackage;
            }
         }
         return lastPackage;
      }
      /// <summary>Add tool extensions of a package element.</summary>
      /// <param name="bplPackage">The BplPackage.</param>
      public void AddToolExtensions(BplPackage bplPackage) {

         string stereotype = bplPackage.IsContract ? "bplContract" : "bplPackage";

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

         xElementExt.Add(new XElement("properties",
            new XAttribute("documentation", bplPackage.CanonicName),
            new XAttribute("isSpecification", "false"),
            new XAttribute("sType", "Package"),
            new XAttribute("scope", "public"),
            new XAttribute("stereotype", stereotype)));

         // Add the profile extension
         XElement xTags = new XElement("tags");
         xTags.AddTags(new Pair("isNamespace", "true"));
         xElementExt.Add(xTags);

         XmiElements.Add(xElementExt);

         // Add primitive elements
         bplPackage.Primitives.Apply<BplPrimitive>(pt => AddToolExtensions(pt));

         // Add class elements
         bplPackage.Classes.Apply<BplClass>(cls => AddToolExtensions(cls));

         // Add sub packaages
         bplPackage.Packages.Apply<BplPackage>(pkg => AddToolExtensions(pkg));
      }
      /// <summary>Add uml extentions for package.</summary>
      private void AddUmlExtensions(BplPackage bplPackage) {

         // Add the profile extension for the package
         string stereotype = bplPackage.IsContract ? "bplContract" : "bplPackage";
         AddUmlExtentions(stereotype, BASE_PACKAGE, bplPackage.GetID(), new Pair("isNamespace", "true"), new Pair("canonicName", bplPackage.CanonicName));

         // Add profile extensions for the package primitives
         bplPackage.Primitives.Apply<BplPrimitive>(pt => AddUmlExtensions(pt));

         // Add the profile extension for the package classes
         bplPackage.Classes.Apply<BplClass>(cls => AddUmlExtensions(cls));

         // Add the profile extension for the contained packages
         bplPackage.Packages.Apply<BplPackage>(pkg => AddUmlExtensions(pkg));
      }
      /// <summary>Generate package file.</summary>
      private void generatePackageFile(BplPackage packag, string templateName, string folder, string filePattern) {
         this.notifyAction("Generating package {0} ...", packag.CanonicName);

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

         // Generate package related source files
         string targetFolder = verifyDirectory(folder, packag.CanonicName);
         template.SetAttribute("BplPackage", packag);

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