Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Specifying EJavaClass in Editor
Specifying EJavaClass in Editor [message #1067423] Mon, 08 July 2013 14:59 Go to next message
Tobias Freudenreich is currently offline Tobias FreudenreichFriend
Messages: 19
Registered: July 2013
Junior Member
Hi,

I created an editor for a simple model. One of the classes in the model has an attribute called "Type" with the type EJavaClass.
In the editor, I try setting that attribute via the properties view to one of my classes (called: Coordinates). However, no matter if I am using just the class name or the fully qualified class name (obtained by calling getCanonicalName and copied), the editor always complains with a WrapperException: java.lang.ClassNotFoundException.

I am pretty sure that the class is in the classpath (I used Class.forName in a Testclass, and it could get that class). Do I need to provide some extra functionality, so I can set the class there?

Thanks
Re: Specifying EJavaClass in Editor [message #1067437 is a reply to message #1067423] Mon, 08 July 2013 16:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Tobias,

Probably you shouldn't model it as a java.lang.Class. An instance of
such a value must exist in the JVM itself and for that to be the case,
it needs to be loaded by the/a class loader in the running JVM. But if
these are to be able to represent classes available only in the
workspace of the IDE, or on the classpaths of projects in the workspace,
trying to represent that as a java.lang.Class instance is just not going
to work, as you've noticed. If you look at
org.eclipse.emf.ecore.impl.EcoreFactoryImpl.createEJavaClassFromString(EDataType,
String) you'll see it ultimately is using the EMF Ecore bundle's class
loader and while that bundle has this policy specified

Eclipse-BuddyPolicy: dependent

it's still only able to load classes from bundles that depend on the
org.eclipse.emf.ecore bundle.


On 08/07/2013 6:25 PM, Tobias Freudenreich wrote:
> Hi,
>
> I created an editor for a simple model. One of the classes in the
> model has an attribute called "Type" with the type EJavaClass.
> In the editor, I try setting that attribute via the properties view to
> one of my classes (called: Coordinates). However, no matter if I am
> using just the class name or the fully qualified class name (obtained
> by calling getCanonicalName and copied), the editor always complains
> with a WrapperException: java.lang.ClassNotFoundException.
>
> I am pretty sure that the class is in the classpath (I used
> Class.forName in a Testclass, and it could get that class). Do I need
> to provide some extra functionality, so I can set the class there?
>
> Thanks


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Specifying EJavaClass in Editor [message #1067445 is a reply to message #1067437] Mon, 08 July 2013 18:05 Go to previous messageGo to next message
Tobias Freudenreich is currently offline Tobias FreudenreichFriend
Messages: 19
Registered: July 2013
Junior Member
Ed,

thanks a lot for the reply. That actually makes a lot of sense. I tried obtaining the instantiation code, but being relatively new to EMF/GMF, I looked in the wrong place (the generated diagram editor).
I'll just resort to a String then and do the loading myself. Probably even better if bytecode is not serialized when persisting model instances...

So thanks again for the reply.
Re: Specifying EJavaClass in Editor [message #1067454 is a reply to message #1067445] Mon, 08 July 2013 19:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Tobias,

Comments below.

On 08/07/2013 8:05 PM, Tobias Freudenreich wrote:
> Ed,
>
> thanks a lot for the reply. That actually makes a lot of sense. I
> tried obtaining the instantiation code, but being relatively new to
> EMF/GMF, I looked in the wrong place (the generated diagram editor).
> I'll just resort to a String then and do the loading myself.
Have a close look at how EcoreFactoryImpl supports EJavaClass. Instances
are serialized to and from a String representation; one important issue
is which class loader should be use. Another import issue is whether
it makes sense to load the classes at all if you're just working with
files in the workspace. You might look also at how EClassifierImpl
supports both instanceClassTypeName and instanceClass, so at development
time of an Ecore model, the wrapped type of an EClassifier is just a
string, but at runtime (e.g., in a deployed generated model) we can try
to load the actual class...
> Probably even better if bytecode is not serialized when persisting
> model instances...
>
> So thanks again for the reply.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Specifying EJavaClass in Editor [message #1069762 is a reply to message #1067454] Tue, 16 July 2013 14:05 Go to previous message
Tobias Freudenreich is currently offline Tobias FreudenreichFriend
Messages: 19
Registered: July 2013
Junior Member
Ed,

thanks for the detailed comments. I see that the factory just calls Class.forName, which -of course- fails since the plugin does not have access to the project's classes out of the box. I think for now I will stick to a String representation. Eventually, I will want to load a workspace-class based on that string name from within the plugin, but I will probably have to supply my own classloader anyway (and dynamically construct the project's classpath).
So I will see where I end up and then decide how to model it.
Previous Topic:Popup Bar Type
Next Topic:GMF Editor without associated files
Goto Forum:
  


Current Time: Thu Apr 18 13:28:56 GMT 2024

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

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

Back to the top