Giter Club home page Giter Club logo

nmf's People

Contributors

5argan avatar bwanner avatar can-oezkan avatar chrish07 avatar frederikp avatar georghinkel avatar lukasboersma avatar lukeiam avatar mlessmann avatar nikoant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nmf's Issues

Deserialization of ecore with inner text

Ecore models generated from XML schema files can contain "dummy" attributes to catch inner text of elements. NMF does not currently support reading element inner text. For example, Simulink models have "P" elements with inner text:

<Model>
    <P Name="MdlSubVersion">7</P>
    <P Name="SavedCharacterEncoding">windows-1252</P>
    ...
</Model>

Where the derived schema is:

<xs:element name="P">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:string">   <!-- This element has inner text of type string -->
        <xs:attribute type="xs:string" name="Name"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

Which, according to this, generates the following Ecore model where the value attribute is used to collect the inner text:

<eClassifiers xsi:type="ecore:EClass" name="PType">
  <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
    <details key="name" value="P_._type"/>
    <details key="kind" value="simple"/>
  </eAnnotations>
  <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">  <!-- This is the inner text attribute -->
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="name" value=":0"/>      <!-- Docs imply name->:0 with kind->simple denotes this attribute is the inner text -->
      <details key="kind" value="simple"/>
    </eAnnotations>
  </eStructuralFeatures>
  <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="kind" value="attribute"/>
      <details key="name" value="Name"/>
      <details key="namespace" value="##targetNamespace"/>
    </eAnnotations>
  </eStructuralFeatures>
</eClassifiers>

I can catch the inner text as XmlNodeType.Text in XmiSerializer.InitializeElementProperties, but it is not clear how I would extend/modify IPropertySerializationInfo to support this behavior or if this is even the appropriate place to handle this case. Any guidance is appreciated.
Thank you,
Chris

Ecore metamodel default values not taken into account (e.g. "unique=true")

The default values of the attributes of the Ecore metamodel seem to not be taken into account (e.g. unique=true);

For example:

  • In Eclipse, I create an Ecore model with a single class and with an EReference with unique=true using the built-in editor. In the serialized ecore file, it results in this line: <eStructuralFeatures xsi:type="ecore:EReference" name="uniqueOrdered" upperBound="-1" eType="#//Test1"/>
    in which we do not see explicitly that unique is set to true, because true is the default value in the Ecore metamodel.
  • When importing the Ecore file using NMeta, I can see in the resulting NMeta metamodel that unique is set to null, and not to true
  • I generated the C# code for this imported metamodel. When using the generated code, the EReference behaves as if unique=false, probably because it was nullin the NMeta metamodel.

To bypass the problem, I have tried adding explicitly unique = true manually in the Ecore file I was importing, and then everything worked as expected.

Please find attached a small project with both Ecore files (one with unique=true implicit , and another with unique=true explicit in the file), and a small test suite to show what I have tried, expected, and observed.

TestUnique.zip

EDataType could not be resolved

Hello,
I have a simple ecore and want to convert nmf. When i try to Ecore2Code command, this error shows up

An error occurred reading the Ecore file. The error message was: The reference ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String could not be resolved

I want to use nmf because i have a much bigger ecore for my project but if an error occured in this small ecore, my file won't passed neither.

By the way sample ecore which i tried is below

