Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » ClassCast exception during JET transformation!
ClassCast exception during JET transformation! [message #53460] Fri, 28 November 2008 15:40 Go to next message
cyril is currently offline cyrilFriend
Messages: 4
Registered: July 2009
Junior Member
Dear all,

1°) I have developed an eclipse plugin which lets create a J2EE project
(ear + web project) customized with my company's framework.

I do it at the end of the Wizard page , in the performFinish method, by
creating an ecore model with all the informations collected in the
previous wizards ,
saving it into an xml file, and operating a JET transformation on it.

This is the utility method used at this aim, to be clear a call to
JET2Platform.runTransformOnResource(transformId, aModel, aMonitor):

public static void execute (IFile aModel, IProgressMonitor aMonitor)
throws CoreJETException, IOException {

String transformId = ISphinxUIConstants.SPHINX_JET_PLUGIN_ID;

if(transformId == null) {
throw new IllegalArgumentException( "pas de transformId"); //$NON-NLS-1$
}

if(JET2Platform.getJETBundleManager().getDescriptor(transfor mId)
== null) {
throw new IllegalArgumentException("transform id non valide");
}

final IStatus result = JET2Platform.runTransformOnResource(transformId,
aModel, aMonitor);

if(!result.isOK()) {
throw new IllegalArgumentException(result.getMessage());
}

2°) now i want to only execute the jet transformation on the model inside
RSA7 via right-click and execute JET transformation or with the
<jet-transform> ant task

<!-- =================================
target: default
================================= -->
<target name="jet-transformation" depends="depends" description="Runs
JET transformation on JET Model">
<jet.transform
transformid="com.natixis.sphinx.ide.eclipse.codegen"
source="WizAnt/src/model.xml" />
</target>

Here's the problem: every time i execute the JET transformation by either
way - right-click or ant task execution - i receive the following error:

!STACK 0
java.lang.ClassCastException:
org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl incompatible with
com.natixis.sphinx.ide.eclipse.codegen.emf.Racine
at org.eclipse.jet.compiled._jet_main.generate(Unknown Source)

It means that the in the deserialisation of such JET code:
Racine lRacine = (Racine) context.getVariable("root");

the JET engine isn't able to give me the correct object with correct type.

My xml with the targetNamespace
urn:com:natixis:sphinx:ide:eclipse:codegen:emf:Racine :

<sxgcm:Racine
xmlns:sxgcm="urn:com:natixis:sphinx:ide:eclipse:codegen:emf:Racine "
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:namespaceSchemaLocation="schema.xsd">

