Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] Issues setting up project to generate text from UML2 profile metamodel
[Xpand] Issues setting up project to generate text from UML2 profile metamodel [message #647200] Wed, 05 January 2011 00:32 Go to next message
Eclipse User is currently offline Eclipse UserFriend
Messages: 14
Registered: January 2011
Junior Member
I have a UML2 model that uses a custom profile (UML stereotypes) that I would like to use Xpand to generate code from. It appears that Xpand does provide a UML2 profile metamodel support, but I can't get even a simple example to work.

Alternately, I tried doing a model-to-model transformation from a UML2 model to ecore, but the instance data from my custom profile properties was not being populated correctly when I use Xtend to transform the model.

Any advice from someone who has more experience with this would be greatly appreciated.

Thanks,

sedzen
Re: [Xpand] Issues setting up project to generate text from UML2 profile metamodel [message #647221 is a reply to message #647200] Wed, 05 January 2011 07:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
Here a Working Sample Workflow:

<workflow>
	
	<bean class="org.eclipse.xtend.typesystem.uml2.Setup" standardUML2Setup="true" />
	
	<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" platformUri=".." />
	
	<component class="org.eclipse.emf.mwe.utils.Reader">
		<uri value="platform:/resource/xpand.uml.profile.sample/src/model/test.uml" />
		<modelSlot value="model" />
	</component>
	
	<component class="org.eclipse.emf.mwe.utils.DirectoryCleaner">
		<directory value="src-gen" />
	</component>
	
	
	<component class="org.eclipse.xpand2.Generator">
		<metaModel class="org.eclipse.xtend.typesystem.uml2.profile.ProfileMetaModel">
			<profile value="platform:/resource/xpand.uml.profile.sample/src/model/test.profile.uml" />
		</metaModel>
		<metaModel class="org.eclipse.xtend.typesystem.uml2.UML2MetaModel" />
		<expand value="template::Template::main FOR model" />
		<outlet path="src-gen" >
			<postprocessor class="org.eclipse.xpand2.output.JavaBeautifier" />
		</outlet>
	</component>
	

</workflow>


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [Xpand] Issues setting up project to generate text from UML2 profile metamodel [message #647324 is a reply to message #647200] Wed, 05 January 2011 16:30 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

You could also inspect the code from the UML2 cartridges hosted at fornax-platform.org for more samples.

~Karsten


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: [Xpand] Issues setting up project to generate text from UML2 profile metamodel [message #647349 is a reply to message #647324] Wed, 05 January 2011 18:12 Go to previous messageGo to next message
Eclipse User is currently offline Eclipse UserFriend
Messages: 14
Registered: January 2011
Junior Member
Thanks, Christian! That helped me get a little further along in my pathfinding.

Now the problem I'm stuck on is trying to access a custom profile stereotype property.

I have found good examples to reference the stereotypes as "types" in the Xpand template, and have even gotten to the point where I can echo the name of a class that has the stereotype applied, but when I try to access the property values, I haven't had much success.

I've tried «MyProfile::MyService::MyProperty»
which results in "uml::Property" being output to the target file.

I've also tried using a modified example from the old oAW forums:

«FOREACH this.getAllAttributes().typeSelect(MyProfile::MyService) AS attr ITERATOR iter»
«attr.getValue(attr.getAppliedStereotype(MyProfile::MyServi ce.toString()), "index")»
«ENDFOREACH»

which results in the following errors:

2636 ERROR StereotypeType - Couldn't find type for EcorePrimitiveTypes::EString
2636 ERROR StereotypeType - Couldn't find type for EcorePrimitiveTypes::EString
2636 ERROR StereotypeType - Couldn't find type for EcorePrimitiveTypes::EString

(What I find encouraging is that I have 3 properties for the stereotype, so it does appear to be iterating correctly, even if the mechanism to produce the output is clearly missing something).

Any help would be greatly appreciated!!
Re: [Xpand] Issues setting up project to generate text from UML2 profile metamodel [message #647372 is a reply to message #647349] Wed, 05 January 2011 20:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
Hi,

the Mapping between the Typesystem (UML) and The Internal Xtend Typesystem is done manually in the UML2Metamodel.

So to be able to deal with this you could do something like this:

package model;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.mwe.utils.Mapping;
import org.eclipse.xtend.typesystem.Type;
import org.eclipse.xtend.typesystem.uml2.UML2MetaModel;

public class ExtendedUML2Metamodel extends UML2MetaModel {
	
	private Map<String,String> mappings = new HashMap<String,String>();
	
	public void addMapping(Mapping mapping) {
		mappings.put(mapping.getFrom(), mapping.getTo());
	}
	
	@Override
	public Type getTypeForName(String typeName) {
		Type mappedType = null;
		String mappedTypeName = mappings.get(typeName);
		if (mappedTypeName != null) {
			mappedType = getTypeForName(mappedTypeName);
			if (mappedType != null) {
				return mappedType;
			}
		}
		return super.getTypeForName(typeName);
	}

}



	<component class="org.eclipse.xpand2.Generator">
		<metaModel class="org.eclipse.xtend.typesystem.uml2.profile.ProfileMetaModel">
			<profile value="platform:/resource/xpand.uml.profile.sample/src/model/test.profile.uml" />
		</metaModel>
		<metaModel class="model.ExtendedUML2Metamodel">
			<mapping from="EcorePrimitiveTypes::EString" to="ecore::EString" />
		</metaModel>
		<expand value="template::Template::main FOR model" />
		<outlet path="src-gen" >
			<postprocessor class="org.eclipse.xpand2.output.JavaBeautifier" />
		</outlet>
	</component>


Maybe there is a better solution but i cannot say

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [Xpand] Issues setting up project to generate text from UML2 profile metamodel [message #647375 is a reply to message #647372] Wed, 05 January 2011 20:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14738
Registered: July 2009
Senior Member
Created https://bugs.eclipse.org/bugs/show_bug.cgi?id=333605 for the problem

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [Xpand] Issues setting up project to generate text from UML2 profile metamodel [message #647701 is a reply to message #647375] Fri, 07 January 2011 21:04 Go to previous message
Eclipse User is currently offline Eclipse UserFriend
Messages: 14
Registered: January 2011
Junior Member
Just to confirm, the workaround does appear to get us past the issue that the bug report was opened to address. At least, we are able to continue moving forward with our efforts.

Thanks!
Previous Topic:[XPand, MWE2] Why full xtext dependency?
Next Topic:[Acceleo 3] Protected section ERROR ?
Goto Forum:
  


Current Time: Fri Dec 27 01:34:44 GMT 2024

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

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

Back to the top