init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sda.Modeling.Provider.Classes
|
||||
{
|
||||
internal class AssociationElement : Extendable, IAssociation
|
||||
{
|
||||
public IStartRole StartRole
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IEndRole EndRole
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IModel Model
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public IClass AssociationClass
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sda.Modeling.Provider.Classes
|
||||
{
|
||||
internal class AttributeElement : Extendable, IAttribute
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string Type
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string DefaultValue
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IClass Class
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sda.Modeling.Provider.Classes
|
||||
{
|
||||
internal class ClassElement : Extendable, IClass
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public ICollection<IOperation> Operations
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public ICollection<IAttribute> Attributes
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public ICollection<IClass> SubClasses
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IClass SuperClass
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public ICollection<IRole> Roles
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IPackage Package
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IIdentified Generalization
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sda.Modeling.Provider.Classes
|
||||
{
|
||||
internal class EndRoleElement : Role, IEndRole
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sda.Modeling.Provider.Classes
|
||||
{
|
||||
internal abstract class Extendable : Versionable, IExtendable
|
||||
{
|
||||
public ICollection<IStereotype> Stereotypes
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public ICollection<ITagValuePair> TagValues
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sda.Modeling.Provider.Classes
|
||||
{
|
||||
sealed class Identified : IIdentified
|
||||
{
|
||||
public long LocalId { get; set; }
|
||||
|
||||
public Identified(long localId)
|
||||
{
|
||||
LocalId = localId;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sda.Modeling.Provider.Classes
|
||||
{
|
||||
internal class ModelElement : IModel
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public ICollection<IPackage> Packages
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public ICollection<IAssociation> Associations
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sda.Modeling.Provider.Classes
|
||||
{
|
||||
internal class OperationElement : Extendable, IOperation
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public ICollection<IParameter> Parameters
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IClass Class
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sda.Modeling.Provider.Classes
|
||||
{
|
||||
internal class PackageElement : Extendable, IPackage
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public ICollection<IClass> Classes
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IModel Model
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IPackage Parent
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public ICollection<IPackage> Children
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sda.Modeling.Provider.Classes
|
||||
{
|
||||
internal class ParameterElement : Extendable, IParameter
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string Type
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string Direction
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IOperation Operation
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sda.Modeling.Provider.Classes
|
||||
{
|
||||
internal abstract class Role : Versionable, IRole
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string Multiplicity
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public bool IsNavigable
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IClass Class
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IAssociation Association
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sda.Modeling.Provider.Classes
|
||||
{
|
||||
internal class StartRoleElement : Role, IStartRole
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sda.Modeling.Provider.Classes
|
||||
{
|
||||
internal class Stereotype : IStereotype
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sda.Modeling.Provider.Classes
|
||||
{
|
||||
internal class TagValuePair : ITagValuePair
|
||||
{
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string Value
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sda.Modeling.Provider.Classes
|
||||
{
|
||||
internal abstract class Versionable : IVersionable
|
||||
{
|
||||
public string Author
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string Documentation
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string GlobalId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public long LocalId
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string Version
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace Sda.Modeling.Provider
|
||||
{
|
||||
public interface IModelProvider
|
||||
{
|
||||
IModel Model(params string[] packages);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,614 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
using Sda.Modeling.Provider.Classes;
|
||||
|
||||
namespace Sda.Modeling.Provider.Providers.Xmi
|
||||
{
|
||||
// ReSharper disable PossibleNullReferenceException
|
||||
public sealed class XmiModelProvider : IModelProvider
|
||||
{
|
||||
static readonly XNamespace _umlNs = "omg.org/UML1.3";
|
||||
static readonly Regex _alias = new Regex("alias=(?<alias>\\d+);", RegexOptions.Singleline | RegexOptions.Compiled);
|
||||
|
||||
readonly ModelElement _model;
|
||||
|
||||
public XmiModelProvider(XDocument modelDocument, params XDocument[] packageDocuments)
|
||||
{
|
||||
XElement modelElement =
|
||||
modelDocument.Root
|
||||
.Element("XMI.content")
|
||||
.Element(_umlNs + "Model");
|
||||
_model = new ModelElement
|
||||
{
|
||||
Name = modelElement.Attribute("name").Value,
|
||||
Associations = new List<IAssociation>(),
|
||||
Packages = new List<IPackage>(),
|
||||
};
|
||||
XElement owned;
|
||||
if ((owned = modelElement.Element(_umlNs + "Namespace.ownedElement")) == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ResolveMainModelElements(owned);
|
||||
foreach (var subOwned in
|
||||
packageDocuments
|
||||
.Select(pd =>
|
||||
pd.Root
|
||||
.Element("XMI.content")
|
||||
.Element(_umlNs + "Model")
|
||||
.Element(_umlNs + "Namespace.ownedElement"))
|
||||
.Where(o => o != null))
|
||||
{
|
||||
ResolveMainModelElements(subOwned);
|
||||
}
|
||||
ResolveModelElements(owned);
|
||||
foreach (var subOwned in
|
||||
packageDocuments
|
||||
.Select(pd =>
|
||||
pd.Root
|
||||
.Element("XMI.content")
|
||||
.Element(_umlNs + "Model")
|
||||
.Element(_umlNs + "Namespace.ownedElement"))
|
||||
.Where(o => o != null))
|
||||
{
|
||||
ResolveModelElements(subOwned);
|
||||
}
|
||||
foreach (var generalizationElement in
|
||||
packageDocuments
|
||||
.Select(pd =>
|
||||
pd.Root
|
||||
.Element("XMI.content")
|
||||
.Element(_umlNs + "Model")
|
||||
.Element(_umlNs + "Namespace.ownedElement"))
|
||||
.Where(oe => oe != null)
|
||||
.SelectMany(oe =>
|
||||
oe
|
||||
.Elements(_umlNs + "Package")
|
||||
.SelectMany(pe =>
|
||||
pe
|
||||
.Element(_umlNs + "Namespace.ownedElement")
|
||||
.Elements(_umlNs + "Generalization"))))
|
||||
{
|
||||
var superTypeId = FormatGuid(generalizationElement.Attribute("supertype").Value);
|
||||
var subTypeId = FormatGuid(generalizationElement.Attribute("subtype").Value);
|
||||
var superType = _model.Packages.SelectMany(p => p.Classes).Single(c => c.GlobalId == superTypeId);
|
||||
var subType = _model.Packages.SelectMany(p => p.Classes).Single(c => c.GlobalId == subTypeId);
|
||||
if (subType.SuperClass != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
subType.SuperClass = superType;
|
||||
superType.SubClasses.Add(subType);
|
||||
}
|
||||
foreach (var associationElement in
|
||||
packageDocuments
|
||||
.Select(pd =>
|
||||
pd.Root
|
||||
.Element("XMI.content")
|
||||
.Element(_umlNs + "Model")
|
||||
.Element(_umlNs + "Namespace.ownedElement"))
|
||||
.Where(oe => oe != null)
|
||||
.SelectMany(oe =>
|
||||
oe
|
||||
.Elements(_umlNs + "Package")
|
||||
.SelectMany(pe =>
|
||||
pe
|
||||
.Element(_umlNs + "Namespace.ownedElement")
|
||||
.Elements(_umlNs + "Association"))))
|
||||
{
|
||||
if (GetDescriptor(associationElement, "associationclass") == null)
|
||||
{
|
||||
string globalId = associationElement.Attribute("xmi.id").Value;
|
||||
ResolveAssociation(associationElement);
|
||||
ResolveRoles(_model.Associations.Single(a => a.GlobalId == globalId), associationElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
string globalId = FormatGuid(GetDescriptor(associationElement, "associationclass"));
|
||||
var association = _model.Associations.Single(a => a.AssociationClass != null && a.AssociationClass.GlobalId == globalId);
|
||||
GetAssocElement(associationElement, association);
|
||||
ResolveRoles(association, associationElement);
|
||||
}
|
||||
}
|
||||
foreach (var tag in
|
||||
packageDocuments
|
||||
.SelectMany(pd =>
|
||||
pd.Root
|
||||
.Element("XMI.content")
|
||||
.Elements(_umlNs + "TaggedValue")))
|
||||
{
|
||||
var globalId = tag.Attribute("modelElement").Value;
|
||||
var classes = _model.Packages.SelectMany(p => p.Classes).Where(c => c.GlobalId == globalId);
|
||||
foreach (var @class in classes)
|
||||
{
|
||||
@class.TagValues.Add(new TagValuePair { Value = tag.Attribute("value").Value, Name = tag.Attribute("tag").Value });
|
||||
}
|
||||
}
|
||||
foreach (XElement tagElement in
|
||||
packageDocuments
|
||||
.Concat(new[] { modelDocument })
|
||||
.Select(pd => pd.Root.Element("XMI.content"))
|
||||
.SelectMany(e => e.Elements(_umlNs + "TaggedValue")))
|
||||
{
|
||||
string classId = FormatGuid(tagElement.Attribute("modelElement").Value);
|
||||
IClass @class = _model.Packages.SelectMany(p => p.Classes).SingleOrDefault(c => c.GlobalId == classId);
|
||||
if (@class != null)
|
||||
{
|
||||
@class.TagValues.Add(new TagValuePair
|
||||
{
|
||||
Name = tagElement.Attribute("tag").Value,
|
||||
Value = tagElement.Attribute("value").Value
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ResolveRoles(IAssociation association, XContainer associationElement)
|
||||
{
|
||||
foreach (var end in associationElement.Element(_umlNs + "Association.connection").Elements())
|
||||
{
|
||||
var classId = FormatGuid(end.Attribute("type").Value);
|
||||
var @class = _model.Packages.SelectMany(p => p.Classes).SingleOrDefault(c => c.GlobalId == classId);
|
||||
if (@class == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var endName = end.Attribute("name");
|
||||
var roleName = endName == null ? "" : endName.Value;
|
||||
var multiplicityAttribute = end.Attribute("multiplicity");
|
||||
if (multiplicityAttribute == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var multiplicity = multiplicityAttribute.Value;
|
||||
var isNavigable = bool.Parse(end.Attribute("isNavigable").Value);
|
||||
Role role;
|
||||
long localId;
|
||||
var eaEnd = GetDescriptor(end, "ea_end");
|
||||
if (eaEnd == "source")
|
||||
{
|
||||
var style = GetDescriptor(end, @"sourcestyle");
|
||||
if (string.IsNullOrEmpty(style)
|
||||
||
|
||||
!_alias.IsMatch(style)
|
||||
||
|
||||
!long.TryParse(_alias.Match(style).Result("${alias}"), out localId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
role = new StartRoleElement
|
||||
{
|
||||
Association = association,
|
||||
Class = @class,
|
||||
IsNavigable = isNavigable,
|
||||
Multiplicity = multiplicity,
|
||||
Name = roleName,
|
||||
LocalId = localId,
|
||||
GlobalId = "EA_" + localId,
|
||||
};
|
||||
association.StartRole = (StartRoleElement)role;
|
||||
}
|
||||
else
|
||||
{
|
||||
var style = GetDescriptor(end, @"deststyle");
|
||||
if (string.IsNullOrEmpty(style)
|
||||
||
|
||||
!_alias.IsMatch(style)
|
||||
||
|
||||
!long.TryParse(_alias.Match(style).Result("${alias}"), out localId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
role = new EndRoleElement
|
||||
{
|
||||
Association = association,
|
||||
Class = @class,
|
||||
IsNavigable = isNavigable,
|
||||
Multiplicity = multiplicity,
|
||||
Name = roleName,
|
||||
LocalId = localId,
|
||||
GlobalId = "EA_" + localId,
|
||||
};
|
||||
association.EndRole = (EndRoleElement)role;
|
||||
}
|
||||
@class.Roles.Add(role);
|
||||
}
|
||||
}
|
||||
|
||||
void ResolvePackageGeneralizationElements(XContainer packageElements)
|
||||
{
|
||||
var elements = packageElements.Elements().ToList();
|
||||
foreach (var childPackageElement in elements.Where(e => e.Name == _umlNs + "Package"))
|
||||
{
|
||||
ResolvePackageGeneralization(childPackageElement);
|
||||
}
|
||||
foreach (var generalizationElement in elements.Where(e => e.Name == _umlNs + "Generalization"))
|
||||
{
|
||||
var superTypeId = FormatGuid(generalizationElement.Attribute("supertype").Value);
|
||||
var subTypeId = FormatGuid(generalizationElement.Attribute("subtype").Value);
|
||||
var superType = _model.Packages.SelectMany(p => p.Classes).Single(c => c.GlobalId == superTypeId);
|
||||
var subType = _model.Packages.SelectMany(p => p.Classes).Single(c => c.GlobalId == subTypeId);
|
||||
// ReSharper disable once InvertIf
|
||||
if (subType.SuperClass == null)
|
||||
{
|
||||
var styleex = GetDescriptor(generalizationElement, "styleex");
|
||||
long localId;
|
||||
if (!string.IsNullOrEmpty(styleex)
|
||||
&&
|
||||
_alias.IsMatch(styleex)
|
||||
&&
|
||||
long.TryParse(_alias.Match(styleex).Result("${alias}"), out localId))
|
||||
{
|
||||
subType.Generalization = new Identified(localId);
|
||||
}
|
||||
subType.SuperClass = superType;
|
||||
superType.SubClasses.Add(subType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ResolvePackageGeneralization(XContainer element)
|
||||
{
|
||||
var owned = element.Element(_umlNs + "Namespace.ownedElement");
|
||||
if (owned != null)
|
||||
{
|
||||
ResolvePackageGeneralizationElements(owned);
|
||||
}
|
||||
}
|
||||
|
||||
void ResolvePackageAssociationElements(XContainer packageElements)
|
||||
{
|
||||
var elements = packageElements.Elements().ToList();
|
||||
foreach (var childPackageElement in elements.Where(e => e.Name == _umlNs + "Package"))
|
||||
{
|
||||
ResolvePackageAssoc(childPackageElement);
|
||||
}
|
||||
foreach (var associationElement in elements.Where(e => e.Name == _umlNs + "Association"))
|
||||
{
|
||||
string globalId = associationElement.Attribute("xmi.id").Value;
|
||||
ResolveAssociation(associationElement);
|
||||
// ReSharper disable once AccessToModifiedClosure
|
||||
var association = _model.Associations.Single(a => a.GlobalId == globalId);
|
||||
ResolveRoles(association, associationElement);
|
||||
// ReSharper disable once InvertIf
|
||||
if (GetDescriptor(associationElement, "associationclass") != null)
|
||||
{
|
||||
globalId = FormatGuid(GetDescriptor(associationElement, "associationclass"));
|
||||
// ReSharper disable once AccessToModifiedClosure
|
||||
var @class = _model.Packages.SelectMany(p => p.Classes).Single(c => c.GlobalId == globalId);
|
||||
association.AssociationClass = @class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ResolvePackageAssoc(XContainer element)
|
||||
{
|
||||
var owned = element.Element(_umlNs + "Namespace.ownedElement");
|
||||
if (owned != null)
|
||||
{
|
||||
ResolvePackageAssociationElements(owned);
|
||||
}
|
||||
}
|
||||
|
||||
void ResolveMainModelElements(XContainer modelElements)
|
||||
{
|
||||
foreach (var packageElement in modelElements.Elements().Where(e => e.Name == _umlNs + "Package"))
|
||||
{
|
||||
ResolvePackage(packageElement, null);
|
||||
}
|
||||
}
|
||||
|
||||
void ResolvePackageElements(XContainer packageElements, IPackage parent)
|
||||
{
|
||||
var elements = packageElements.Elements().ToList();
|
||||
foreach (var childPackageElement in elements.Where(e => e.Name == _umlNs + "Package"))
|
||||
{
|
||||
ResolvePackage(childPackageElement, parent);
|
||||
}
|
||||
foreach (var classElement in elements.Where(e => e.Name == _umlNs + "Class"))
|
||||
{
|
||||
ResolveClass(classElement, parent);
|
||||
}
|
||||
}
|
||||
|
||||
void ResolveModelElements(XContainer modelElements)
|
||||
{
|
||||
foreach (var packageElement in modelElements.Elements().Where(e => e.Name == _umlNs + "Package"))
|
||||
{
|
||||
ResolvePackageAssoc(packageElement);
|
||||
}
|
||||
foreach (var packageElement in modelElements.Elements().Where(e => e.Name == _umlNs + "Package"))
|
||||
{
|
||||
ResolvePackageGeneralization(packageElement);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ResolveAssociation(XElement associationElement)
|
||||
{
|
||||
var association = new AssociationElement();
|
||||
GetAssocElement(associationElement, association);
|
||||
if (_model.Associations.Any(a => a.GlobalId == association.GlobalId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_model.Associations.Add(association);
|
||||
}
|
||||
|
||||
void GetAssocElement(XElement associationElement, IAssociation association)
|
||||
{
|
||||
var globalId = associationElement.Attribute("xmi.id").Value;
|
||||
var styleex = GetDescriptor(associationElement, "styleex");
|
||||
long localId;
|
||||
if (string.IsNullOrEmpty(styleex)
|
||||
||
|
||||
!_alias.IsMatch(styleex)
|
||||
||
|
||||
!long.TryParse(_alias.Match(styleex).Result("${alias}"), out localId))
|
||||
{
|
||||
localId = -Int64.Parse(GetDescriptor(associationElement, "ea_localid"));
|
||||
}
|
||||
association.Author = GetDescriptor(associationElement, "author");
|
||||
association.Documentation = GetDescriptor(associationElement, "documentation");
|
||||
association.GlobalId = globalId;
|
||||
association.LocalId = localId;
|
||||
association.Name = associationElement.Attribute("name") != null ?
|
||||
associationElement.Attribute("name").Value :
|
||||
"";
|
||||
association.Model = _model;
|
||||
association.Stereotypes = GetStereoTypes(associationElement);
|
||||
association.TagValues = GetTagValues(associationElement);
|
||||
association.Version = GetDescriptor(associationElement, "version");
|
||||
}
|
||||
|
||||
void ResolvePackage(XElement element, IPackage parent)
|
||||
{
|
||||
var name = element.Attribute("name").Value;
|
||||
var package = _model.Packages.SingleOrDefault(p => p.Name == name);
|
||||
if (package == null)
|
||||
{
|
||||
var globalId = element.Attribute("xmi.id").Value;
|
||||
string alias = GetDescriptor(element, "alias");
|
||||
long localId;
|
||||
if (string.IsNullOrEmpty(alias) || !long.TryParse(alias, out localId))
|
||||
{
|
||||
localId = Math.Abs(name.GetHashCode());
|
||||
}
|
||||
package = new PackageElement
|
||||
{
|
||||
Author = GetDescriptor(element, "author"),
|
||||
Documentation = GetDescriptor(element, "documentation"),
|
||||
GlobalId = globalId,
|
||||
Children = new List<IPackage>(),
|
||||
Classes = new List<IClass>(),
|
||||
LocalId = localId,
|
||||
Model = _model,
|
||||
Name = name,
|
||||
Parent = parent,
|
||||
Stereotypes = GetStereoTypes(element),
|
||||
TagValues = GetTagValues(element),
|
||||
Version = GetDescriptor(element, "version"),
|
||||
};
|
||||
_model.Packages.Add(package);
|
||||
if (parent != null)
|
||||
{
|
||||
parent.Children.Add(package);
|
||||
}
|
||||
}
|
||||
var owned = element.Element(_umlNs + "Namespace.ownedElement");
|
||||
if (owned != null)
|
||||
{
|
||||
ResolvePackageElements(owned, package);
|
||||
}
|
||||
}
|
||||
|
||||
public IModel Model(params string[] packages)
|
||||
{
|
||||
return _model;
|
||||
}
|
||||
|
||||
static string FormatGuid(string guid)
|
||||
{
|
||||
return FormatGuid(Guid.Parse(guid.Substring(5).Replace('_', '-')));
|
||||
}
|
||||
|
||||
static string FormatGuid(Guid guid)
|
||||
{
|
||||
string s = guid.ToString("D");
|
||||
return
|
||||
s.Substring(0, 14).ToUpperInvariant() +
|
||||
s.Substring(14, 4).ToLowerInvariant() +
|
||||
s.Substring(18).ToUpperInvariant();
|
||||
}
|
||||
|
||||
static string MapType(string type)
|
||||
{
|
||||
switch (type ?? "")
|
||||
{
|
||||
case "XmlString":
|
||||
return "Object";
|
||||
default:
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
static void ResolveClass(XElement element, IPackage parent)
|
||||
{
|
||||
if (element.Attribute("name") == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var name = element.Attribute("name").Value;
|
||||
var globalId = FormatGuid(element.Attribute("xmi.id").Value);
|
||||
if (parent.Classes.Any(c => c.Name == name))
|
||||
{
|
||||
throw new XmiProviderException(string.Format(CultureInfo.InvariantCulture, "Duplicate class by name {0}!", name));
|
||||
}
|
||||
string alias = GetDescriptor(element, "alias");
|
||||
long localId;
|
||||
if (string.IsNullOrEmpty(alias) || !long.TryParse(alias, out localId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var @class = new ClassElement
|
||||
{
|
||||
Attributes = new List<IAttribute>(),
|
||||
Author = GetDescriptor(element, "author"),
|
||||
Documentation = GetDescriptor(element, "documentation"),
|
||||
GlobalId = globalId,
|
||||
LocalId = localId,
|
||||
Name = name,
|
||||
Operations = new List<IOperation>(),
|
||||
Package = parent,
|
||||
Roles = new List<IRole>(),
|
||||
Stereotypes = GetStereoTypes(element),
|
||||
SubClasses = new List<IClass>(),
|
||||
SuperClass = null,
|
||||
TagValues = GetTagValues(element),
|
||||
Version = GetDescriptor(element, "version"),
|
||||
};
|
||||
ResolveAttributes(element, @class);
|
||||
ResolveOperations(element, @class);
|
||||
parent.Classes.Add(@class);
|
||||
}
|
||||
|
||||
static void ResolveAttributes(XContainer element, IClass parent)
|
||||
{
|
||||
var classifier = element.Element(_umlNs + "Classifier.feature");
|
||||
if (classifier == null)
|
||||
return;
|
||||
foreach (var attributeElement in classifier.Elements(_umlNs + "Attribute"))
|
||||
{
|
||||
var defaultDescriptor =
|
||||
attributeElement
|
||||
.Element(_umlNs + "Attribute.initialValue")
|
||||
.Element(_umlNs + "Expression")
|
||||
.Attribute("body");
|
||||
string alias = GetDescriptor(attributeElement, "style");
|
||||
long localId;
|
||||
if (string.IsNullOrEmpty(alias) || !long.TryParse(alias, out localId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
parent.Attributes.Add(new AttributeElement
|
||||
{
|
||||
Author = GetDescriptor(attributeElement, "author"),
|
||||
Class = parent,
|
||||
DefaultValue = defaultDescriptor == null ? null : defaultDescriptor.Value,
|
||||
Documentation = GetDescriptor(attributeElement, "description"),
|
||||
GlobalId = GetDescriptor(attributeElement, "ea_guid"),
|
||||
LocalId = localId,
|
||||
Name = attributeElement.Attribute("name").Value,
|
||||
Stereotypes = GetStereoTypes(attributeElement),
|
||||
TagValues = GetTagValues(attributeElement),
|
||||
Type = GetDescriptor(attributeElement, "type"),
|
||||
Version = GetDescriptor(attributeElement, "version"),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static void ResolveOperations(XContainer element, IClass parent)
|
||||
{
|
||||
var classifier = element.Element(_umlNs + "Classifier.feature");
|
||||
if (classifier == null)
|
||||
return;
|
||||
foreach (var operationElement in classifier.Elements(_umlNs + "Operation"))
|
||||
{
|
||||
string alias = GetDescriptor(operationElement, "style");
|
||||
long localId;
|
||||
if (string.IsNullOrEmpty(alias) || !long.TryParse(alias, out localId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var operation = new OperationElement
|
||||
{
|
||||
Author = GetDescriptor(operationElement, "author"),
|
||||
Class = parent,
|
||||
Documentation = GetDescriptor(operationElement, "documentation"),
|
||||
GlobalId = FormatGuid(Guid.Parse(GetDescriptor(operationElement, "ea_guid"))),
|
||||
LocalId = localId,
|
||||
Name = operationElement.Attribute("name").Value,
|
||||
Parameters = new List<IParameter>(),
|
||||
Stereotypes = GetStereoTypes(operationElement),
|
||||
TagValues = GetTagValues(operationElement),
|
||||
Version = GetDescriptor(operationElement, "version"),
|
||||
};
|
||||
parent.Operations.Add(operation);
|
||||
foreach (var parameterElement in operationElement.Element(_umlNs + "BehavioralFeature.parameter").Elements())
|
||||
{
|
||||
operation.Parameters.Add(new ParameterElement
|
||||
{
|
||||
Author = GetDescriptor(parameterElement, "author"),
|
||||
Direction = parameterElement.Attribute("kind").Value,
|
||||
Documentation = GetDescriptor(parameterElement, "documentation"),
|
||||
GlobalId = GetDescriptor(parameterElement, "ea_guid"),
|
||||
LocalId = 0,
|
||||
Name = parameterElement.Attribute("name") == null ? null : parameterElement.Attribute("name").Value,
|
||||
Operation = operation,
|
||||
Stereotypes = GetStereoTypes(parameterElement),
|
||||
TagValues = GetTagValues(parameterElement),
|
||||
Type = MapType(GetDescriptor(parameterElement, "type")),
|
||||
Version = GetDescriptor(parameterElement, "version"),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ICollection<ITagValuePair> GetTagValues(XContainer element)
|
||||
{
|
||||
return
|
||||
element.Element(_umlNs + "ModelElement.taggedValue")
|
||||
.Elements()
|
||||
.Where(e =>
|
||||
e.Attribute("xmi.id") != null
|
||||
||
|
||||
e.Attribute("tag").Value == @"alias"
|
||||
||
|
||||
e.Attribute("tag").Value == @"type"
|
||||
||
|
||||
e.Attribute("tag").Value == @"version"
|
||||
||
|
||||
e.Attribute("tag").Value == @"style"
|
||||
||
|
||||
e.Attribute("tag").Value == @"styleex"
|
||||
||
|
||||
e.Attribute("tag").Value == @"deststyle"
|
||||
||
|
||||
e.Attribute("tag").Value == @"sourcestyle"
|
||||
||
|
||||
e.Attribute("tag").Value == @"ea_end"
|
||||
||
|
||||
e.Attribute("tag").Value == @"ea_localid"
|
||||
||
|
||||
e.Attribute("tag").Value == @"ea_guid"
|
||||
||
|
||||
e.Attribute("tag").Value == @"stereotype"
|
||||
||
|
||||
e.Attribute("tag").Value == @"associationclass"
|
||||
||
|
||||
e.Attribute("tag").Value == @"author"
|
||||
||
|
||||
e.Attribute("tag").Value == @"documentation"
|
||||
||
|
||||
e.Attribute("tag").Value == @"description")
|
||||
.Select(e => new TagValuePair { Name = e.Attribute("tag").Value, Value = e.Attribute("value").Value, })
|
||||
.Cast<ITagValuePair>()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
static ICollection<IStereotype> GetStereoTypes(XContainer element)
|
||||
{
|
||||
return GetTagValues(element).Where(t => t.Name == "stereotype").Select(t => new Stereotype { Name = t.Value }).Cast<IStereotype>().ToList();
|
||||
}
|
||||
|
||||
static string GetDescriptor(XContainer element, string name)
|
||||
{
|
||||
return GetTagValues(element).Where(t => t.Name == name).Select(t => t.Value).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
// ReSharper restore PossibleNullReferenceException
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Sda.Modeling.Provider.Providers.Xmi
|
||||
{
|
||||
[Serializable]
|
||||
public sealed class XmiProviderException : Exception
|
||||
{
|
||||
public XmiProviderException() { }
|
||||
public XmiProviderException(string message) : base(message) { }
|
||||
public XmiProviderException(string message, Exception inner) : base(message, inner) { }
|
||||
XmiProviderException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{CCAC367F-DBE4-4484-9AC1-9A83671AA5FC}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Sda.Modeling.Provider</RootNamespace>
|
||||
<AssemblyName>Sda.Modeling.Provider</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>sn.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Build|AnyCPU'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\Build\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\SharedAssemblyInfo.cs">
|
||||
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Classes\AttributeElement.cs" />
|
||||
<Compile Include="Classes\AssociationElement.cs" />
|
||||
<Compile Include="Classes\ClassElement.cs" />
|
||||
<Compile Include="Classes\Extendable.cs" />
|
||||
<Compile Include="Classes\EndRoleElement.cs" />
|
||||
<Compile Include="Classes\Identified.cs" />
|
||||
<Compile Include="Classes\ParameterElement.cs" />
|
||||
<Compile Include="Classes\Versionable.cs" />
|
||||
<Compile Include="Classes\ModelElement.cs" />
|
||||
<Compile Include="Classes\OperationElement.cs" />
|
||||
<Compile Include="Classes\PackageElement.cs" />
|
||||
<Compile Include="Classes\Role.cs" />
|
||||
<Compile Include="Classes\StartRoleElement.cs" />
|
||||
<Compile Include="Classes\Stereotype.cs" />
|
||||
<Compile Include="Classes\TagValuePair.cs" />
|
||||
<Compile Include="Providers\Xmi\XmiModelProvider.cs" />
|
||||
<Compile Include="IModelProvider.cs" />
|
||||
<Compile Include="Providers\Xmi\XmiProviderException.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="sn.snk" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SDA.Modeling\SDA.Modeling.csproj">
|
||||
<Project>{43e28ccf-4918-4ccd-b1bf-9bbfcf43c4cc}</Project>
|
||||
<Name>SDA.Modeling</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
BIN
Tools/CodeGeneration/src/Sda.Modeling.Provider/sn.snk
Normal file
BIN
Tools/CodeGeneration/src/Sda.Modeling.Provider/sn.snk
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue