Example #1
0
      /// <summary>Creates a new <see cref="BplBinaryLayoutViewer"/> for the given BPL class.</summary>
      public BplBinaryLayoutViewer(BplClass bplClass) {
         if (bplClass == null) return;

         Grid.SetIsSharedSizeScope(this, true);
         var operation = bplClass.Operation;
         if (operation == null || operation.Output == null) {
            Children.Add(Slot.Create(bplClass));
         } else {
            RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
            RowDefinitions.Add(new RowDefinition { Height = new GridLength(26, GridUnitType.Pixel) });
            RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
            var slot0 = Slot.Create(operation.Input);
            var slot2 = Slot.Create(operation.Output);
            Grid.SetRow(slot0, 0);
            Grid.SetRow(slot2, 2);
            Children.Add(slot0);
            Children.Add(slot2);
         }
      }
Example #2
0
      /// <summary>Initializes a new instance of the <see cref="MetaClass"/> class.</summary>
      public MetaClass(BplClass bplClass) : this() {

         // Fill class level attributes
         this.Name = bplClass.Name;
         this.CanonicName = bplClass.CanonicName;
         this.Namespace = bplClass.Namespace.Name;
         this.OpCode = (uint)bplClass.Protocol.Opcode;
         this.OpCodeHex = string.Format("0x{0:X}", this.OpCode);
         this.IsCoreClass = bplClass.IsCoreClass;
         this.IsAbstract = !bplClass.IsConcrete;
         this.Documentation = new Documentation(BplLanguage.Documentation[bplClass].Content);
         this.IdentityScope = bplClass.IdentityScope.ScopeName;
         this.TagName = bplClass.TagName.NamespaceName;
         this.BaseClass = (bplClass.BaseClass != null) ? bplClass.BaseClass.CanonicName : "";
         this.Stereotype = bplClass.UnderlyingType.IsA<IBplResponseMessage>() ? "Response" : bplClass.UnderlyingType.IsA<IBplMessage>() ? "Message" : "Class";

         this.Register();

         // Fill all Properties
         bplClass.OwnProperties.Apply<BplProperty>(pr => this.addProperty(pr, this.Properties));
      }
Example #3
0
         public static Slot Create(BplClass bplClass) {
            if (bplClass == null) return null;

            var opcode = bplClass.Protocol.Opcode;
            var version = bplClass.Protocol.Version;
            var headerRows = new[] {
               new Slot(new Record("4", "Length"), _slotHeaderBG),
               new Slot(new Record("8", "Version (<c>v{0}</c>)".Substitute(version.ToString(4))), _slotHeaderBG),
               new Slot(new Record("4", "Checksum"), _slotHeaderBG)
            };
            var header = new Slot(0, headerRows);

            var footerRow = new Border {
               Child = new TextBlock { Text = "- EOF -", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center },
               MaxHeight = _slotSize,
               Padding = new Thickness(_slotMargin)
            };
            var footer = new Slot(footerRow, _slotHeaderBG);

            var body = _createBodySlot(null, bplClass, new Stack<BplClass>());

            return new Slot(0, header, body, footer);
         }
Example #4
0
      private bool _parse(Hashtable inputJson, BplClass expectedClass) {
         try {
            _mapping = new XmlNamespaceMap();
            if (inputJson.Contains(NAMESPACE_ATTR)) {
               var inputMapping = inputJson[NAMESPACE_ATTR] as Hashtable;
               if (inputMapping != null) {
                  foreach (string prefix in inputMapping.Keys) {
                     var nsname = inputMapping[prefix] as string;
                     if (nsname.NotEmpty() && BplNamespace.Get(nsname) != null) {
                        _mapping.Add(prefix, nsname);
                     } else {
                        AddError("Invalid namespace '{0}'.", nsname);
                     }
                  }
               } else {
                  AddError("Invalid namespace mapping.");
               }
            }
            if (!Success) return false;

            _resolver = new BplReferenceResolver();
            _resolver.CustomResolver = CustomResolver;

            _errorPath = PreserveErrorsInfo ? new List<object>() : null;
            _errorDepth = 0;

            Output = _deserializeObject(inputJson, expectedClass);
            if (!Success) return false;

            if (ResolutionStrategy != BplResolutionStrategy.Manual) {
               var success = _resolver.Resolve();
               if (success || ResolutionStrategy == BplResolutionStrategy.Tolerant) {
                  Output.CompleteInitialization();
               } else {
                  foreach (var R in _resolver.Pending) {
                     AddError("Failed to resolve reference from '{0}' to '{1}' ('{2}' association).", R.Source, R.TargetId, R.Property.Name);
                  }
               }
            }
            Pending = _resolver.Pending;
            return true;
         } catch (Exception e) {
            AddException(e);
            return false;
         }
      }