Regards
Umut

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="library" nsURI="http://www.example.eclipse.org/Library" nsPrefix="library">
  <eClassifiers xsi:type="ecore:EClass" name="Book">
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="name" value="Book"/>
      <details key="kind" value="elementOnly"/>
    </eAnnotations>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="title" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="title"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="pages" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Int"
        unsettable="true">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="pages"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="category" lowerBound="1"
        eType="#//BookCategory" unsettable="true">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="category"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EReference" name="author" lowerBound="1"
        eType="#//Writer" eOpposite="#//Writer/books">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="author"/>
      </eAnnotations>
    </eStructuralFeatures>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EEnum" name="BookCategory">
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="name" value="BookCategory"/>
    </eAnnotations>
    <eLiterals name="Mystery"/>
    <eLiterals name="ScienceFiction" value="1"/>
    <eLiterals name="Biography" value="2"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EDataType" name="BookCategoryObject" instanceClassName="org.eclipse.emf.common.util.Enumerator">
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="name" value="BookCategory:Object"/>
      <details key="baseType" value="BookCategory"/>
    </eAnnotations>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="DocumentRoot">
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="name" value=""/>
      <details key="kind" value="mixed"/>
    </eAnnotations>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="mixed" unique="false" upperBound="-1"
        eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="elementWildcard"/>
        <details key="name" value=":mixed"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EReference" name="xMLNSPrefixMap" upperBound="-1"
        eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEntry"
        transient="true" containment="true" resolveProxies="false">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="attribute"/>
        <details key="name" value="xmlns:prefix"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EReference" name="xSISchemaLocation" upperBound="-1"
        eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEntry"
        transient="true" containment="true" resolveProxies="false">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="attribute"/>
        <details key="name" value="xsi:schemaLocation"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EReference" name="book" upperBound="-2" eType="#//Book"
        volatile="true" transient="true" derived="true" containment="true" resolveProxies="false">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="Book"/>
        <details key="namespace" value="##targetNamespace"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="bookCategory" unique="false"
        upperBound="-2" eType="#//BookCategory" volatile="true" transient="true" derived="true">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="BookCategory"/>
        <details key="namespace" value="##targetNamespace"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EReference" name="library" upperBound="-2"
        eType="#//Library" volatile="true" transient="true" derived="true" containment="true"
        resolveProxies="false">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="Library"/>
        <details key="namespace" value="##targetNamespace"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EReference" name="writer" upperBound="-2"
        eType="#//Writer" volatile="true" transient="true" derived="true" containment="true"
        resolveProxies="false">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="Writer"/>
        <details key="namespace" value="##targetNamespace"/>
      </eAnnotations>
    </eStructuralFeatures>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Library">
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="name" value="Library"/>
      <details key="kind" value="elementOnly"/>
    </eAnnotations>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="name"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EReference" name="writers" upperBound="-1"
        eType="#//Writer" containment="true" resolveProxies="false">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="writers"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EReference" name="books" upperBound="-1"
        eType="#//Book" containment="true" resolveProxies="false">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="books"/>
      </eAnnotations>
    </eStructuralFeatures>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Writer">
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="name" value="Writer"/>
      <details key="kind" value="elementOnly"/>
    </eAnnotations>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="name"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EReference" name="books" upperBound="-1"
        eType="#//Book" eOpposite="#//Book/author">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="books"/>
      </eAnnotations>
    </eStructuralFeatures>
  </eClassifiers>
</ecore:EPackage>

Ambiguous type names in generated code when using eSubpackages

I have issues with generating code from ecore files that contain subPackages and type names that are ambiguous with existing classes in the NMF assemblies (for example "IType").

Here is a small example that generates code that does not compile:

<?xml version="1.0" encoding="ASCII"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore">

  <ecore:EPackage
    name="TestPackage"
    nsURI="http://ttc/AmbiguousNames"
    nsPrefix="an">
    <eSubpackages name="p1">
        <eClassifiers xsi:type="ecore:EClass" name="Type"/>
    </eSubpackages>
    <eSubpackages name="p2">
      <eClassifiers xsi:type="ecore:EClass" name="TestClass" abstract="false">
        <eStructuralFeatures
            xsi:type="ecore:EReference"
            name="testFeature"
            eType="#//p1/Type"/>
      </eClassifiers>
    </eSubpackages>
  </ecore:EPackage>
</xmi:XMI>

Using the Ecore2Code tool, this generates the following code:

    public interface ITestClass : IModelElement
    {
        
        [...]
        IType TestFeature
        {
            get;
            set;
        }

        [...]
    }

This does not compile because IType could be both: TestPackage.P1.IType or NMF.Models.Meta.IType. If IType was in the same namespace/subpackage, it would compile.

I think the proper fix would be to always generate the full type name in the code generation (TestPackage.P1.IType instead of IType).

What are your thoughts on this? I could try to fix this and submit a pull request if you give me some hints on where to look.

Ecore to NMeta transform creates incorrect names for serialization

When converting an Ecore model to NMeta (Ecore2Code) the generated classes and properties have the wrong name in the XmlElementNameAttribute attribute. This occurs when the Ecore model is generated from an XML schema. The rules defined in XML Schema To Ecore Mapping specify the serialized name in an eAnnotation where the source is http:///org/eclipse/emf/ecore/util/ExtendedMetaData.

