Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xtend] Problem with JAVA Extension -> static initializer -> EFactory
[Xtend] Problem with JAVA Extension -> static initializer -> EFactory [message #546063] Sat, 10 July 2010 16:04 Go to next message
Abdull is currently offline Abdull
Messages: 32
Registered: May 2010
Member
Dear modeling friends,

For a rather complex model transformation using Xtend, I require to use a JAVA Extension to call a static method within my Java class "TransformHelper".
This static method shall return some object/model element. I want this object to be created earlier within a static initializer. This static initializer uses the factory of my EMF metamodel.

//file my_transformation_rules.ext
import ecore;
import ti_c_psmm_02; // some awkward metamodel name

ti_c_psmm_02::Include getMeMyInclude() :
	JAVA my.package.TransformHelper.getMeMyInclude();

...


//file TransformHelper.java
package my.package;

import ti_c_psmm_02.Include;
import ti_c_psmm_02.Ti_c_psmm_02Factory;

public class TransformHelper {
	private static Include myInclude;
	
	static {
		myInclude = Ti_c_psmm_02Factory.eINSTANCE.createInclude(); 
		myInclude.setName("fancy_header.h");
	}
	public static Include getMeMyInclude() {
		return myInclude;
	}
}


When I try to run a workflow using my_transformation_rules.ext and extension getMeMyInclude(), I get the following exception trace

java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EFactoryImpl cannot be cast to ti_c_psmm_02.Ti_c_psmm_02Factory
	at ti_c_psmm_02.impl.Ti_c_psmm_02FactoryImpl.init(Ti_c_psmm_02FactoryImpl.java:34)
	at ti_c_psmm_02.Ti_c_psmm_02Factory.<clinit>(Ti_c_psmm_02Factory.java:26)
	at my.package.TransformHelper.<clinit>(TransformHelper.java:10)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at org.eclipse.emf.mwe.internal.core.MWEPlugin.loadClass(MWEPlugin.java:75)
	at org.eclipse.emf.mwe.core.resources.ResourceLoaderDefaultImpl.tryLoadClass(ResourceLoaderDefaultImpl.java:38)
	at org.eclipse.emf.mwe.core.resources.AbstractResourceLoader.loadClass(AbstractResourceLoader.java:37)
	at org.eclipse.emf.mwe.core.resources.ResourceLoaderDefaultImpl.loadClass(ResourceLoaderDefaultImpl.java:28)
	at org.eclipse.internal.xtend.xtend.ast.JavaExtensionStatement.getJavaMethod(JavaExtensionStatement.java:119)
	at org.eclipse.internal.xtend.xtend.ast.JavaExtensionStatement.evaluateInternal(JavaExtensionStatement.java:67)
	at org.eclipse.internal.xtend.xtend.ast.AbstractExtension.evaluate(AbstractExtension.java:166)
	at org.eclipse.internal.xtend.expression.ast.OperationCall.evaluate(OperationCall.java:335)
	at org.eclipse.internal.xtend.expression.ast.OperationCall.evaluateInternal(OperationCall.java:76)
	at org.eclipse.internal.xtend.expression.ast.Expression.evaluate(Expression.java:50)
	at org.eclipse.internal.xtend.expression.ast.LetExpression.evaluateInternal(LetExpression.java:55)
	at org.eclipse.internal.xtend.expression.ast.Expression.evaluate(Expression.java:50)
	at org.eclipse.internal.xtend.xtend.ast.CreateExtensionStatement.evaluate(CreateExtensionStatement.java:93)
	at org.eclipse.internal.xtend.expression.ast.OperationCall.evaluate(OperationCall.java:335)
	at org.eclipse.internal.xtend.expression.ast.OperationCall.evaluateInternal(OperationCall.java:76)
	at org.eclipse.internal.xtend.expression.ast.Expression.evaluate(Expression.java:50)
	at org.eclipse.xtend.expression.ExpressionFacade.evaluate(ExpressionFacade.java:56)
	at org.eclipse.xtend.expression.ExpressionFacade.evaluate(ExpressionFacade.java:45)
	at org.eclipse.xtend.XtendComponent.invokeInternal2(XtendComponent.java:190)
	at org.eclipse.xtend.expression.AbstractExpressionsUsingWorkflowComponent.invokeInternal(AbstractExpressionsUsingWorkflowComponent.java:239)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
	at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
	at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:31)
	at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:80)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)

I have the feeling that I run into a classloader class lifecycle problem: probably, my static initializer code tries to access my factory's eINSTANCE singleton instance, which does not exist yet at the moment of access.

