-
Couldn't load subscription status.
- Fork 3
uml4net.project
The uml4net project contains the core classes, interfaces and enumerations that are documented in the UML 2.5.1 specification. This project is intended:
- To be as lean as possible.
- To have the minimal number of dependencies on other libraries or projects.
- To contain only the bare minimum required to represent the UML 2.5.1 metamodel in C#,
- To be self documenting to make the life of developers and consumers as simple as possible.
Most of the files are generated using uml4net itself (yes yes, some kind inception, sounds like a dream, in a dream in a dream...). The generated files can be found in the following folders (the folder names speak for themselves)
- AutoGenClasses
- AutoGenEnumeration
- AutoGenInterfaces
The other project folders contain hand-coded classes:
- Decorators: C# Attributes used to decorate Classes and Properties to make them self documenting.
- Extend: Extension methods that implement
derivedproperties.
The UML 2.5.1 specification makes use of multiple inheritance to describe the UML metamodel. Multiple inheritance is not supported in C# for classes with the exception of interfaces. A C# class can inherit from at most 1 other class and can implement multiple interfaces. A C# interface can inherit from multiple interfaces. These rules are used to implement UML 2.5.1 in C# as follows:
- All UML classes (both abstract and concrete) are generated as C#
public partial interfaceswith owned attributes as C# properties with getters and setters. - The name of the interface uses the name of UML class prefixed with an
I. - The namespace of each
interfacestarts withuml4net(which replaces the root namespace calledUML) and then includes the rest of the Fully Qualified name. - In case an owned attribute is
derived, aderived-unionorreadonly, the associated property only has a getter. - The generalizations (inheritance) specified in the UML metamodel are generated as inherited interfaces.
- Each
interfaceis decorated with the[Class]C# attribute that documents theinterface(read more about the attributes in the sections below). - Each property is decorated with the
[Property]C# attribute. - In case the property is subsetted it is decorated with the
[SubsettedProperty]C# attribute. - In case the property is redefined by another property it is decorated with the
[RedefinedByProperty]C# attribute. - In case the property is a redefinition of another property it is decorated with the
[RedefinedProperty]C# attribute.
The generated interfaces can be found in the
AutoGenInterfacesfolder.
- All concrete (non-abstract) UML classes are generated a C#
public partial class. - Each UML class inherits from the
XmiElementabstract super class and implements the interface with the same name (prefixed with anIto follow the C# convention). - Due to the fact that the interface that is being implemented might inherit from other interfaces, the C# UML class implements all the attributes along the inheritance chain.
- Each
classis decorated with the[Class]C# attribute that documents theclass(read more about the attributes in the sections below). - Each property is decorated with the
[Property]C# attribute. - Each property is decorated with the
[Implements]C# attribute that states which interface the property belongs to. - In case the property is subsetted it is decorated with the
[SubsettedProperty]C# attribute. - In case the property is redefined by another property it is decorated with the
[RedefinedByProperty]C# attribute. - In case the property is a redefinition of another property it is decorated with the
[RedefinedProperty]C# attribute. - In case the property is a derived property it only has a getter that resolves to a hand-coded method that is named using the name of the property prefixed with the word
Query. These hand-coded methods are implemented as Extension methods in the classes found in the Extend project folder. - In case the property is a redefined property it is implemented as an explicit interface implementation. The getter and setter will throw in an InvalidOperation exception.
The generated classes can be found in the
AutoGenClassesfolder.
In UML, ownership refers to the relationship where one element (the owner) is responsible for the existence, lifecycle, or behavior of another element (the owned element). This is typically implemented using composite aggregation.
The top level class from which everything derives, called Element, has two attributes that capture this concept:
- Owner [0..1]: The Element that owns this Element {readonly, derived, derived-union}.
- OwnedElement [0..*]: The Elements owned by this Element {readonly, derived, derived-union}.
Since the Owner property is {readonly, derived, derived-union}, it cannot be set. When reading an XMI document that contains a UML model, the ownership is encoded. The partial IElement interface has an extra hand-coded property called Possessor property of type IElement used to set the ownership relation when read from the XMI document. The IElement.Owner derived property returns the set Possesor or null if it is not set.
The OwnedElement property, and all composite aggregations found in the UML model, are implemted using the IContainerList<T> interface. When an instance of T is added to a IContainerList<T> the owner is immediately set as well using the Possessor property.
The IXmiElement interface and XmiElement are hand-coded classes that facilitate, together with the XmiElementCache and Assembler, processing a UML model from a data source such as an XMI file and returning a fully dereferenced object graph of a UML model.
Each class in the UML model derives from XmiElement. The XmiElement class exposes the following properties:
- XmiId: the unique identifier of the Element in the XMI document.
- XmiGuid: the GUID unique identifier of the Element in the XMI document.
- XmiType: the name of the XMI type
- XmiNamespaceUri: the namespace Uri of the XMi element that it belongs to.
- DocumentName: the name of the XMI document(or other data-source)
- FullyQualifiedIdentifier: The Fully Qualified Identifier which is the concatenation of the DocumentName and the XmiId, separated by the
#character. This identiefier is used to store theXmiElementin theXmiElementCache. - SingleValueReferencePropertyIdentifiers: a dictionary of single-valued reference properties and the associated unique identifiers. The key is the name of the property, the value is the unique identifier (XmiId) of the referenced Type.
- MultiValueReferencePropertyIdentifiers: a dictionary of multivalued reference properties and the associated unique identifiers. The key is the name of the property, the values are the unique identifiers (XmiId) of the referenced Types.
- Cache: The
XmiElementCachethat theXmiElementis stored in.
The XmiElementCache and Assembler work in unison to dereference an object graph. This is necessary when the reference properties of the IXmiElement instances (the UML classes) are not yet pointers to other instances, but are encoded in the SingleValueReferencePropertyIdentifiers or MultiValueReferencePropertyIdentifiers AND all the instances are stored in the IXmiElementCache.
The Assembler exposes the Synchronize method that iterates through all the entries in the SingleValueReferencePropertyIdentifiers and MultiValueReferencePropertyIdentifiers of all the XmiElement that are stored in the XmiElementCache and updates the single-valued and multi-valued properties of these instances. Both the SingleValueReferencePropertyIdentifiers and the MultiValueReferencePropertyIdentifiers properties are Dictionaries where each entry is a key-value pair that contains the naem of the property, the values are either single or multiple unique identifiers, the XmiElement.XmiId property, of other XmiElement instances. Based on the DocumentName (the name of the XMI document the XmiElement was read from), and the XmiId, the associated XmiElement can be retrieved from the XmiElementCache.
The uml4net library/project contains a number of C# attributes that are used to decorate interfaces, classes and properties to make these self documenting and to support precise reflection. The following C# attributes exist:
- ClassAttribute: used to decorate an interface and class to make it explicit whether it is abstract, a final specialisation or whether it is active.
- ImplementsAttribute: used to decorate a property and make it explicit which interface owns this property
- PropertyAttribute: used to decorate a property and make it explicit what kind of aggregation is used, the multiplicity and other features that are part of the UML model {IsOrdered, IsReadOnly, IsDerived, IsDerivedUnion, IsUnique, DefaultValue}.
- RedefinedByPropertyAttribute: used to decorate a property in case it has been redefined by another property.
- RedefinedPropertyAttribute: used to decorate a property in case it redefines another property.
- SubsettedPropertyAttribute: used to decorate a property in case it subsets another property.
The
PropertyAttributeis used by theAssemblerto process theSingleValueReferencePropertyIdentifiersandMultiValueReferencePropertyIdentifiersand set the values XmiElement properties.
copyright @ Starion Group S.A.