Example #5
0
 private XElement _generateElement(BplClass bplClass) {
    var xsd = XNamespaces.xsd;
    return new XElement(xsd + "element",
       new XAttribute("name", TagName(bplClass)),
       new XAttribute("type", QName(bplClass))
    );
 }
Example #6
0
      /// <summary>Add BPL Class to the collection.</summary>
      private void addClass(BplClass bplClass) {

         if (classes.Contains(bplClass)) return;
         classes.Add(bplClass);
         packages[bplClass.Namespace.Name].Classes.Add(bplClass);

         foreach (var property in bplClass.OwnProperties) {
            addProperty(property);
         }

         if (bplClass.BaseClass != null) {
            addClass(bplClass.BaseClass);
         }
      }
 private static bool IsSelected(BplClass bplClass) { return Shell.SelectedClasses.Contains(bplClass); }
         // Constructor
         public SourceNode(BplClass sourceClass) {
            Class = sourceClass;
            Name = sourceClass.Name;
            Children = new List<RelationNode>();
            Func<DisplayOptions, bool> check = option => Diagram.DisplayOptions.Has(option);

            var f1 = check(DisplayOptions.ShowInheritance);
            var directlyDerived = Class.DerivedClasses.OrderBy(c => c.Name).ToArray();
            var indirectlyDerived = Class.SubClasses.Except(directlyDerived).OrderBy(c => c.Name).ToArray();
            _addRelation("Super Classes", RelationKind.Inheritance, f1, f1, Class.InheritanceChain);
            if (indirectlyDerived.Length == 0) {
               _addRelation("Sub Classes", RelationKind.Inheritance, f1, f1, directlyDerived);
            } else {
               _addRelation("Direct Sub Classes", RelationKind.Inheritance, f1, f1, directlyDerived);
               _addRelation("Indirect Sub Classes", RelationKind.Inheritance, f1, false, indirectlyDerived);
            }

            var f2 = check(DisplayOptions.ShowContainment);
            Func<BplProperty, bool> c2 = p => p.IsContainer;
            _addDependents("Contained Classes", RelationKind.Containment, f2, f2, c2);
            _addPrecedents("Containing Classes", RelationKind.Containment, f2, f2, c2);

            var f3 = check(DisplayOptions.ShowAssociations);
            Func<BplProperty, bool> c3 = p => p.IsAssociation || p.IsWeakAssociation;
            _addDependents("Referenced Classes", RelationKind.Association, f3, f3, c3);
            _addPrecedents("Referencing Classes", RelationKind.Association, f3, f3, c3);

            var relatedClasses = Children.SelectMany(r => r.Children).Select(t => t.Class);
            var unrelatedClasses = Shell.SelectedClasses.Except(relatedClasses).OrderBy(c => c.Name);
            _addRelation("Unrelated Classes", RelationKind.None, true, false, unrelatedClasses);
         }
Example #9
0
         // Constructor
         public ClassNode(BplClass bplClass) {
            Children = new List<ClassNode>();
            Class = bplClass;
            Name = bplClass.Name;
            Index.Add(this);

            _isSelected = Explorer.Shell.SelectedClasses.Contains(Class);
         }
