Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Doubt in Xpand template(Doubt in Xpand template)
Doubt in Xpand template [message #498081] Sat, 14 November 2009 10:50 Go to next message
zakir Hussain is currently offline zakir HussainFriend
Messages: 76
Registered: July 2009
Member
Hello All,

I am using OAW from past 5 to 6 months...

I have got a following requirement to invoke definitions in the Xpand file dynamically :

Earlier my Xpand definition was:

«DEFINE main FOR Model»

«EXPAND javaClass FOREACH entities()»

«ENDDEFINE»



As per my requirement now the invocation of definition should be:

«DEFINE main FOR Model»

«EXPAND this.getDefinitionName() FOREACH entities()»

«ENDDEFINE»

But our Xpand editor is complaining about this and even when i try to execute the template it is trying to find the Xpand definition by name this.getDefinitionName() where as i am expecting Xpand to search for the definition with return value of this.getDefinitionName()

Please help me in resolving this problem....

Regards,

Zakir
Re: Doubt in Xpand template [message #498096 is a reply to message #498081] Sat, 14 November 2009 12:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14725
Registered: July 2009
Senior Member
hello zakir.

this is afaik not possible since xpand ist stacially typed and wants to check at edit time if the definition you want to call exists for the type you want to call it.

can you tell more about your requirements? maybe there are some other solutions like aop for your problem


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Doubt in Xpand template [message #498126 is a reply to message #498096] Sat, 14 November 2009 18:45 Go to previous messageGo to next message
zakir Hussain is currently offline zakir HussainFriend
Messages: 76
Registered: July 2009
Member
Hello Christian,

Thank you very much for the quick reply....

My requirement is all standard definitions will be written in one template(called as platform templates), we have even provided a facility for our project user to provide his own template, these templates are called as customer templates (We have customized OAW for this feature, the reason is customer will write his own Xpand definitions with completely new names).

All the names of the Xpand definitions will be in model which is passed to templates, so i wanted to invoke them in the following way:

«DEFINE main FOR Model»

«EXPAND this.getDefinitionName() FOREACH entities()»

«ENDDEFINE»

The value of this.getDefinitionName() is obtained from the model, its equivalent Xpand definition is also present in the template file.

Regards,

Zakir
Re: Doubt in Xpand template [message #498130 is a reply to message #498126] Sat, 14 November 2009 20:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14725
Registered: July 2009
Senior Member
Hello Zakir,

one thing that comes into my mind is to call XpandFacade using a java extension.
another possibility is to move the problem to the workflow using the cartrige mechanisms or moving to template names to properties

e.g. (from a oaw 4.3.1 sample)
<property name="template" value="template::Template::main" />

	<!--  generate code -->
	<component class="org.openarchitectureware.xpand2.Generator">
		<metaModel idRef="mm"/>
		<expand
			value="${template} FOR model" />
		<outlet path="${src-gen}" >
			<postprocessor class="org.openarchitectureware.xpand2.output.JavaBeautifier" />
		</outlet>
	</component>


Regards Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Doubt in Xpand template [message #498161 is a reply to message #498130] Sun, 15 November 2009 08:58 Go to previous messageGo to next message
zakir Hussain is currently offline zakir HussainFriend
Messages: 76
Registered: July 2009
Member
Hello Christian,

Thanks for the reply...

I am executing my template in the following way using XpandFacade:

XpandFacade facade = XpandFacade.create(execCtx);
facade.evaluate("template::Start::main", inputModel);

Here i am trying to call main Xpand definition inside template Start.xpt which is present in template folder

This is working perfectly fine....

My Start.Xpt is in the following way:

«IMPORT metamodel»

«EXTENSION template::GeneratorExtensions»

«DEFINE main FOR Model»

	«EXPAND   this.definitionName FOREACH entities()»

«ENDDEFINE»


«DEFINE textOutput FOR Entity»
	«FILE name+".txt"»
			«FOREACH features AS f»
 				«f.type.name» :: «f.name»
 				
 			«ENDFOREACH»
	«ENDFILE»
«ENDDEFINE»


«DEFINE javaClass FOR Entity»
	«FILE name+".java"»
		public class «name» {
			«FOREACH features AS f»
				private «f.type.name» «f.name»;
				
				public void «f.setter()»(«f.type.name» «f.name») {
					this.«f.name» = «f.name»;
				}
				
				public «f.type.name» «f.getter()»() {
					return «f.name»;
				}
			«ENDFOREACH»
		}
	«ENDFILE»
«ENDDEFINE»




Quote:
Here in line

«EXPAND this.definitionName FOREACH entities()»
this.definitionName is the value which is obtained from the model....it is pretty dynamic ....so it could be either textOutput or javaClass..... so i expect Xpand to decide the corresponding definition in runtime...i.e from my model and execute corresponding definition.......



Hope now it is clear that i want to invoke various definitions inside my Xpand template ...dynamically based upon model data.....
Re: Doubt in Xpand template [message #498162 is a reply to message #498161] Sun, 15 November 2009 09:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14725
Registered: July 2009
Senior Member
so why don't you call a java excetion as replacement
for

«EXPAND   this.definitionName FOREACH entities()»


that invokes the template dynamically

«invoketemplate(this.definitionName, entities())»


with
XpandFacade facade = XpandFacade.create(execCtx);
facade.evaluate("template::Start::main", inputModel);


replaced by someting like

XpandFacade facade = XpandFacade.create(execCtx);
facade.evaluate(templateName, inputModel);


in the java extenstion


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Sun, 15 November 2009 09:52]

Report message to a moderator

Re: Doubt in Xpand template [message #498163 is a reply to message #498162] Sun, 15 November 2009 10:32 Go to previous message
zakir Hussain is currently offline zakir HussainFriend
Messages: 76
Registered: July 2009
Member
Hello Christian,

Thank you very much for your amazing solution.....it worked like a charm........

Java extension concept has resolved the concept of invoking Xpand definitions dynamically....

public class JavaExt {

	private static XpandFacade facade;

 
	public static void setFacade(XpandFacade facade) {
		JavaExt.facade = facade;
	}
	
	public static String invokeDefinition(String definitionName, Object inputModel){
		
		facade.evaluate(definitionName, inputModel);
		
		return null;
	}
	
}



If it would not have worked then we would have shifted to another template language..........as we are completely dependent on dynamic definition execution........

thanks a lot......
Previous Topic:XPAND and XSD adapter
Next Topic:XPAND and XSD adapter: root not found
Goto Forum:
  


Current Time: Tue Oct 15 01:22:15 GMT 2024

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

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

Back to the top