Skip to main content



      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
Eclipse UserFriend
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
Eclipse UserFriend
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
Eclipse UserFriend
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: Tue Jul 01 00:29:15 EDT 2025

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

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

Back to the top