Example #10
0
      // recursively serializes a BPL object
      private void _serializeObject(XContainer parent, BplObject bplObject, BplClass expectedClass) {
         if (bplObject == null) return;

         var bplClass = bplObject.Class;
         var schema = bplClass.Schema;
         var prefix = BplLanguage.Schemas[schema];
         NSMapping.AddIfNeeded(prefix, schema);

         XElement element = null;
         if (expectedClass == null || schema == expectedClass.Schema) {
            element = new XElement(bplClass.TagName);
         } else {
            NSMapping.AddIfNeeded("xsi", xsi);
            element = new XElement(expectedClass.TagName);
            element.Add(new XAttribute(xsi + "type", prefix + ":" + bplClass.TagName.LocalName));
         }

         var identityProperty = bplClass.IdentityProperty;
         if (identityProperty != null) {
            var id = (BplIdentity)identityProperty.GetValue(bplObject);
            if (!id.IsEmpty) {
               element.Add(new XAttribute(identityProperty.TagName, id.ToString(bplClass.IdentityScope)));
            } else if (bplClass.IsA<BplEntity>()) {
               AddError("{0} is missing Id.", bplObject);
            }
         }

         // invariant: write the properties according to their "ProtocolIndex" order
         foreach (var property in bplClass.PropertiesSorted) {
            if (property.IsCalculated || property.IsVirtual || property == identityProperty) continue;

            var value = property.GetValue(bplObject);
            if (value == null) continue;

            if (!ShouldSerialize(property, bplObject)) continue;

            if (property.IsPrimitive) {
               if (property.IsScalar) {
                  _serializeScalar(element, property, value);
               } else if (property.IsArray) {
                  _serializeArray(element, property, (IEnumerable)value);
               }
            } else if (property.IsContainer) {
               if (property.IsReference) {
                  _serializeContainer(element, property, (BplObject)value);
               } else {
                  _serializeContainer(element, property, (IBplCollection)value);
               }
            } else if (property.IsAssociation) {
               if (property.IsReference) {
                  _serializeAssociation(element, property, (BplObject)value);
               } else {
                  _serializeAssociation(element, property, (IBplCollection)value);
               }
            }
         }

         parent.Add(element);
      }
Example #11
0
 private string TagName(BplClass bplClass) {
    return bplClass.TagName.LocalName;
 }
Example #12
0
 private string QName(BplClass bplClass, string suffix) {
    return QName(bplClass.Schema, TagName(bplClass, suffix));
 }
Example #13
0
 private string QName(BplClass bplClass) {
    return QName(bplClass.Schema, TagName(bplClass));
 }
Example #14
0
 private XElement _generateWSDLMessage_11(BplClass bplClass, bool isMessageHeader) {
    var wsdl = XNamespaces.wsdl_11;
    Func<string, string, XElement> createMessage = (elementName, partName) => {
       return new XElement(wsdl + "message",
          new XAttribute("name", TagName(bplClass)),
          new XElement(wsdl + "part",
             new XAttribute("name", partName),
             new XAttribute("element", elementName)
          )
       );
    };
    if (isMessageHeader) {
       return createMessage(TnsName(bplClass), "body");
    } else {
       return createMessage(QName(bplClass), "parameters");
    }
 }
Example #15
0
 private XElement _generateWSDLMessageHeader(BplService service, BplClass headerClass) {
    var xsd = XNamespaces.xsd;
    var headerFields = new XElement(xsd + "sequence");
    var headerSelector = headerClass.OwnProperties.Where(p => p.IsPrimitive || p.IsTaxonomy);
    if (SortMembers) {
       headerSelector = headerSelector.OrderBy(p => p.Name);
    }
    foreach (var prop in headerSelector) {
       var propType = (prop.IsPrimitive ? QName(prop.PrimitiveType) : QName(BplPrimitive.Get<BplIdentity>()));
       headerFields.Add(new XElement(xsd + "element",
          new XAttribute("name", prop.Name),
          new XAttribute("type", propType)
       ));
    };
    return new XElement(xsd + "element",
       new XAttribute("name", headerClass.Name),
       new XElement(xsd + "complexType", headerFields)
    );
 }
Example #16
0
      private XElement[] _generateContainer(BplClass bplClass) {
         if (!_containers.ContainsKey(bplClass)) return new XElement[0];
         var containerFlags = _containers[bplClass];

         var xsd = XNamespaces.xsd;
         var result = new List<XElement>();

         var groupRef = QName(bplClass.Schema, TagName(bplClass, "-Base"));
         var groupDef = new XElement(xsd + "choice");
         if (bplClass.IsConcrete) {
            groupDef.Add(new XElement(xsd + "element", new XAttribute("ref", QName(bplClass))));
         }
         foreach (var subclass in bplClass.DerivedClasses) {
            if (subclass.Schema != bplClass.Schema) {
               // TODO: this is a known limitation that prevents using derived classes defined in one schema
               //       inside a container that is defined in another schema
               continue;
            }
            groupDef.Add(new XElement(xsd + "group", new XAttribute("ref", QName(subclass, "-Base"))));
         }
         result.Add(new XElement(xsd + "group",
            new XAttribute("name", TagName(bplClass, "-Base")),
            groupDef
         ));

         if (containerFlags.Has(ContainerFlags.Singleton)) {
            result.Add(new XElement(xsd + "complexType",
               new XAttribute("name", TagName(bplClass, "-Item")),
               new XElement(xsd + "group",
                  new XAttribute("ref", groupRef),
                  new XAttribute("minOccurs", "1"),
                  new XAttribute("maxOccurs", "1")
               )
            ));
         }

         if (containerFlags.Has(ContainerFlags.Collection)) {
            result.Add(new XElement(xsd + "complexType",
               new XAttribute("name", TagName(bplClass, "-List")),
               new XElement(xsd + "group",
                  new XAttribute("ref", groupRef),
                  new XAttribute("minOccurs", "0"),
                  new XAttribute("maxOccurs", "unbounded")
               )
            ));
         }

         return result.ToArray();
      }
