Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Upcasting and Downcasting in XPand?(Check if element of model is of some subtype in xpand template?)
Upcasting and Downcasting in XPand? [message #645789] Mon, 20 December 2010 10:28 Go to next message
Stefan Mijatov is currently offline Stefan Mijatov
Messages: 44
Registered: March 2010
Location: Vienna, Austria
Member
I have the following code in my xpand template file:

«IMPORT ejb3»
«IMPORT java»
«DEFINE packageTemplate FOR JavaPackage»
«FOREACH eClassifiers AS c»
«EXPAND entityTemplate FOR c»
«ENDFOREACH»
«ENDDEFINE»
«DEFINE entityTemplate FOR EntityBean»
«FILE name + ".java" »
import java.io.Serializable;
//@Entity
class «name» implements Serializable{
	
	private static final long serialVersionUID = 1L;
	«FOREACH fields AS f»
	«f.javaVisibility.toString().toLowerCase()» «IF f.eType.name != null»«f.eType.name»«ELSE»String«ENDIF» «f.name»;
	«ENDFOREACH»
	«FOREACH fields AS f»
	public void set«((String)f.name).toFirstUpper()»(«IF f.eType.name != null»«f.eType.name»«ELSE»String«ENDIF» value){
		this.«f.name» = value;
	}
	public «IF f.eType.name != null»«f.eType.name»«ELSE»String«ENDIF» get«((String)f.name).toFirstUpper()»(){
		return this.«f.name»;
	}
	«ENDFOREACH»
}
«ENDFILE»
«ENDDEFINE»


Is it possible to somehow check for the subtype of element f in foreach loop, as I would do in QVT like this:

f.oclIsTypeOf(ManyToOne);


Please help Sad
Re: Upcasting and Downcasting in XPand? [message #645817 is a reply to message #645789] Mon, 20 December 2010 11:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6198
Registered: July 2009
Senior Member
Hello Stefan,

on a list you can use
mylist.typeSelect(MyType)


a normal properties you can use
MyTypel.isInstance(myprop)


~Christian
Re: Upcasting and Downcasting in XPand? [message #645821 is a reply to message #645817] Mon, 20 December 2010 12:01 Go to previous message
Stefan Mijatov is currently offline Stefan Mijatov
Messages: 44
Registered: March 2010
Location: Vienna, Austria
Member
I did it, and it works. Thanks!
Previous Topic:[Xpand] : runing workflows with ant or Maven
Next Topic:Code autocompletion in xpt files
Goto Forum:
  


Current Time: Thu Aug 21 00:42:41 EDT 2014

Powered by FUDForum. Page generated in 0.02120 seconds