Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Ecore Model & Xpand: Uppercase Attributes lead to errors
Ecore Model & Xpand: Uppercase Attributes lead to errors [message #676480] Sat, 04 June 2011 19:03 Go to next message
Stefan is currently offline 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 #676483 is a reply to message #676480] Sat, 04 June 2011 19:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6305
Registered: July 2009
Senior Member
Hi,

i cannot reproduce this using Xpand 1.0.1 and EMF Metamodels configured. can you share a reproducable example with us?

~Christian
Re: Ecore Model & Xpand: Uppercase Attributes lead to errors [message #676488 is a reply to message #676483] Sat, 04 June 2011 19:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6305
Registered: July 2009
Senior Member
Hi,

actually i can reproduce this problem using the JavaBeansMetamodel and emfmetamodel mixed. maybe you are using javabeans in ui and emf in workflow or the other wax round?.

=> Use the same metamodel in both ui and workflow and it will work.

~Christian

[Updated on: Sat, 04 June 2011 19:57]

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 Go to previous messageGo to next message
Stefan is currently offline 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 #676544 is a reply to message #676535] Sun, 05 June 2011 07:32 Go to previous messageGo to next message
Stefan is currently offline Stefan
Messages: 9
Registered: June 2011
Junior Member
I relaced the bean with:

  <bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" platformUri="..">
    <registerEcoreFile value="model/library_with_books_model.ecore" />
  </bean>


and then I removed the genmodel and everything what was generated from it.

Workflow runs fine, but XPand editor complains. It cannot find the model elements, e.g. on the
«IMPORT ModelPackage» 

statement the error is "Namespace ModelPackage is unknown or unused." (Note: ModelPackage is my ecore package name, equal to "metamodel" here: h_t_t_p_:_/_/www.peterfriese.de/getting-started-with-code-generation-with-xpand/)


I am afraid of a genmodel with generated "Model Code" is needed for Xpand editor to get it know the ecore model elements?
Re: Ecore Model & Xpand: Uppercase Attributes lead to errors [message #676548 is a reply to message #676544] Sun, 05 June 2011 07:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6305
Registered: July 2009
Senior Member
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
Re: Ecore Model & Xpand: Uppercase Attributes lead to errors [message #676554 is a reply to message #676548] Sun, 05 June 2011 08:43 Go to previous messageGo to next message
Stefan is currently offline Stefan
Messages: 9
Registered: June 2011
Junior Member
Christian Dietrich wrote on Sun, 05 June 2011 09:59
Hi,
...

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 Smile


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

Re: Ecore Model & Xpand: Uppercase Attributes lead to errors [message #676555 is a reply to message #676554] Sun, 05 June 2011 08:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6305
Registered: July 2009
Senior Member
Hi,

just a remark: if the package name of the JavaClasses is ModelPackage then it of course works if you import ModelPackage and use the JavaBeansMetamodel.

~Christian
Re: Ecore Model & Xpand: Uppercase Attributes lead to errors [message #676557 is a reply to message #676555] Sun, 05 June 2011 08:49 Go to previous message
Stefan is currently offline Stefan
Messages: 9
Registered: June 2011
Junior Member
Christian Dietrich wrote on Sun, 05 June 2011 10:46
Hi,

just a remark: if the package name of the JavaClasses is ModelPackage then it of course works if you import ModelPackage and use the JavaBeansMetamodel.

~Christian


This was the case. But the genmodel generated also a "ModelPackagePackage", which can be confusing. I should choose another package name in future.
Previous Topic:not able to work with JET
Next Topic:[Xpand2]Loading multiple model files
Goto Forum:
  


Current Time: Sat Sep 20 02:01:11 GMT 2014

Powered by FUDForum. Page generated in 0.03235 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software