Example #17
0
      private XElement _generateClass(BplClass bplClass) {
         var xsd = XNamespaces.xsd;
         var complexType = new XElement(xsd + "complexType", 
            new XAttribute("name", TagName(bplClass))
         );
         if (!bplClass.IsConcrete) {
            complexType.Add(new XAttribute("abstract", "true"));
         }

         var baseClass = bplClass.BaseClass;
         var extension = complexType;
         var properties = new List<BplProperty>();

         if (HideCore && baseClass != null && baseClass.IsCoreClass) {
            properties.AddRange(baseClass.Properties);
            baseClass = null;
         }

         if (baseClass != null) {
            extension = new XElement(xsd + "extension", new XAttribute("base", QName(baseClass)));
            complexType.Add(new XAttribute("mixed", "false"));
            complexType.Add(new XElement(xsd + "complexContent", extension));
         }

         if (SortMembers) {
            properties.AddRange(bplClass.OwnPropertiesSorted);
         } else {
            properties.AddRange(bplClass.OwnProperties);
         }
         var propertyDefs = properties.Where(p => !p.IsCalculated && !p.IsVirtual && !p.IsOverridden).Select(p => _generateProperty(p)).ToArray();
         var elementDefs = propertyDefs.Where(p => p != null && p.Name == xsd + "element").ToArray();
         var attributeDefs = propertyDefs.Where(p => p != null && p.Name == xsd + "attribute").ToArray();

         if (elementDefs.Length > 0) {
            var container = new XElement(xsd + "sequence");
            for (var i = 0; i < elementDefs.Length; i++) {
               container.Add(elementDefs[i]);
            }
            extension.Add(container);
         }

         if (attributeDefs.Length > 0) {
            for (var i = 0; i < attributeDefs.Length; i++) {
               extension.Add(attributeDefs[i]);
            }
         }

         return complexType;
      }