and the correct mapping in the EPackage ecore model:
public interface InputSchemaPackage extends EPackage {
/**
* The package name.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
String eNAME = "com.natixis.sphinx.ide.eclipse.codegen.emf";

/**
* The package namespace URI.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
String eNS_URI = "urn:natixis:sphinx:gencode:model:1.0";

/**
* The package namespace name.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
String eNS_PREFIX = "sxgcm";

Do you have any ide of the damned problem?
Thanks a lot in advance!
Re: ClassCast exception during JET transformation! [message #53491 is a reply to message #53460] Fri, 28 November 2008 18:19 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Cyril:

I think the problem is a difference between the URI specified in the XML
document, and that in the generated EMF code

Your XML:

<sxgcm:Racine
xmlns:sxgcm="urn:com:natixis:sphinx:ide:eclipse:codegen:emf:Racine "
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:namespaceSchemaLocation="schema.xsd">

Your generated EMF code:

> /**
> * The package namespace URI.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> String eNS_URI = "urn:natixis:sphinx:gencode:model:1.0";
>


One has urn:com:natixis... the other urn:natixix.

Check the EMF project's plugin.xml, too, as there is usually an extension
point there that registers the URI with the EPackage.

Paul
Re: ClassCast exception during JET transformation! [message #53517 is a reply to message #53491] Mon, 01 December 2008 15:24 Go to previous messageGo to next message
cyril is currently offline cyrilFriend
Messages: 4
Registered: July 2009
Junior Member
Paul Elder wrote:


> Check the EMF project's plugin.xml, too, as there is usually an extension
> point there that registers the URI with the EPackage.

> Paul

Hi Paul,

Thanks a lot for your quick answer.

1°) I have added the extension point dedicated to package mapping in
plugin.xml

<extension point="org.eclipse.emf.ecore.generated_package">
<package
uri="urn:natixis:sphinx:gencode:model:1.0"
class=" com.natixis.sphinx.ide.eclipse.codegen.emf.InputSchemaPackag e " />
</extension>


and then i have no more ClassCastException and the JET transformation
from the model.xml and right-click -> source of JET transformation is
working well!

2°)But I still have a problem with Ant generation, from

a) inside
b) and outside Eclipse.

a) I don't understand why the Jet Ant transform task hosted in Eclipse
doesn't work although it works very well via right click -> Jet
transformation on the model.
There are only few informations on log file = console during the build
failure, although i activated -verbose option for the configuration of ant
transformation:

BUILD FAILED
D:\Documents\Developpements\workspaces\sphinx_fwk\WizAnt\src \build.xml:19:
Des erreurs se sont produites lors de l'exécution
at org.eclipse.jet.ant.tasks.JETTransformTask.execute(Unknown Source)
at org.apache.tools.ant.UnknownElement.execute(Unknown Source)
at org.apache.tools.ant.Task.perform(Unknown Source)
at org.apache.tools.ant.Target.execute(Unknown Source)
at org.apache.tools.ant.Target.performTasks(Unknown Source)
at org.apache.tools.ant.Project.executeSortedTargets(Unknown Source)
at org.apache.tools.ant.Project.executeTarget(Unknown Source)


My build.xml file, very simple:
============================================================ ==========
-->
<project name="project" default="jet-transformation">
<description>
Permet de générer une transformation Jet à partir d'un modèle
EMF sous
format xml.
</description>

<target name="jet-transformation" depends="depends" description="Runs
JET transformation on JET Model">
<jet.transform
transformid="com.natixis.sphinx.ide.eclipse.codegen"
source="WizAnt/src/model.xml" />
</target>

<!-- - - - - - - - - - - - - - - - - -
target: depends
- - - - - - - - - - - - - - - - - -->
<target name="depends" description="Permet de déclarer le task de
transformation Jet">
<taskdef name="jet.transform"
classname="org.eclipse.jet.ant.tasks.JETTransformTask" />
</target>

</project>

I've also cheked 'same Jre' in the option of the ant transformation as
explained by Paul in other threads.


b) For headless eclipse: As i run under RSA 7 and so Eclipse 3.2 i wonder
if it is not a bug of antrunner task in headless Eclipse as explained in
these threads...
cf bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=184528
and thread from this newsgroups:
http://www.eclipse.org/newsportal/article.php?id=1197&gr oup=eclipse.modeling.m2t#1197

Regards,
Cyril.
Re: ClassCast exception during JET transformation! [message #53544 is a reply to message #53491] Mon, 01 December 2008 15:37 Go to previous messageGo to next message
cyril is currently offline cyrilFriend
Messages: 4
Registered: July 2009
Junior Member
Paul Elder wrote:


> Check the EMF project's plugin.xml, too, as there is usually an extension
> point there that registers the URI with the EPackage.

> Paul

Hi Paul,

Thanks a lot for your quick answer.

1°) I have added the extension point dedicated to package mapping in
plugin.xml

<extension point="org.eclipse.emf.ecore.generated_package">
<package
uri="urn:natixis:sphinx:gencode:model:1.0"
class=" com.natixis.sphinx.ide.eclipse.codegen.emf.InputSchemaPackag e " />
</extension>


and then i have no more ClassCastException and the JET transformation
from the model.xml and right-click -> source of JET transformation is
working well!

2°)But I still have a problem with Ant generation, from

a) inside
b) and outside Eclipse.

a) I don't understand why the Jet Ant transform task hosted in Eclipse
doesn't work although it works very well via right click -> Jet
transformation on the model.
There are only few informations on log file = console during the build
failure, although i activated -verbose option for the configuration of ant
transformation:

BUILD FAILED
D:\Documents\Developpements\workspaces\sphinx_fwk\WizAnt\src \build.xml:19:
Des erreurs se sont produites lors de l'exécution
at org.eclipse.jet.ant.tasks.JETTransformTask.execute(Unknown Source)
at org.apache.tools.ant.UnknownElement.execute(Unknown Source)
at org.apache.tools.ant.Task.perform(Unknown Source)
at org.apache.tools.ant.Target.execute(Unknown Source)
at org.apache.tools.ant.Target.performTasks(Unknown Source)
at org.apache.tools.ant.Project.executeSortedTargets(Unknown Source)
at org.apache.tools.ant.Project.executeTarget(Unknown Source)


My build.xml file, very simple:
============================================================ ==========
-->
<project name="project" default="jet-transformation">
<description>
Permet de générer une transformation Jet à partir d'un modèle
EMF sous
format xml.
</description>

<target name="jet-transformation" depends="depends" description="Runs
JET transformation on JET Model">
<jet.transform
transformid="com.natixis.sphinx.ide.eclipse.codegen"
source="WizAnt/src/model.xml" />
</target>

<!-- - - - - - - - - - - - - - - - - -
target: depends
- - - - - - - - - - - - - - - - - -->
<target name="depends" description="Permet de déclarer le task de
transformation Jet">
<taskdef name="jet.transform"
classname="org.eclipse.jet.ant.tasks.JETTransformTask" />
</target>

</project>

I've also cheked 'same Jre' in the option of the ant transformation as
explained by Paul in other threads.


b) For headless eclipse: As i run under RSA 7 and so Eclipse 3.2 i wonder
if it is not a bug of antrunner task in headless Eclipse as explained in
these threads...
cf bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=184528
and thread from this newsgroups:
http://www.eclipse.org/newsportal/article.php?id=1197&gr oup=eclipse.modeling.m2t#1197

Regards,
Cyril.
Re: ClassCast exception during JET transformation! [message #53571 is a reply to message #53491] Mon, 01 December 2008 15:48 Go to previous messageGo to next message
cyril is currently offline cyrilFriend
Messages: 4
Registered: July 2009
Junior Member
Paul Elder wrote:


> Check the EMF project's plugin.xml, too, as there is usually an extension
> point there that registers the URI with the EPackage.

> Paul

Hi Paul,

Thanks a lot for your quick and instructive answer!

1°) I have added the extension point dedicated to package mapping in
plugin.xml

<extension point="org.eclipse.emf.ecore.generated_package">
<package
uri="urn:natixis:sphinx:gencode:model:1.0"
class=" com.natixis.sphinx.ide.eclipse.codegen.emf.InputSchemaPackag e " />
</extension>


and then i have no more ClassCastException and the JET transformation
from the model.xml and right-click -> source of JET transformation is
working well!

2°)But I still have a problem with Ant generation, from

a) inside
b) and outside Eclipse.

a) I don't understand why the Jet Ant transform task hosted in Eclipse
doesn't work although it works very well via right click -> Jet
transformation on the model.
There are only few informations on log file = console during the build
failure, although i activated -verbose option for the configuration of ant
transformation:

BUILD FAILED
D:\Documents\Developpements\workspaces\sphinx_fwk\WizAnt\src \build.xml:19:
Des erreurs se sont produites lors de l'exécution
at org.eclipse.jet.ant.tasks.JETTransformTask.execute(Unknown Source)
at org.apache.tools.ant.UnknownElement.execute(Unknown Source)
at org.apache.tools.ant.Task.perform(Unknown Source)
at org.apache.tools.ant.Target.execute(Unknown Source)
at org.apache.tools.ant.Target.performTasks(Unknown Source)
at org.apache.tools.ant.Project.executeSortedTargets(Unknown Source)
at org.apache.tools.ant.Project.executeTarget(Unknown Source)


My build.xml file, very simple:
============================================================ ==========
-->
<project name="project" default="jet-transformation">
<description>
Permet de générer une transformation Jet à partir d'un modèle
EMF sous
format xml.
</description>

<target name="jet-transformation" depends="depends" description="Runs
JET transformation on JET Model">
<jet.transform
transformid="com.natixis.sphinx.ide.eclipse.codegen"
source="WizAnt/src/model.xml" />
</target>

<!-- - - - - - - - - - - - - - - - - -
target: depends
- - - - - - - - - - - - - - - - - -->
<target name="depends" description="Permet de déclarer le task de
transformation Jet">
<taskdef name="jet.transform"
classname="org.eclipse.jet.ant.tasks.JETTransformTask" />
</target>

</project>

I've also cheked 'same Jre' in the option of the ant transformation as
explained by Paul in other threads.


b) For headless eclipse:
As i run under RSA 7 and so Eclipse 3.2 i wonder if it is not a bug of
antrunner task in headless Eclipse as explained in these threads...
cf bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=184528
and thread from this newsgroups:
http://www.eclipse.org/newsportal/article.php?id=1197&gr oup=eclipse.modeling.m2t#1197

Regards,
Cyril.
Re: ClassCast exception during JET transformation! [message #53598 is a reply to message #53517] Wed, 03 December 2008 13:07 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Cyril:

I'm going to fire up RSA 7.0 today and see if I what I can find. I'll post
back with results.

Paul
Re: ClassCast exception during JET transformation! [message #53623 is a reply to message #53517] Wed, 03 December 2008 20:15 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Cyril:

OK. I've done a lot of experimenting.

The good news: I can get Ant builds with jet.transform tasks to work without
ClassCastExceptions in nearly all situations.

The bad news: I said 'nearly'.

The key problem your are experiencing is a ClassCastException when you try
to get at one of the objects that JET has loaded for you. This exception
happens because JET/EMF failed to use the classes associated with the
EPackage you defined.

I've found two situations where this will happen - both are related to using
an XML Schema as the basis of the EMF project. They are:

1) The XML Schema contains no targetNamespace. In this case, I can see that
EMF might ligitimately not be able to match a document to the generated Java
classes. But, this is not your situation.

2) The XML document contains an xsi:schemaLocation attribute. In this case,
EMF seems to prefer to dynamically generate the EClasses/EObjects by parsing
the specified schema over using the generated classes in your EMF project.

Fortunately, there are two simple workarounds

The one situation that fails is when the EMF project/EPackage was generated
from an XML schema that did not include a target namespace. Consider an XML
schema without a target namespace, like this one:

a) Ensure that the schema referenced in the xsi:schemaLocation is not
available. Closing the project containing the schema is one such way of
doing this.
b) Remove the xsi:schemaLocation attribute for the XML document.

I recommend option b).

In doing so, you risk loosing the ability to validate the XML document
against its schema. To overcome this, register the schema in the XML Catalog
(this is a preference page installed by the Web Tools project - RSA ships
it). This way, schema validation will find your schema and continue to work.

Paul
Previous Topic:[Xpand] Re: [newbie] Getting my Check.chk recognized
Next Topic:Re: Genereta XML file with VE
Goto Forum:
  


Current Time: Thu Dec 26 13:43:59 GMT 2024

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

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

Back to the top