Here is a simplified Ecore model demonstrating the issue:

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="Simulink" nsURI="">
  <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
    <details key="qualified" value="false"/>
  </eAnnotations>
  <eClassifiers xsi:type="ecore:EClass" name="AnnotationDefaultsType">
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="name" value="AnnotationDefaults_._type"/>
      <details key="kind" value="elementOnly"/>
    </eAnnotations>
    <eStructuralFeatures xsi:type="ecore:EReference" name="p" upperBound="-1" eType="#//PType"
        containment="true" resolveProxies="false">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="P"/>
        <details key="namespace" value="##targetNamespace"/>
      </eAnnotations>
    </eStructuralFeatures>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="PType">
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="name" value="P_._type"/>
      <details key="kind" value="simple"/>
    </eAnnotations>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="name" value=":0"/>
        <details key="kind" value="simple"/>
      </eAnnotations>
    </eStructuralFeatures>
  </eClassifiers>
</ecore:EPackage>

Currently in Attribute2Property, Class2Type, and Reference2Property the XmlElementNameAttribute is only added when the input and output names don't match. For the example above the reference to PType in AnnotationDefaultsType will be generated as

[XmlElementNameAttribute("p")]
public IOrderedSetExpression<IPType> P

instead of an uppercase P as specified in the "name" key in the annotation for the reference. Likewise the PType and AnnotationDefaultType classes should be have similar annotations based on their "name" keys (minus the _._type).

Deserialization from unqualified xml