Any ideas?
Thanks, Abdull
Re: [Xtend] Problem with JAVA Extension -> static initializer -> EFactory [message #546072 is a reply to message #546063] Sat, 10 July 2010 18:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6382
Registered: July 2009
Senior Member
Hello Abdull,

the error message is a hint that you use static emf (using the generated classes) and dynamic emf (using the ecore file) at the same time. See http://www.openarchitectureware.org/forum/viewtopic.php?foru m=2&showtopic=12828 in the good old oaw forum.

Can you post your workflow?

Regards
Christian
Re: [Xtend] Problem with JAVA Extension -> static initializer -> EFactory [message #546084 is a reply to message #546063] Sat, 10 July 2010 20:24 Go to previous message
Abdull is currently offline Abdull
Messages: 32
Registered: May 2010
Member
Hello Christian,
your suggestion solved my problem!
This was my mwe2 workflow:
module project.skunkflow.DspTiCWorkflow03

var model = "full_fixp_phase_mod_and_fir_2"
var pimExtension = "hl_dsp_pimm_02"
var pimModelFile = "${model}.${pimExtension}"

var tiCPsmExtension ="ti_c_psmm_02"
var tiCPsmModelFile = "${model}.${tiCPsmExtension}"


var workflowProjectName = "workflows_transformations_models"
var workflowProjectDir = "../${workflowProjectName}"

var hlDspPimmProjectName = "hl_dsp_pimm_02"
var hlDspPimmProjectDir = "../${hlDspPimmProjectName}"

var tiCPsmmProjectName = "ti_c_psmm_02"
var tiCPsmmProjectDir = "../${tiCPsmmProjectName}"


Workflow {
	
	bean = org.eclipse.emf.mwe.utils.StandaloneSetup {
		registerEcoreFile = "${hlDspPimmProjectDir}/metamodel/${hlDspPimmProjectName}.ecore"
		registerEcoreFile = "${tiCPsmmProjectDir}/metamodel/${tiCPsmmProjectName}.ecore"
		// platformUri ?
	}
	
	
	component = org.eclipse.emf.mwe.utils.Reader {
		uri = "${workflowProjectDir}/models/${pimModelFile}"
		modelSlot = "model_pim"
		firstElementOnly = true
	}
	
	component = org.eclipse.xtend.XtendComponent {
	
		metaModel = org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel { }
			
		invoke = "${workflowProjectDir}::transformations::dsp_pim_2_ti_c_psm_03::transform_dsp_pim_to_ti_c_psm(model_pim)"
		outputSlot = "model_ti_c_psm"
	}
	
	component = org.eclipse.emf.mwe.utils.Writer {
		modelSlot = "model_ti_c_psm"
		uri = "${workflowProjectDir}/out/${tiCPsmModelFile}"
	}
	
	
}


As you can see in the above workflow, I was using the dynamic method (e.g. registerEcoreFile = " ${hlDspPimmProjectDir}/metamodel/${hlDspPimmProjectName}.eco re " ).
Though I cannot tell at which place within my workflow I'm switching to static EMF. Possibly this happens with
	component = org.eclipse.xtend.XtendComponent {
	
		metaModel = org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel { }
...
though I don't know how to do it in another way.

...
I switched from dynamic EMF to static EMF. My workflow now looks like this
module project.skunkflow.DspTiCWorkflow04

var model = "full_fixp_phase_mod_and_fir_2"
var pimExtension = "hl_dsp_pimm_02"
var pimModelFile = "${model}.${pimExtension}"
var tiCPsmExtension = "ti_c_psmm_02"
var tiCPsmModelFile = "${model}.${tiCPsmExtension}"
var workflowProjectName = "workflows_transformations_models"
var workflowProjectDir = "../${workflowProjectName}"
var hlDspPimmProjectName = "hl_dsp_pimm_02"
var hlDspPimmProjectDir = "../${hlDspPimmProjectName}"
var tiCPsmmProjectName = "ti_c_psmm_02"
var tiCPsmmProjectDir = "../${tiCPsmmProjectName}"

Workflow {

	bean = org.eclipse.emf.mwe.utils.StandaloneSetup {
		registerGeneratedEPackage = "hl_dsp_pimm_02.Hl_dsp_pimm_02Package"
		registerGeneratedEPackage = "ti_c_psmm_02.Ti_c_psmm_02Package"
	}

	component = org.eclipse.emf.mwe.utils.Reader {
		uri = "${workflowProjectDir}/models/${pimModelFile}"
		modelSlot = "model_pim"
		firstElementOnly = true
	}

	component = org.eclipse.xtend.XtendComponent {

		metaModel = org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel {}

		invoke = "${workflowProjectDir}::transformations::dsp_pim_2_ti_c_psm_03::transform_dsp_pim_to_ti_c_psm(model_pim)"
		outputSlot = "model_ti_c_psm"
	}

	component = org.eclipse.emf.mwe.utils.Writer {
		modelSlot = "model_ti_c_psm"
		uri = "${workflowProjectDir}/out/${tiCPsmModelFile}"
	}

}


The workflow now runs flawlessly.
Actually, I was required to switch to static EMF for yet another reason, as already similarly discussed in another thread.

The problem was that one of my Java extension had a metamodel class as a parameter
Void handleMyCs(hl_dsp_pimm_02::CompoundSystem cs) :
	JAVA de.mimoon.meta.m2m.TransformHelper.handleMyCs(hl_dsp_pimm_02.CompoundSystem);


When executing the old dynamic workflow, Xtend complained in the following way

hl_dsp_pimm_02::CompoundSystem is not responsible for java type hl_dsp_pimm_02.CompoundSystem


Changing the workflow from dynamic EMF to static EMF solved my problem - though I'd still prefer to have it running in the dynamic way.

I'd like to thank you and your colleagues once again for the great and quick support you are providing for the community!
Cheers,
Abdull

[Updated on: Sat, 10 July 2010 20:25]

Report message to a moderator

Previous Topic:[Xtend] Using EEnum Literals within Xtend expressions
Next Topic:[Xpand] Controlling Whitespaces
Goto Forum:
  


Current Time: Wed Oct 22 01:48:33 GMT 2014

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

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