Example #18
0
      // recursively deserializes a BPL object
      private BplObject _deserializeObject(Hashtable jsonTable, BplClass expectedClass) {
         var bplClass = expectedClass;

         if (StronglyTyped) {
            var qname = jsonTable[TYPE_ATTR] as string;
            if (qname.IsEmpty()) {
               AddError("Type specifier is missing.");
               return null;
            }
            var k = qname.IndexOf(":");
            var prefix = qname.Before(k);
            var className = qname.After(k);
            if (prefix.IsEmpty() || !_mapping.Contains(prefix)) {
               AddError("Type prefix '{0}' is invalid.", prefix);
               return null;
            }
            if (className.IsEmpty()) {
               AddError("Type name is missing.");
               return null;
            }
            var tagName = _mapping[prefix] + className;
            bplClass = BplClass.GetCompatible(tagName);
            if (bplClass != null && expectedClass != null && !bplClass.IsA(expectedClass)) {
               AddError("Unexpected BPL class '{0}'. Was expecting '{1}' class or a derived class.", bplClass, expectedClass);
               return null;
            }
         }

         if (bplClass == null) {
            AddError("BPL class is unspecified and cannot be inferred from context.");
            return null;
         }

         // create object
         BplObject bplObject = null;
         try {
            bplObject = bplClass.CreateUninitialized();
         } catch (Exception e) {
            AddError("Failed to create BPL object '{0}'. {1}", bplClass, e.Message);
            return null;
         }
         var existingProperties = new HashSet<BplProperty>();

         
         // read id property, if required
         var identityProperty = bplClass.IdentityProperty;
         if (identityProperty != null) {
            var localId = jsonTable[identityProperty.TagName.LocalName] as string;
            var isEntity = bplClass.IsA<BplEntity>();
            if (localId.IsEmpty()) {
               if (isEntity) {
                  AddError("Entity Id is missing.", bplClass);
               }
            } else {
               var id = BplIdentity.Get(localId, bplClass.IdentityScope);
               existingProperties.Add(identityProperty);
               identityProperty.SetValue(bplObject, id);
               if (isEntity && !_resolver.AddTarget(id, bplObject)) {
                  AddError("Encountered duplicate entity Id '{0}'.", id.ToString(true));
               }
            }
         }

         // read all other properties 
         _errorDepth++;
         foreach (string tag in jsonTable.Keys) {
            if (tag.At(0) == "$") continue;
            if (PreserveErrorsInfo) _updateErrorInfo(tag);

            var property = bplClass.GetProperty((XName)tag);
            if (property == null) {
               AddError("Unknown BPL property.");
               continue;
            }
            if (property == identityProperty) continue;
            if (existingProperties.Contains(property)) {
               AddError("Property is set more than once.");
               continue;
            }
            if (property.IsCalculated) {
               AddWarning("Calculated property found and ignored.");
               continue;
            }
            existingProperties.Add(property);

            try {
               var value = jsonTable[tag];
               if (property.IsScalar) {
                  _deserializeScalar(bplObject, property, value);
               } else if (property.IsArray) {
                  if (value == null) continue;
                  _deserializeArray(bplObject, property, (ArrayList)value);
               } else if (property.IsContainer) {
                  if (value == null) continue;
                  if (property.IsReference) {
                     _deserializeContainer(bplObject, property, (Hashtable)value);
                  } else if (property.IsCollection) {
                     _deserializeContainer(bplObject, property, (ArrayList)value);
                  }
               } else if (property.IsAssociation) {
                  if (value == null) continue;
                  if (property.IsReference) {
                     _deserializeAssociation(bplObject, property, (string)value);
                  } else if (property.IsCollection) {
                     _deserializeAssociation(bplObject, property, (ArrayList)value);
                  }
               } else {
                  AddError("Unexpected property type '{0}'.", property.UnderlyingType.Name);
               }
            } catch (Exception e) {
               AddException(e);
            }
         }
         _errorDepth--;

         return bplObject;
      }
Example #19
0
 /// <summary>Gets the documentation of the specified BPL class.</summary>
 public BplDocumentationTopic this[BplClass bplClass] {
    get { return new BplDocumentationTopic(bplClass); }
 }
Example #20
0
 private string TagName(BplClass bplClass, string suffix) {
    return TagName(bplClass) + suffix;
 }
Example #21
0
 private int _getMaxDepth(BplClass baseClass) {
    var depth = 0;
    foreach (var bplClass in baseClass.DerivedClasses) {
       depth = Math.Max(depth, _getMaxDepth(bplClass));
    }
    return depth + 1;
 }
Example #22
0
 private string TnsName(BplClass bplClass) {
    return TnsName(bplClass.TagName.LocalName);
 }
Example #23
0
 public static ClassNode Get(BplClass bplClass) {
    return Index[bplClass];
 }
Example #24
0
 /// <summary>Constructor</summary>
 public MessageType(BplClass bplClass) {
    this.BplVersion = bplClass.Protocol.Version;
    this.BplOpCode = (uint)bplClass.Protocol.Opcode;
    this.ClassType = bplClass.CanonicName;
 }
 // Constructor
 public TargetNode(RelationNode parent, bool isEnabled, BplClass targetClass) {
    Class = targetClass;
    IsEnabled = isEnabled;
    Name = targetClass.Name;
    Parent = parent;
 }