I'm trying to deserialize from an xml document that is unqualified (Simulink diagram) and I get an exception inside GetTypeInfo stating that the type can't be found in namespace "". To create my model I took an existing Ecore model and used Ecore2Code to create the nmeta model. Since the Ecore model was generated from an schema file I had to fix the XMLType references (same as #23). I could not deserialize a model file since it was expecting fully qualified elements, so I modified the meta model by setting Prefix="" in the root Namespace element. I could then serialize manually created models with some added artifacts, but get an exception when deserializing real models. Stepping in the debugger shows the model elements are added to typesByQualifier with a key corresponding to the Uri. If I also set Uri="" then nothing is added to typesByQualifier and I get the same exception. How do I work with a model whose elements are unqualified?

Some names in .ecore file can cause compilation errors

Some names used in a source .ecore file cause compilation errors after following the basic tutorial.

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="model" nsURI="http://ns.ansys.com/test_model" nsPrefix="model">
  <eClassifiers xsi:type="ecore:EClass" name="Element" abstract="true">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
        iD="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Tree" abstract="true" eSuperTypes="#//Element">
    <eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
        eType="#//Element" containment="true"/>
  </eClassifiers>
</ecore:EPackage>

Compilation errors:

1>------ Build started: Project: NMFDemo, Configuration: Debug Any CPU ------
1>C:\Users\nsharp\source\repos\NMFDemo\NMFDemo\Metamodel\ITree.cs(53,41,53,49): warning CS0108: 'ITree.Children' hides inherited member 'IModelElement.Children'. Use the new keyword if hiding was intended.
1>C:\Users\nsharp\source\repos\NMFDemo\NMFDemo\Metamodel\Element.cs(226,51,226,56): error CS0118: 'Model' is a namespace but is used like a type
1>C:\Users\nsharp\source\repos\NMFDemo\NMFDemo\Metamodel\Element.cs(226,67,226,72): error CS0118: 'Model' is a namespace but is used like a type
1>C:\Users\nsharp\source\repos\NMFDemo\NMFDemo\Metamodel\Tree.cs(71,48,71,56): warning CS0114: 'Tree.Children' hides inherited member 'ModelElement.Children'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
1>C:\Users\nsharp\source\repos\NMFDemo\NMFDemo\Metamodel\Tree.cs(82,62,82,70): error CS0102: The type 'Tree' already contains a definition for 'Children'
1>Done building project "NMFDemo.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I am using VS 2019 with NMF-Basic 2.0.176.

Renaming 'model' to 'model2' and 'children' to 'children2' resolves the issue, but changes the DSL.

Running Ecore2Code on .NET core

Hi. I am trying to run NMF to generate .NET code from an Ecore meta-model and then do some constraint checking and transformations in .NET languages. I am planning to use these examples in our upcoming text book (http://mdsebook.org). Unfortunately, I am quite handicapped in .NET universe. Also I am insisting to use .NET Core (as far as I understand), or in no circumstances rely on Visual Studio, as all examples are cross-platform in the book, and I am developing these on Linux.

I installed dotnet-classic on Ubuntu (dotnet --version reports 3.1.201). I created an example project with dotnet new console and added NMF-Basics: dotnet add package NMF-Basics.

Ecore2Code is not added to the PATH, but I can find it in ~/.nuget/packages/nmf-basics/2.0.157/tools/Ecore2Code.exe. Unfortunately, I am unable to run it. dotnet ~/.nuget/packages/nmf-basics/2.0.157/tools/Ecore2Code.exe produces:

A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/home/wasowski/.nuget/packages/nmf-basics/2.0.157/tools/'.
Failed to run as a self-contained app. If this should be a framework-dependent app, add the /home/wasowski/.nuget/packages/nmf-basics/2.0.157/tools/Ecore2Code.runtimeconfig.json file specifying the appropriate framework.

I am almost sure that my .NET handicap is the main issue here, so I apologize for asking basic questions, and hope for some guidance.

Ecore2Code does not handle multiple namespaces

I'm using Ecore2Code to generate classes from a nmf file that contains references to types in another metamodel. Since I use a different namespace when generating code for the referenced metamodel, the output when using resolve creates the wrong namespace for the referenced metamodel. The root cause is Namespace2Namespace.GetName using the DefaultNamespace from the transformation since it has no other information. To workaround this issue I added a Uri to base namespace map in Meta2ClassesTransformation. I modified the syntax of the resolve string to be of the form: uri<@baseNamespace>=file where the bracketed part is optional then populate this map. Namespace2Namespace.GetName then tests if the model Uri is in the map and uses that baseName instead. If this is a reasonable fix this I can submit a pull request.

Support .NET Standard?

I think this framework is really a great work. I see that the project source contains already .NET Standard target. However, it seems that the target platform of this library (version 2.0.148) is only targeting .NET Framework if I get it from NuGet package manager from Visual Studio. We are looking for a platform-neutral modeling framework, i.e. targeting .NET Core. Do you have plan to provide NuGet package for .NET Standard, such that the library can run on both .NET Framework and .NET core? Thanks.

Support for Extrinsic XMI IDs

When resolving an XMI model that uses XMI:ID attributes, NMF successfully resolves references using those IDs. When saving a model, NMF does not use the XMI:ID attribute but rather uses the URL path to the element instead. This causes a problem in round tripping data with other tools that depend on the XMI:ID. Is there a way to set the desired behavior? The goal is to utilize "Extrinsic IDs" as outlined in the EMF modeling guide.

Ecore2Code: Generated reference models have incorrect ModelRepresentationClassAttribute

When generating code for an NMF metamodel that references classes in another metamodel which is not a loaded assembly, the code generator will apply ModelRepresentationClassAttribute corresponding to the LostProperties Uri and not the actual model Uri.
To reproduce this issue, run Ecore2Code as follows with the attached files (change .txt to .nmf): Ecore2Code.exe -f -x -n MetaModels -r http://example.com/MetaModels/ModelA/=.\ModelA.nmf -o . .\ModelB.nmf. This will result in [ModelRepresentationClassAttribute("http://example.com/MetaModels/ModelA/#//ReferencedClass#//ReferencedClass")] instead of [ModelRepresentationClassAttribute("http://example.com/MetaModels/ModelA/#//ReferencedClass")].

So far I've been able determine this is the result of the generator first deserializing ModelB then adding the LostProperty entry for http://example.com/MetaModels/ModelA/#//ReferencedClass which subsequently is used when deserializing/resolving every class in ModelA. It's likely an order of operations issue that could be resolved by generating and loading ModelA first as hinted in #44 but it's not clear to me at this point. @georghinkel Any ideas where to go with this one?

ModelA.txt
ModelB.txt

What is the different between EMF and NMF?

I'm looking for library which like EMF in .NET platform. (Unfortunately, the EMF4NET is dead. )
Is NMF another EMF port on C# ? or Equavalent tool?
What is the different between EMF and NMF?
Could I think of EcoreInterop is a wrapper of Ecore in NMF?
For example:
EPackage ePackage= EcoreInterop.LoadPackageFromFile("myModel.ecore");
var eFactoryInstance = package.EFactoryInstance;

Can I treat ePackage and eFactoryInstance as if they were in EMF?
But I can't find "create(EClass eClass)" method in EFactory, how to create new instance in NMF?

Best regards.

Serialization: Boolean TypeConverter doesn't conform to XML standard

When serializing a model using NMF, boolean values are serialized upper case "True"/"False". As a result, deserialization using other tools/libraries fails. One prominent example would be the default EMF Deserializer.

According to the XML schema specification, only "true", "false" or "1" and "0" are legal values (see https://w3.org/TR/xmlschema-2/#boolean). I don't know if this is an issue for other datatypes as well.
I think NMF should adhere to the specification, at least when serializing.

The .NET framework already provides a static class XmlConvert with several useful functions (XmlConvert.ToString with multiple overloads for serialization, XmlConvert.ToBoolean, XmlConvert.ToInt32 etc. for deserialization) which could be used. Maybe we could wrap these XmlConverts in a TypeConverter and use them instead of the System.ComponentModel ones.

I would be willing to provide a pull request once a decision is made.

Using NMF metamodels in Unity

Hi, I 'm new to this project so I might be doing something fundamentally wrong.

I followed this video tutorial: https://www.youtube.com/watch?v=NIMYuwTltVs&feature=youtu.be (First steps with NMF)

I was able to generate my C# types from my ecore file as well as the *.nmf file.
My issue stems from the fact that I try to now use these generated files in the context of a Unity package, which usually doesn't have an AssemblyInfo.cs file to register the ModelMetadata. I'm a bit lost (since I'm also new to Unity) to understand how I can register the ModelMetadata in a Unity package. Any help would be appreciated.

"Data at root level is invalid. Line 1, position 1."

Hello,

so I went a step back and created a Console Application according to the First Steps video tutorial.

There, I am able to create the Model Repository, but trying to actual resolve a model from the repo, yields this exception. Any clues on why this could be the case?

" at System.Xml.XmlTextReaderImpl.Throw(Exception e)\r\n at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)\r\n at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()\r\n at System.Xml.XmlTextReaderImpl.ParseDocumentContent()\r\n at System.Xml.XmlTextReaderImpl.Read()\r\n at NMF.Serialization.XmlSerializer.CreateRoot(XmlReader reader)\r\n at NMF.Models.Repository.Serialization.ModelSerializer.Deserialize(Stream source, Uri modelUri, IModelRepository repository, Boolean addToRepository)\r\n at NMF.Models.Repository.ModelRepository.Resolve(Uri uri, String hintPath, Boolean loadOnDemand)\r\n at NMF.Models.Repository.ModelRepository.Resolve(String path)\r\n at StoryGraphMetamodelConverter.Program.Main(String[] args) in D:\MyPath\dev\StoryGraphMetamodelConverter\Program.cs:line 15"

Extra Uri entries in MetaRepository.entries?

Hi Georg,

While stepping through the code, there were more Uri entries in the MetaRepository.entries collection than I expected. The "extra" Uri entries get added in the LoadModel function. Some of these entries appear to have an invalid Uri since the followingAttribute.ModelUri is not associated with the deserialized model. Here is contents of the collection while debugging EcoreInterop:
entries
In my case, none of the Uri entries ending in .nmf are accessed and could be removed. Could you help me understand why the Uri of the next attribute in the assembly is associated with the current attributes model? For reference you added this as an additional step in 2c875e3.

Thank you,

Chris

enum values differ between model and serialization

Hello.
When I use enumerations in my model and serialize it, NMF capitalizes the names of the enums instead of using the original names defined in the model.

Example:
Model:

  <Types xsi:type="nmeta:Class" Name="TestElement">
    <Attributes IsOrdered="True" IsUnique="True" LowerBound="1" Type="nmeta:Enumeration #//Enum" Name="enum" />
  </Types>
  <Types xsi:type="nmeta:Enumeration" Name="Enum">
    <Literals Value="0" Name="first" />
    <Literals Value="1" Name="second" />
    <Literals Value="2" Name="third" />
  </Types>

Code that uses the model:

TestElement testElement = new TestElement();
testElement.Enum = MetaModel.Model.Enum.Second;

Serialization by NMF:
<model:TestElement xmi:version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" enum="Second" xmlns:xmi="http://www.omg.org/XMI" xmlns:model="http://example.com/model" />

The value of the attribute "enum" should be "second" as defined in the meta model, but instead it seems as if it gets the name of the generated C# enumeration element. Since the code generation creates a Class EnumConverter and two functions ConvertFrom and ConvertTo to map between the C# enumeration and the model values, I think this was not intended.

Because of this naming issue, when I try to read the serialization with EMF the enum value cannot be found, because of the wrong name.

Could you fix this issue?

Troubles loading EMF instances of an Ecore model

(possibly related to issue #55)

Hi, Apologies to bother you again. Unfortunately, I have run into another problem. Issue #55 seems to be related, giving some hope. I am loading an instance of the Ecore meta-model created in EMF. This is the instance I am loading:

<?xml version="1.0" encoding="ASCII"?>
<mdsebook.fsm:Model
    xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mdsebook.fsm="http://www.mdsebook.org/mdsebook.fsm" 
    xsi:schemaLocation="http://www.mdsebook.org/mdsebook.fsm ../model/fsm.ecore#//fsm"
    name="test-00">
  <machines
      name="SingleMachine"
      initial="a">
    <states
        name="a"/>
  </machines>
</mdsebook.fsm:Model>

(The metamodel is here: https://bitbucket.org/itu-square/mdsebook/src/master/mdsebook.fsm/model/fsm.ecore - almost the same meta-model that you are using in your examples.)

I am trying to load it with something like

var repository = new ModelRepository();
var model = repository.Resolve("test-00.xmi");
GeneratedCode.Fsm.Model fsm = model.RootElements[0] as GeneratedCode.Fsm.Model;

This compiles, but loading fails at runtime with the following message:

Unhandled exception. System.InvalidOperationException: The type Model in namespace http://www.mdsebook.org/mdsebook.fsm could not be resolved.
   at NMF.Serialization.XmlSerializer.GetTypeInfo(String ns, String localName)
   at NMF.Serialization.XmlSerializer.GetRootElementTypeInfo(XmlReader reader)
   at NMF.Serialization.XmlSerializer.CreateRoot(XmlReader reader)
   at NMF.Models.Repository.Serialization.ModelSerializer.Deserialize(Stream source, Uri modelUri, IModelRepository repository, Boolean addToRepository)
   at NMF.Models.Repository.ModelRepository.Resolve(Uri uri, String hintPath, Boolean loadOnDemand)
   at NMF.Models.Repository.ModelRepository.Resolve(Uri uri, Boolean loadOnDemand)
   at NMF.Models.Repository.ModelRepository.Resolve(String path)
   at Constraints.Program.Main(String[] args) in /home/wasowski/work/mdsebook/mdsebook.fsm.net/Constraints/Program.cs:line 30

I have been unable to understand what is wrong. My guess was that the meta-model is not loading, but I cannot load the meta-model either, and the other examples do not explicitly load meta-models.

Any ideas? I appreciate any suggestions.

Alternatively: if there is no easy way to solve it, is there a way to translate Ecore instances to NFM instances? I figured that I can translate the meta-model with ecore2code, but have not figured out how to translate the instances.

Problem following tutorial with NMF version 2.0.176

Hello,

I am trying to follow this tutorial, "First Steps with the .NET Modeling Framework"
https://www.youtube.com/watch?v=NIMYuwTltVs

I took the fsm.ecore file here : https://github.com/NMFCode/NMFDemo

PM> Ecore2Code -f -n NMFDemo2 -o Metamodel -m fsm.nmf fsm.ecore
An error occurred reading the Ecore file. The error message was: La r‚f‚rence d'objet n'est pas d‚finie … une instance d'un objet.
No package could be found.

The problem can be reproduced with a console app (.net core or .net 4.8 framework) with NMF version 2.0.176

Question to NMF and EMF XML output compability

Hello.
I’ve not much knowledge of NMF and EMF, so maybe the information I provide is not sufficient to give me an answer.

Currently I try to use a NMF to create data based on an EMF Meta model that I get from a colleague. Therefore, I use Ecore2Code.exe to generate the code and a NMF Meta model that is used in my project. I’m able to load a XML file, that was generated from a Java program based on the EMF Model in to my application. When I save the program with modelRepository.Save to XML and compare the output to the original file I loaded it looks a little bit different and when I try to load it in Eclipse I get an error because of one of the differences.

Example Eclipse EMF based XML output:

...
<stepParameter>
  <parameter xsi:type="program:PrimitiveVariable" href="Commands.program#number"/>
  <value xsi:type="program:Value" value="19">
    <type href="DataTypes.program#Integer"/>
  </value>
</stepParameter>
...

Example NMF based C# project XML output:

...
<stepParameter parameter="Commands.program#number">
  <value xsi:type="program:Value" value="19" type="DataTypes.program#Integer" />
</stepParameter>
...

The C# application reads the output of the Java application without any error. Eclipse seems to have a problem with the missing “xsi:type="program:PrimitiveVariable" for the parameter element, which is represented by NMF as attribute. NMF seems to represent all EMF elements that have an "href" attribute and no others as XML attribute with the value of the "href". The only exception is the parameter element from above. It includes a "xsi:type" attribute in EMF based output and NMF puts it in an XML attribute anyway.

Is this something that should be compatible or do I have a wrong expectation or misunderstanding?

Problem to install NMF-Basics 2.0.*

Hello.
Currently I use the nuget package NMF-Basics 1.0.99 with .NET Framworke 4.6.1 in Visual Studio 2015 Update 3. When I try to update to the newest version or create a test project and try to freshly install version 2.0.111 i get always the following error for all .NET Frameworks from 4.0 to 6.6.1.

Could not install package 'NMF-Expressions 2.0.111'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

I had the same problem with all 2.0.* versions. Version 1.0.99 installs without any problem. I've had a look in the package that causes the error NMF-Expressions. From version 2.0 on there is not net45 folder with the libraries anymore. Instead there is a folder netstandard2.0. Is it intended that the Version 2.0 does not work for the normal .NET Framework anymore or do I miss something?

Thnak you for the help!

Wrong deserialization of multivalued reference properties

Synopsis

Since the version 2.0.190 of the Ecore2Code tool, the deserialization process fails in populating corss-reference properties passing the --collectionsAreElements properties.

Description

To reproduce the problem is sufficient to generate the model code from a generic metamodel having a multivalued reference property by passing the --collectionsAreElements option to the Ecore2Code generation tool. The collection-valued property (i.e., refB in the example below) is not properly deserialized when reading the input instance model which appears to be empty at runtime, even though in the input model instance it's indeed fulfilled with data. Viceversa, by not passing the --collectionsAreElements option to the Ecore2Code generation tool, the component correctly deserialize the multivalued property as expected.

NOTE: The problem does not occur in case of a single-valued property (containment or not) as for the refC in the ClassD class (cfr. the example below).

Example.
The Ecore metamodel has a couple of classes that reference to each other. ClassA has a single containment reference to ClassB which, in turn, has a back reference to multiple objects of class ClassA. Further, ClassC have a single containment and opposite reference to ClassD.

Ecore model:

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="mwe6" nsURI="http://mwe6" nsPrefix="mwe6">
  <eClassifiers xsi:type="ecore:EClass" name="Root">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="classA" upperBound="-1"
        eType="#//ClassA" containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="classC" upperBound="-1"
        eType="#//ClassC" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ClassA">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="refB" eType="#//ClassB"
        containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ClassB">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="refA" upperBound="-1" eType="#//ClassA"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ClassC">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="refD" upperBound="-1" eType="#//ClassD"
        containment="true" eOpposite="#//ClassD/refC"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ClassD">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="refC" eType="#//ClassC"
        eOpposite="#//ClassC/refD"/>
  </eClassifiers>
</ecore:EPackage>

Instance model (original):

<?xml version="1.0" encoding="UTF-8"?>
<mwe6:Root xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mwe6="http://mwe6"
    xsi:schemaLocation="http://mwe6 mwe6.ecore"
    name="Mwe">
  <classA name="A1">
    <refB name="B1"
        refA="//@classA.1 //@classA.2"/>
  </classA>
  <classA name="A2">
    <refB name="B2"
        refA="//@classA.0 //@classA.2"/>
  </classA>
  <classA name="A3">
    <refB name="B3"
        refA="//@classA.0 //@classA.1"/>
  </classA>
  <classC name="C1">
    <refD name="D1"/>
    <refD name="D2"/>
  </classC>
  <classC name="C2">
    <refD name="D2"/>
  </classC>
</mwe6:Root>

Instance model (read by NMF):

<?xml version="1.0" encoding="utf-8"?>
<mwe6:Root xmi:version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Mwe" xmlns:xmi="http://www.omg.org/XMI" xmlns:mwe6="http://mwe6">
  <classA name="A1">
    <refB name="B1" />
  </classA>
  <classA name="A2">
    <refB name="B2" />
  </classA>
  <classA name="A3">
    <refB name="B3" />
  </classA>
  <classC name="C1">
    <refD name="D1" />
    <refD name="D2" />
  </classC>
  <classC name="C2">
    <refD name="D2" />
  </classC>
</mwe6:Root>

Additional references

A minimum working example is provided here: Mwe.zip. The command line used for the example project is: ecore2code --collectionsAreElements -f -o src/Models -n Models -m mwe6.nmf mwe6.ecore. The example just reads and save the instance model back to a different file, without touching anything. The Model.xmi is treated as the "original" instance model of the Ecore metamodel.

Expressions.Test build issues

Hello!

I was having issues building this project when I built the entire solution after checking it out from github. It was giving me grief about the .tt files, so I removed the clarius reference and added the following to the top of the .csproj:

C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\TextTemplating

now it works by dotnet msbuild and from the solution.

Thanks -
scott

Exception: The type TransitionGraph in namespace http://transitiongraph/1.0 could not be resolved.

I've two solutions. The first one from the internet (working NMF sln) that I copy into the second one, which is mine. I did almost nothing except of copy 6 file and change on the naming.

var repository = new ModelRepository();
var transitionGraph = repository.Resolve("c:\\W.......er4_3.xmi").RootElements[0] as TransitionGraph;

In the original solution, there is no problem, but in my case, I get this exception:

System.InvalidOperationException was unhandled
HResult=-2146233079
Message=The type TransitionGraph in namespace http://transitiongraph/1.0 could not be resolved.
Source=NMF.Serialization
StackTrace:
at NMF.Serialization.XmlSerializer.GetTypeInfo(String ns, String localName)
at NMF.Serialization.XmlSerializer.GetRootElementTypeInfo(XmlReader reader)
at NMF.Serialization.XmlSerializer.CreateRoot(XmlReader reader)
at NMF.Models.Repository.Serialization.ModelSerializer.Deserialize(Stream source, Uri modelUri, IModelRepository repository, Boolean addToRepository)
at NMF.Models.Repository.ModelRepository.Resolve(Uri uri, String hintPath, Boolean loadOnDemand)
at NMF.Models.Repository.ModelRepository.Resolve(String path)
at TTC2017.StateElimination.ModelHandler.CheckModel() in c:\WD_PaMMTE\PaMMTE_Managed\Call_PaMMTE\MyFiles\ModelHandler.cs:line 21
at TTC2017.StateElimination.Program.Main(String[] args) in c:\WD_PaMMTE\PaMMTE_Managed\Call_PaMMTE\Program.cs:line 39
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

Thanks, Tamás

Issue loading model created in EMF

Hi there,
I have been following the tutorial in both the paper and on youtube to load a model from EMF into a C# project I'm working on. I used eclipse EMF 2019-3 to create the .ecore and model instances, and got EMF via nuget in a clean C# project. The model fails to load depending on which parts of it are instantiated. The model has a ProductLibrary with [0...*] products, and within each products workpiecetypes which are referenced by productsegments.

I found that EMF and NMF save the references in a different way.

EMF saved it like this:

<product:ProductLibrary ...>
  <products ID="C40">
    <productsegments ID="segment" workpieceOut="//@products[ID='C40']/@workpiecetypes.0"/>
    <workpiecetypes ID="workpiece"/>
  </products>
</product:ProductLibrary>

NMF like this:

<product:ProductLibrary ...>
  <products ID="C40">
    <productsegments ID="segment" workpieceOut="C40/@workpiecetypes.0" />
    <workpiecetypes ID="workpiece" />
  </products>
</product:ProductLibrary>

Is there a way for me to load the model created in EMF in NMF without an aditional step to translate between the reference styles?

NMF Expressions - Feature idea - implement `ToLookup`

I think it would be great to have a ToLookup implementation. I have been using NMF to create in memory projections from an Event Store, and having a ToLookup implementation would enable me to find the items by key, like a DB index.

I think this is a very neat project by the way. I was using OLinq, but switched my code over once I discovered it. I think the uptake may be hampered a little bit by seeming like a component of the larger NMF project - I don't know if you would consider splitting and rebranding it with a catchy name, e.g. IncrementalLINQ or something like that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.