Generated edit code and Dynamic EMF [message #663271] |
Mon, 04 April 2011 13:44 |
Steve Missing name Messages: 6 Registered: April 2011 |
Junior Member |
|
|
Hi,
I've searched hi and low but cannot find an answer, I think I understand what is going wrong but don't see how I fix the problem.
I am using an EMF (ecore) model that describes my system. I am using code generation to generate the mode, edit and editor code which is then used inside a set of plugins running in Eclipse.
In my model I have an EReference to an EObject which uses Dynamic EMF to allow my to save arbitrary data into my model. This allows my to have a "schema" that is different in different parts of the model but still ensure typed data. The "schema" is defined and also stored in another part of the model so I can use it for reference and when I generate my EObject.
This all works brilliantly and I can programmatically create my objects and the XML looks correct if I open the file up, but I'm having problems when it comes to the generated edit code. When I open the model to edit I get:
PackageNotFoundException: Package with uri 'null' not found.
And I cannot open the editor. The seems to be due to it not having a EPackage to be able to resolve the persisted EObjects against when it reads the data back in from the .xmi file. But the EPackage is defined in another part of the model. To fix this I guess I will need to make some changes to the edit code so that it can use my previously persisted EPackage during load?
Any pointers as to how I can make the generated edit code work nicely when I have a reference to some dynamically generated model objects?
Thank you.
[Updated on: Mon, 04 April 2011 13:44] Report message to a moderator
|
|
|
|
|
|
|
Re: Generated edit code and Dynamic EMF [message #663576 is a reply to message #663520] |
Tue, 05 April 2011 16:37 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
Steve,
Comments below.
Steve wrote:
> On 04/04/2011 16:08, Ed Merks wrote:
>> Comments below.
>>> And I cannot open the editor. The seems to be due to it not having a
>>> EPackage to be able to resolve the persisted EObjects against when it
>>> reads the data back in from the .xmi file. But the EPackage is defined
>>> in another part of the model.
>> Yes, but is it know to the package registry?
>>> To fix this I guess I will need to make some changes to the edit code
>>> so that it can use my previously persisted EPackage during load?
>> It should be registered either in the global package registry
>> EPackage.Registry.INSTANCE or the local one,
>> ResourceSet.getPackageRegistry.
>
> To further clarify what I'm trying to achieve I've created a
> mini-model and example .xmi file that I am trying to use, which will
> hopefully be helpful.
>
> The model allows me to declare multiple schemas and then multiple data
> objects who's data structure is defined by one of the schemas. The
> schemas can be created by the user dynamically and then the user can
> create data that will be a Dynamic EMF instance of that schema and
> also add that into the model.
>
> The model will not load with the reflective editor in eclipse with the
> previously mentioned "Package with uri 'null' not found." error message.
You will need a specialized resource implementation to mix your
instances and their models in the same resource. A normal
XMIResourceImpl won't be able to deal with this. (Hmmm, I suspect
though that if the instance included a schema location and the package
was earlier in the resource that it might well work like that.)
> Although I did create the data part of the .xmi file by hand rather
> than writing code but it will hopefully give the idea of what I am
> trying to achieve.
>
> Any pointers on how to achieve this sort of system would be greatly
> appreciated.
Try playing with the xsi:schemaLocation stuff. E.g.,
xsi:schemaLocation="<nsURI> #/<index>" where index is the zero-based
position of the package in the serialization.
>
> Thank you.
>
>
> My project.xmi file is:
> =======================
>
> <?xml version="1.0" encoding="ASCII"?>
> <core:Project xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:core="http://example.com/core"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xsi:schemaLocation="http://example.com/core example.ecore
> http://www.eclipse.org/emf/2002/Ecore
> ../../../plugin/org.eclipse.emf.ecore/model/Ecore.ecore">
> <schemas>
> <schema name="schema1">
You'll need a the fragment path to get to this, i.e., #//@schema.0.
Null namespace packages aren't valid and will cause yet more problems.
Try to avoid them.
> <eClassifiers xsi:type="ecore:EClass" name="fieldList">
> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="stringField1">
> <eType xsi:type="ecore:EDataType"
> href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eStructuralFeatures>
> </eClassifiers>
> </schema>
> </schemas>
> <datas>
> <customData xsi:type="fieldList" stringField1="someData" />
Classes should have upper case names. Ideally here you'd have
"foo:fieldList" where foo binds to the namespace of the package.
> </datas>
> </core:Project>
>
>
>
> My model is this:
> =================
>
> <?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="core"
> nsURI="http://example.com/core" nsPrefix="core">
> <eClassifiers xsi:type="ecore:EClass" name="schemaContainer">
It would be best to try to conform to the case conventions, i.e.,
classifiers are upper case and features/operations are lower cased.
> <eStructuralFeatures xsi:type="ecore:EReference" name="schema"
> eType="ecore:EClass
> platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//E Package "
> containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="dataContainer">
> <eStructuralFeatures xsi:type="ecore:EReference" name="customData"
> eType="ecore:EClass
> platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//E Object "
> containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Project">
> <eStructuralFeatures xsi:type="ecore:EReference" name="schemas"
> upperBound="-1"
> eType="#//schemaContainer" containment="true"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="datas"
> upperBound="-1"
> eType="#//dataContainer" containment="true"/>
> </eClassifiers>
> </ecore:EPackage>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03477 seconds