Ecore Model & Xpand: Uppercase Attributes lead to errors [message #676480] |
Sat, 04 June 2011 19:03 |
Stefan Messages: 9 Registered: June 2011 |
Junior Member |
|
|
Hello together,
I was faced with a strange problem:
in my xpt file I got some red underlinies from Xpand editor at some attributes from model classes.
I created a ecore model previously and then over the genmodel I created some dynamic .xmi instances and putted data in.
Some of the class attributes had uppercase on the first letter like "Title".
In the Xpand editor if I accessed "Title" it was marked as an error. The auto completion only gave me a "title" as option. With "title", lower case first letter, the error in the editor was gone.
But my workflow (mwe) did not run though with "title", only with "Title".
Now I changed the model that every attribute starts now with a lower case letter and everything is fine.
Is this problem with attributes having uppercase in the first letter known?
[Updated on: Sat, 04 June 2011 19:06] Report message to a moderator
|
|
|
|
|
Re: Ecore Model & Xpand: Uppercase Attributes lead to errors [message #676535 is a reply to message #676488] |
Sun, 05 June 2011 06:10 |
Stefan Messages: 9 Registered: June 2011 |
Junior Member |
|
|
Hello Christian,
thank you for your answer.
Sorry, but I am new to the whole thing with modeling. I also do not know Java.
My intention was to draw a ecore model, add data to the model and then generate C-Code with oAW.
I experienced oAW is moved into EMF project. That is really confusion, because in the internet I find many tutorials or postings regarding the "old" oAW methods and classes.
However I will give a short overview what I have done:
1. I created a ecore model using graphical diagramm editor. Root-Class: "Library", Subclass "Book", connection: A Library can have 0..* Books. A book has a attribute "Title" as EString.
2. I created a genmodel out of it and generated "All" (Model Code, Edit Code, etc.). Now I have some Java-Packages in my src/ folder.
3. I wanted to have data files, so I created a dynamic instance from ecore model. This gave me .xmi files. I added some dummy data to the xmi files.
4. I created a workflow.properties, workflow.mwe and a .xpt file.
5. I want to read in the data in the workflow, so I added:
<component id="ModelReader1"
class="org.eclipse.emf.mwe.utils.Reader">
<uri value="data/${ModelDataFile1}" />
<modelSlot value="slotted_model_with_data_1" />
</component>
Hint: properties: ModelDataFile1=ModelData1.xmi
Unfortuantely I got the following error:
335 INFO CompositeComponent - Reader(ModelReader1): Loading model from data/ModelData1.xmi
388 ERROR WorkflowRunner - Workflow interrupted. Reason: Couldn't load resource under data/ModelData1.xmi : org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'h_t_t_p_:_/_/ModelNsURI/1.0' not found. (f_i_l_e_:_/_/_/home/stefan/workspace/MyPrj.generator/data/ModelData1.xmi, 4, 132)
The "h_t_t_p_:_/_/ModelNsURI/1.0" was the uri I entered in the ecore model. After studing some oAW tutorials I came to a additional entry before the <component>:
<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" platformUri="..">
<registerGeneratedEPackage value="ModelPackage.ModelPackagePackage"/>
</bean>
Now the workflow can resolve the uri and the model data is read in fine.
I think your advice points to not using the <bean> entry anymore. But what can I use instead?
(Sorry I had to add some underlines to urls because I am not allowed to post links)
[Updated on: Sun, 05 June 2011 07:33] Report message to a moderator
|
|
|
|
Re: Ecore Model & Xpand: Uppercase Attributes lead to errors [message #676548 is a reply to message #676544] |
Sun, 05 June 2011 07:59 |
|
Hi,
welcome to Eclipse Modeling/oAW. first of all the Xpand generator always needs to know the metamodel it runs against. so you can configure it. if you have an EMF/Ecore based Metamodel and have generated the Java Classes for it you have basically two possibilities:
(1) using JavaBeansMetaModel
<!-- set up EMF for standalone execution -->
<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" >
<platformUri value=".."/>
<registerGeneratedEPackage value="metamodel.MetamodelPackage" />
</bean>
....
<!-- generate code -->
<component class="org.eclipse.xpand2.Generator">
<metaModel class="org.eclipse.xtend.type.impl.java.JavaBeansMetaModel"/>
<expand
value="template::Template::main FOR model" />
<outlet path="${src-gen}" >
<postprocessor class="org.eclipse.xpand2.output.JavaBeautifier" />
</outlet>
</component>
(2) using Emf(Registry)MetaModel
<!-- set up EMF for standalone execution -->
<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" >
<platformUri value=".."/>
<registerEcoreFile value="platform:/resource/my.generator.project/src/metamodel/metamodel.ecore" />
</bean>
<!-- instantiate metamodel -->
<bean id="mm_emf" class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>
...
<!-- generate code -->
<component class="org.eclipse.xpand2.Generator">
<metaModel idRef="mm_emf"/>
<expand
value="template::Template::main FOR model" />
<outlet path="${src-gen}" >
<postprocessor class="org.eclipse.xpand2.output.JavaBeautifier" />
</outlet>
</component>
if you use javabeans metamodel you have to import the full::qualified::package::name::of::the::javaclasses in your template
if you use EMF/Registry)Metamodel you use simple packagename for the imports
to get the ui along with the workflow you have to configute the corresponding metamodel in your projects properties in the Xpand/Xtend section.
if you have javabeans enabled it will search for java classes on the classpath, if you have emf enabeld it will search für ecore files on the classpath.
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
Re: Ecore Model & Xpand: Uppercase Attributes lead to errors [message #676554 is a reply to message #676548] |
Sun, 05 June 2011 08:43 |
Stefan Messages: 9 Registered: June 2011 |
Junior Member |
|
|
Christian Dietrich wrote on Sun, 05 June 2011 09:59Hi,
...
if you use javabeans metamodel you have to import the full::qualified::package::name::of::the::javaclasses in your template
if you use EMF/Registry)Metamodel you use simple packagename for the imports
to get the ui along with the workflow you have to configute the corresponding metamodel in your projects properties in the Xpand/Xtend section.
if you have javabeans enabled it will search for java classes on the classpath, if you have emf enabeld it will search für ecore files on the classpath.
~Christian
Hello,
thank you again. As you can see in a post above yours, I found that way "using Emf(Registry)MetaModel" already, but yous answer confirms me.
But my experience was different. When I used the javabeans metamodel before, it was also possibe to have a «IMPORT ModelPackage» in the .xpt file. The classes and attributed were solved correctly.
But as far as I do not want to generate java things I want to avoid to deal with genmodel and gernated "Model Code" so I removed them after I switched to "Emf(Registry)MetaModel".
You wrote also for "Emf(Registry)MetaModel" the ecore must be found in the classpath.
I do not exactly know where the classpath really is, but my current understanding is the classpath is wehn I open the MANIFEST.MF and then goto "Dependencies" tab. There "Required Plugins" and "Imported Packages" is for my understandting "the classpath".
But I cannot enter there the path where my ecore is. My ecore is in a folder "model".
This lead me to an idea: I opend the properies of the project -> Java Build Path.
There I added the folder "<project>/model" as source-folder.
The folder icon in the Project Explorer changed.
Now, with this additional source folder it works!
So the rule is: the ecore file has to be in a folder which is a source-folder (instead of a normal folder), isn't it?
I am really very happy now and the first time I can see the metamodel-package name when I press Ctrl+Space in an IMPORT statement
Hint: my build.properties looks now:
bin.includes = .,\
model/,\ <----- ecore (meta)model
META-INF/
jars.compile.order = .
source.. = src/,\ <---- notting
scripts/ <---- workflow, xpand template
output.. = bin/
I have a additional (normal) folder "data/" where the dynamic instances .xmi are stored. But this is not in the build.properties. Is this ok?
[Updated on: Sun, 05 June 2011 08:47] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04443 seconds