ClassCast exception during JET transformation! [message #53460] |
Fri, 28 November 2008 10:40  |
Eclipse User |
|
|
|
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 #53623 is a reply to message #53517] |
Wed, 03 December 2008 15:15  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.04308 seconds