Example #26
0
         private static Slot _createBodySlot(BplProperty parentProperty, BplClass bplClass, Stack<BplClass> parentClasses) {
            if (parentClasses.Any(pclass => bplClass.IsA(pclass))) {
               var error = new Record("", parentProperty.Name + " : " + bplClass.Name + " [recursive]");
               return new Slot(error, _slotErrorBG);
            }
            parentClasses.Push(bplClass);

            var childSlots = new StackPanel {
               Margin = new Thickness(0, _slotSize, _slotSize, 0)
            };

            childSlots.Children.Add(new Slot(0, new Record("4", "Opcode (<c>0x{0:X8}</c>)".Substitute(bplClass.Protocol.Opcode))));

            var depth = 0;
            int? fixedSize = 4;
            foreach (var prop in bplClass.Properties) {
               Slot slot = null;
               if (prop.IsCalculated) continue;
               if (prop.IsPrimitive) {
                  var ptype = prop.PrimitiveType;
                  var pname = "{0} : <i>{1}</i>".Substitute(prop.Name, (ptype.IsDelegate ? "Function" : ptype.Name));
                  var psize = BplLanguage.BinaryConverters[ptype].SizeOf();
                  if (psize.Size.HasValue && fixedSize.HasValue) {
                     fixedSize = fixedSize.Value + psize.Size.Value;
                  } else {
                     fixedSize = null;
                  }
                  slot = new Slot(0, new Record(psize.Formula, pname));
               } else {
                  fixedSize = null;
                  var refClass = prop.ReferencedClass;
                  if (prop.IsAssociation) {
                     var multiplier = "";
                     var suffix = "*";
                     if (prop.IsCollection) {
                        multiplier = @"n {0} ".Substitute(DOT);
                        suffix = "[]";
                     }
                     var record = new Record("4 + {0}|id|".Substitute(multiplier), "{0} : <i>{1}{2}</i>".Substitute(prop.Name, refClass.Name, suffix));
                     slot = new Slot(0, record);
                  } else {
                     slot = _createBodySlot(prop, refClass, parentClasses);
                  }
               }
               depth = Math.Max(depth, slot.Depth);
               childSlots.Children.Add(slot);
            }

            var parentGrid = new Grid();
            parentGrid.Children.Add(childSlots);

            if (parentProperty == null) {
               var title = new HtmlBlock("<b>{0}</b>".Substitute(bplClass.Name)) {
                  Margin = new Thickness(_slotMargin),
                  HorizontalAlignment = HorizontalAlignment.Center,
                  VerticalAlignment = VerticalAlignment.Top
               };
               parentGrid.Children.Add(title);
               _ncollections = 0;
            } else {
               var name = "{0} : <i>{1}</i>".Substitute(parentProperty.Name, bplClass.Name + (parentProperty.IsCollection ? "[]" : "*"));
               var cardinality = "1";
               if (parentProperty.IsCollection) {
                  cardinality = @"N<font size=""8"">{0}</font>".Substitute(++_ncollections);
               }

               var parentSize = String.Empty;
               if (fixedSize.HasValue) {
                  parentSize = fixedSize.Value.ToString();
               } else {
                  parentSize = "|{0}|".Substitute(_getNameStem(bplClass.Name));
               }
               if (cardinality == "1") {
                  parentSize = "4 + {0}?".Substitute(parentSize);
               } else {
                  parentSize = "4 + {0} {1} {2}".Substitute(cardinality, DOT, parentSize);
               }
               parentGrid.Children.Add(new Record(parentSize, name));

               parentGrid.Children.Add(new HtmlBlock(cardinality) {
                  Width = _slotSize,
                  TextAlignment = TextAlignment.Center,
                  HorizontalAlignment = HorizontalAlignment.Right,
                  VerticalAlignment = VerticalAlignment.Center
               });
            }

            parentClasses.Pop();
            return new Slot(depth + 1, parentGrid);
         }
Example #27
0
 /// <summary>Build BPL packages tree from class namespace.</summary>
 private void mapPackageFromClass(BplClass bplClass) {
    string[] segments = bplClass.Namespace.Name.Split('.');
    string packageName = string.Empty;
    foreach (string segment in segments) {
       packageName = packageName.IsEmpty() ? segment : string.Format("{0}.{1}", packageName, segment);
       if (!packages.Contains(packageName)) {
          packages.Add(new BplPackage(packageName, this.usePackageFullNameAsId));
       }
    }
 }
      /// <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));
      }
Example #30
0
      private void _addClass(BplClass bplClass) {
         if (bplClass == null) return;
         if (_classes.Contains(bplClass)) return;
         if (HideCore && bplClass.IsCoreClass) return;

         if (!_schemas.Contains(bplClass.Schema)) {
            _schemas.Add(bplClass.Schema);
         }
         _classes.Add(bplClass);

         foreach (var property in bplClass.OwnPropertiesSorted) {
            _addProperty(property);
         }

         if (bplClass.BaseClass != null) {
            _addClass(bplClass.BaseClass);
         }
      }