Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Class Cast Exception
Class Cast Exception [message #1787347] Wed, 23 May 2018 23:07 Go to next message
om g is currently offline om gFriend
Messages: 12
Registered: February 2018
Junior Member
Hi everyone,
So I'm trying to write an ETL transformation using profiles as metamodels.So my source and target models are basically uml class diagrams.
in my target model I have a class that has a property that reference to a class in my source model.
When I try to pass the value or the reference of the class to the property which is of the same type as the class ,I get a Class Cast Exception .

Here's the code of the rule in my transformation in which I'm having the problem

rule mainRule
  transform  s : Source!Model
  to t1 : Target!Model,
     t2 : Target!Class,
     t3:  Target!Info {


   t1.applyProfile(Source!Profile.allInstances()->first()); 
  
   t1.name = "InfoModel";
   t2.name = "InfoClass";
   t2.package = t1 ;
   t3.base_Class = t2;
   t3.Id = "test" ;  // this one is working
   

     t3.Infox = (Source!Infox).allInstances().first(); // Here I get the Class Cast Exception, even thought the Infox attribute is of type the Infox class in the source. 

    
}




and this the the error :

Internal error: java.lang.ClassCastException: The value of type 'org.eclipse.emf.ecore.impl.EClassImpl@72a8c135 [name: Infox] [instanceClassName: null] [abstract: false, interface: false]' must be of type 'org.eclipse.emf.ecore.impl.EClassImpl@ad4497e [name: Infox] [instanceClassName: null] [abstract: false, interface: false]'


Thank you.
Re: Class Cast Exception [message #1787348 is a reply to message #1787347] Wed, 23 May 2018 23:15 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1609
Registered: July 2009
Location: York, UK
Senior Member

Hi Omar,

I suspect that this is due to UML2 loading the profile twice (once for the source model and once for the target model) which results in two different in-memory instances of the same EClass. Is your profile located in the same workspace as your models? If so, off the top of my head, you may need to put your profile in a workspace, "register" it through an extension [1], and then put your models and transformation in a nested/runtime workspace. Does this help?

Cheers,
Dimitris

[1] https://www.eclipse.org/forums/index.php/t/604098/
Re: Class Cast Exception [message #1787396 is a reply to message #1787348] Thu, 24 May 2018 17:11 Go to previous messageGo to next message
om g is currently offline om gFriend
Messages: 12
Registered: February 2018
Junior Member
Hi Dimitris,
Thank you for your reply.
I registered the profile through an extension, and it is shows up successfully on the the Runtime when applying it to the model. but When I launch the ETL transformation, it doesn't recognize it. This is the error I get :

Internal error: java.lang.IllegalArgumentException: Could not locate a metamodel with the URI 'http://www.info.ca/INFO/profile'. Please ensure that this metamodel has been registered with Epsilon.


Thank you.
Re: Class Cast Exception [message #1787397 is a reply to message #1787396] Thu, 24 May 2018 17:17 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1609
Registered: July 2009
Location: York, UK
Senior Member

Hi Omar,

What happens if you remove all URIs from your EMF model configuration dialogs?

Cheers,
Dimitris
Re: Class Cast Exception [message #1787399 is a reply to message #1787397] Thu, 24 May 2018 17:30 Go to previous messageGo to next message
om g is currently offline om gFriend
Messages: 12
Registered: February 2018
Junior Member
Hi Dimitris,
I'm sorry but I didn't understand what you mean by "EMF model configuration dialogs", is it the metamodel dialog for ETL run configuration ?
https://imgur.com/ig3Auia
Re: Class Cast Exception [message #1787485 is a reply to message #1787399] Sat, 26 May 2018 09:47 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1609
Registered: July 2009
Location: York, UK
Senior Member

Hi Omar,

Yes, this is what I meant.

Cheers,
Dimitris
Re: Class Cast Exception [message #1787493 is a reply to message #1787485] Sat, 26 May 2018 17:08 Go to previous messageGo to next message
om g is currently offline om gFriend
Messages: 12
Registered: February 2018
Junior Member
Hi Dimitris,
Thank you for your reply.
I tried removing all the URIs, but obviously I will not be able to get the stereotypes (types) defined in the profile when creating the target model for example.
Here's the error I get : Type Target!Info' not found

Thank you,
Omar
Re: Class Cast Exception [message #1787571 is a reply to message #1787493] Tue, 29 May 2018 09:24 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1609
Registered: July 2009
Location: York, UK
Senior Member

Hi Omar,

Yes - you're right about the target model. You'd need to create your target plain-vanilla UML model, apply the profile to it and then populate it using the transformation. I don't remember if/how you can get hold of a plugin-contributed profile from Epsilon off the top of my head but I'll have a look and will get back to you.

Cheers,
Dimitris
Re: Class Cast Exception [message #1789251 is a reply to message #1787571] Wed, 30 May 2018 23:58 Go to previous messageGo to next message
om g is currently offline om gFriend
Messages: 12
Registered: February 2018
Junior Member
Thank you Dimitris for your help !
Re: Class Cast Exception [message #1789875 is a reply to message #1789251] Thu, 31 May 2018 08:54 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1609
Registered: July 2009
Location: York, UK
Senior Member

Hi Omar,

You're welcome! If you've already solved this, is there any chance you could share a minimal example that demonstrates your solution?

Cheers,
Dimitris
Re: Class Cast Exception [message #1790010 is a reply to message #1789875] Sat, 02 June 2018 23:09 Go to previous messageGo to next message
om g is currently offline om gFriend
Messages: 12
Registered: February 2018
Junior Member
Hi Dimitris, It seems that the only solution for this problem is to launch the transformation as a java standalone application. In this case, the profiles will be loaded once even without registering the profiles through an extension. But still I couldn't get any result from launching the ETL transformation as it is.
Here's the java code if that might be interesting for someone else :
		EtlModule module = new EtlModule();
		module.parse(new File("path/to/.etl"));
		


		URI inputUri = URI.create(new File("path to input UML Model").toURI().toString());
		URI OutputUri= URI.create(new File("Path to the Output Uri").toURI().toString());
		createUmlModel(module,"Input",inputUri , true, false);
		createUmlModel(module,"Output",OutputUri, false, true);
		module.execute();
		module.getContext().getModelRepository().dispose();
		
		
		
}
	
	private static UmlModel createUmlModel(EtlModule module,String name, URI model, boolean readOnLoad, boolean storeOnDisposal) throws EolModelLoadingException {
		UmlModel umlModel = new UmlModel();
		StringProperties properties = new StringProperties();
		properties.put(EmfModel.PROPERTY_NAME, name);
		properties.put(EmfModel.PROPERTY_FILE_BASED_METAMODEL_URI , new File("Path to the profile").toURI().toString());
		if (model != null) properties.put(EmfModel.PROPERTY_MODEL_URI, model.toString());
		properties.put(EmfModel.PROPERTY_READONLOAD, readOnLoad + "");
		properties.put(EmfModel.PROPERTY_STOREONDISPOSAL, storeOnDisposal + "");
		umlModel.load(properties, (IRelativePathResolver) null);
		
		module.getContext().getModelRepository().addModel(umlModel);
		
		return umlModel;
	}
	



Thank you,
Omar
Re: Class Cast Exception [message #1790521 is a reply to message #1790010] Tue, 12 June 2018 10:32 Go to previous message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1609
Registered: July 2009
Location: York, UK
Senior Member

Hi Omar,

I've added an example that shows how you can apply a profile to an empty UML model using EOL in [1]. Please note that you'll need to update to the latest interim version for this to work. Does this help?

Cheers,
Dimitris

[1] https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/tree/examples/org.eclipse.epsilon.examples.applyprofile/applyprofile.eol
Previous Topic:Executing an ant build file programmatically which, in turn, executes an etl transformation
Next Topic:Licensing
Goto Forum:
  


Current Time: Wed Nov 14 09:05:53 GMT 2018

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

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

Back to the top