Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Can I make an Ecore metamodel that enables references to Java classes?
Can I make an Ecore metamodel that enables references to Java classes? [message #813816] Mon, 05 March 2012 18:41 Go to next message
Glenview Jeff is currently offline Glenview JeffFriend
Messages: 79
Registered: September 2010
Member
Also posted on Stack Overflow.

Suppose I want to design an Ecore metamodel that looks something like this, designed to be used to "run" a list of classes:

JavaClassRunnerList
   0..* JavaClass


And assume I have some Java project that has classes named PrintsHello, PrintsSeparator, and PrintsWorld.

I'd like to be able to then write models that look like this:

JavaClassRunnerList
   PrintsHello.class
   PrintsSeparator.class
   PrintsWorld.class
   PrintsSeparator.class
   PrintsSeparator.class


I want my model to be able to include a Java project and to recognize its classes as choices for the model references (possibly co-located in the same project the model is in.)

Is this possible?

[Updated on: Mon, 05 March 2012 19:57]

Report message to a moderator

Re: Can I make an Ecore metamodel that enables references to Java classes? [message #813841 is a reply to message #813816] Mon, 05 March 2012 19:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
You can use Ecore's EJavaClass data type to create a multi-valued
attribute. You might be better just to use class names, and use a class
loader to convert therm to actual class instances. Same goes for
wanting references to IProject; you can use a string and then resolve it
to an IProject using the the workspace root.


On 05/03/2012 7:41 PM, Glenview Jeff wrote:
> Also posted on http://stackoverflow.com/q/9571845/403455.
>
> Suppose I want to design an Ecore metamodel that looks something like
> this, designed to be used to "run" a list of classes:
>
>
> JavaClassRunnerList
> 0..* JavaClass
>
>
> And assume I have some Java project that has classes named
> PrintsHello, PrintsSeparator, and PrintsWorld.
>
> I'd like to be able to then write models that look like this:
>
>
> JavaClassRunnerList
> PrintsHello.class
> PrintsSeparator.class
> PrintsWorld.class
> PrintsSeparator.class
> PrintsSeparator.class
>
>
>
> I want my model to be able to include a Java project and to recognize
> its classes as choices for the model references (possibly co-located
> in the same project the model is in.)
> Is this possible?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Can I make an Ecore metamodel that enables references to Java classes? [message #813860 is a reply to message #813841] Mon, 05 March 2012 19:53 Go to previous messageGo to next message
Glenview Jeff is currently offline Glenview JeffFriend
Messages: 79
Registered: September 2010
Member
Hi Ed, thanks so much for the quick response. Maybe I wasn't clear about what I was hoping for, or it just may be that I don't understand the answer.

To clarify, ideally the meta-model (or model I suppose?) could be configured with a project containing Java classes. The meta-model would also contain a reference 0..* of, based on your answer, EJavaClass. The classes PrintsHello.class, PrintsWorld.class, etc. would not be explicitly entered into either model or meta-model, but would be imported from the Java project.

Is this something I'd have to implement myself, or is such capability already built in?

If the former, I suppose it would be much easier to populate the model with my class names since I'm still an EMF newbie.

Thanks,
Jeff

Ed Merks wrote on Mon, 05 March 2012 14:23
You can use Ecore's EJavaClass data type to create a multi-valued
attribute. You might be better just to use class names, and use a class
loader to convert therm to actual class instances. Same goes for
wanting references to IProject; you can use a string and then resolve it
to an IProject using the the workspace root.


Re: Can I make an Ecore metamodel that enables references to Java classes? [message #813917 is a reply to message #813860] Mon, 05 March 2012 21:05 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Comments below.

On 05/03/2012 8:53 PM, Glenview Jeff wrote:
> Hi Ed, thanks so much for the quick response. Maybe I wasn't clear
> about what I was hoping for, or it just may be that I don't understand
> the answer.
> To clarify, ideally the meta-model (or model I suppose?) could be
> configured with a project containing Java classes. The meta-model
> would also contain a reference 0..* of, based on your answer,
> EJavaClass. The classes PrintsHello.class, PrintsWorld.class, etc.
> would not be explicitly entered into either model or meta-model, but
> would be imported from the Java project.
You could use JDT for something like that. Or scan the classpath. How
to gather the information isn't really and EMF question...
> Is this something I'd have to implement myself, or is such capability
> already built in?
Yes, you have to implement that yourself.
> If the former, I suppose it would be much easier to populate the model
> with my class names since I'm still an EMF newbie.
Most folks want their models to be persistent. You might not need that
if you always intend to create mode instances by walking an
IJavaProject. Project like MoDisco provide a model for Java, so maybe
that's what you're after.
> Thanks,
> Jeff
>
> Ed Merks wrote on Mon, 05 March 2012 14:23
>> You can use Ecore's EJavaClass data type to create a multi-valued
>> attribute. You might be better just to use class names, and use a
>> class loader to convert therm to actual class instances. Same goes
>> for wanting references to IProject; you can use a string and then
>> resolve it to an IProject using the the workspace root.
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Can I make an Ecore metamodel that enables references to Java classes? [message #813930 is a reply to message #813917] Mon, 05 March 2012 21:28 Go to previous messageGo to next message
Glenview Jeff is currently offline Glenview JeffFriend
Messages: 79
Registered: September 2010
Member
Hi Ed,

> Most folks want their models to be persistent. You might not need that
> if you always intend to create mode instances by walking an
> IJavaProject. Project like MoDisco provide a model for Java, so maybe
> that's what you're after.

Sorry, but I may I confused things further with my attempt at a better explanation. Either way, I'm pretty sure from your response that I'd have to roll my own extensions to the editor in order to support what I want, which is beyond my abilities and wouldn't be worth the investment.

I didn't mean that I wanted the model auto-populated with the classes, I meant that I wanted the (xmi) model editor pull-down choices to already be populated with existing classes from the Java project. Then the author of the (xmi) model would be able to add to the model references to one or more classes from the project without having to worry about data entry errors, etc.

I'll probably just go the route of manually adding representations of the Java classes like PrintsHello, PrintsWorld, etc. to the metamodel as EClasses. A seeming drawback of this approach is that it requires updating the metamodel each time a new class is added. I suppose an advantage is that the metamodel is located in just one place, and if it weren't done this way, the meta model would be partially contained in the Java project.

For future readers of this thread, I did find a related thread from someone I believe was trying to accomplish the same thing here:

http://www.eclipsezone.com/eclipse/forums/t85582.html

Thanks,
Jeff

Re: Can I make an Ecore metamodel that enables references to Java classes? [message #814196 is a reply to message #813930] Tue, 06 March 2012 06:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Jeff,<br>
<br>
Comments below.<br>
<br>
On 05/03/2012 10:28 PM, Glenview Jeff wrote:
<blockquote cite="mid:jj3b56$r85$1@news.eclipse.org" type="cite">Hi
Ed, <br>
<blockquote type="cite">Most folks want their models to be
persistent. You might not need that
<br>
if you always intend to create mode instances by walking an
<br>
IJavaProject. Project like MoDisco provide a model for Java, so
maybe
<br>
that's what you're after.
<br>
</blockquote>
<br>
Sorry, but I may I confused things further with my attempt at a
better explanation.  Either way, I'm pretty sure from your
response that I'd have to roll my own extensions to the editor in
order to support what I want, which is beyond my abilities and
wouldn't be worth the investment.
<br>
<br>
I didn't mean that I wanted the model auto-populated with the
classes, I meant that I wanted the (xmi) model editor pull-down
choices to already be populated with existing classes from the
Java project. <br>
</blockquote>
A Java project in the workspace.  When the project changes, it
should change?<br>
<blockquote cite="mid:jj3b56$r85$1@news.eclipse.org" type="cite">
Then the author of the (xmi) model would be able to add to the
model references to one or more classes from the project without
having to worry about data entry errors, etc.
<br>
</blockquote>
It's very easy to provide your own cell editor that presents only
valid choices.<br>
<blockquote><a
href="http://wiki.eclipse.org/EMF/Recipes#Recipe:_Create_your_own_property_editor_in_a_generated_application"><span
class="tocnumber">3.1</span> <span class="toctext">Recipe:
Create your own property editor in a generated application</span></a></blockquote>
<blockquote cite="mid:jj3b56$r85$1@news.eclipse.org" type="cite">
<br>
I'll probably just go the route of manually adding representations
of the Java classes like PrintsHello, PrintsWorld, etc. to the
metamodel as EClasses.  </blockquote>
So it's really a fixed set of things that you could enumerate?<br>
<blockquote cite="mid:jj3b56$r85$1@news.eclipse.org" type="cite">A
seeming drawback of this approach is that it requires updating the
metamodel each time a new class is added. <br>
</blockquote>
Of course you could have a resource with the instances representing
your choices.  Such a resource could be stored in your bundle. 
(Much like org.eclipse.emf.ecore contains model/Ecore.ecore which
can be referenced via
platform:/plugin/org.eclipse.emf.ecore/Ecore.ecore")<br>
<blockquote cite="mid:jj3b56$r85$1@news.eclipse.org" type="cite"> I
suppose an advantage is that the metamodel is located in just one
place, and if it weren't done this way, the meta model would be
partially contained in the Java project.
<br>
</blockquote>
So when you're referring to a Java project, you're talking about the
project in which you are developing your model.<br>
<blockquote cite="mid:jj3b56$r85$1@news.eclipse.org" type="cite">
<br>
For future readers of this thread, I did find a related thread
from someone I believe was trying to accomplish the same thing
here:
<br>
<br>
<a class="moz-txt-link-freetext" href="http://www.eclipsezone.com/eclipse/forums/t85582.html">http://www.eclipsezone.com/eclipse/forums/t85582.html</a>
<br>
</blockquote>
Yes, that looks similar. <br>
<blockquote cite="mid:jj3b56$r85$1@news.eclipse.org" type="cite">
<br>
Thanks,
<br>
Jeff
<br>
<br>
<br>
</blockquote>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Can I make an Ecore metamodel that enables references to Java classes? [message #814456 is a reply to message #814196] Tue, 06 March 2012 13:28 Go to previous messageGo to next message
Glenview Jeff is currently offline Glenview JeffFriend
Messages: 79
Registered: September 2010
Member
Hi Ed,

FYI, something happened with your previous post causing visible HTML markup all over. I edited the responses:

> A Java project in the workspace. When the project changes, it
> should change?

Exactly.

> It's very easy to provide your own cell editor that presents only
> valid choices.
> http://wiki.eclipse.org/EMF/Recipes#Recipe:_Create_your_own_property_editor_in_a_generated_application

> I'll probably just go the route of manually adding representations
> of the Java classes like PrintsHello, PrintsWorld, etc. to the
> metamodel as EClasses. </blockquote>
> So it's really a fixed set of things that you could enumerate?

It depends how you define "fixed." Smile Right now I am the only client to my application. My intended purpose for this feature is that I want to be able to connect model components that expect a certain interface to code components that implement the interface.

To make the example a little more concrete, suppose I have a ShapeDisplayer component in the model that has a reference to a Shape interface, it would be nice if the meta-model and/or model editor would auto-populate with compatible implementations as the code is modified.

I was going to manually add them to the meta-model not because new classes wouldn't be added, but because I figured it was going to be a big effort (from an EMF novice) to try to "roll my own" editor version to support this based on your previous response.

> Of course you could have a resource with the instances representing
> your choices. Such a resource could be stored in your bundle.
> (Much like org.eclipse.emf.ecore contains model/Ecore.ecore which
> can be referenced via
> platform:/plugin/org.eclipse.emf.ecore/Ecore.ecore")

Isn't that a meta-model?

> I suppose an advantage is that the metamodel is located in just one
> place, and if it weren't done this way, the meta model would be
> partially contained in the Java project.
>
>> So when you're referring to a Java project, you're talking about the
>> project in which you are developing your model.

Yes, so to continue the previous example, my project is the ShapeDrawer and I'm adding new shapes to the system. I want to be able to model the configurations of this project from within the EMF editor. I'm primarily doing this to create a clear and consistent view of the application's architecture.

Thanks again for all of your guidance!

Jeff
Re: Can I make an Ecore metamodel that enables references to Java classes? [message #814484 is a reply to message #814456] Tue, 06 March 2012 13:59 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Jeff,

Comments below.

On 06/03/2012 2:28 PM, Glenview Jeff wrote:
> Hi Ed,
> FYI, something happened with your previous post causing visible HTML
> markup all over.
NNTP and web forum synchronization has frequent problems. :-(
> I edited the responses:
>
>> A Java project in the workspace. When the project changes, it
>> should change?
>
> Exactly.
>
>> It's very easy to provide your own cell editor that presents only
>> valid choices.
>> http://wiki.eclipse.org/EMF/Recipes#Recipe:_Create_your_own_property_editor_in_a_generated_application
>>
>
>> I'll probably just go the route of manually adding representations
>> of the Java classes like PrintsHello, PrintsWorld, etc. to the
>> metamodel as EClasses. </blockquote>
>> So it's really a fixed set of things that you could enumerate?
>
> It depends how you define "fixed." :) Right now I am the only client
> to my application. My intended purpose for this feature is that I
> want to be able to connect model components that expect a certain
> interface to code components that implement the interface.
> To make the example a little more concrete, suppose I have a
> ShapeDisplayer component in the model that has a reference to a Shape
> interface, it would be nice if the meta-model and/or model editor
> would auto-populate with compatible implementations as the code is
> modified.
> I was going to manually add them to the meta-model not because new
> classes wouldn't be added, but because I figured it was going to be a
> big effort (from an EMF novice) to try to "roll my own" editor version
> to support this based on your previous response.
It sounds like one way or another, you're going to write something that
finds a bunch of classes. It's easy to make the results of that
available in a drop down combo box in the editor.
>> Of course you could have a resource with the instances representing
>> your choices. Such a resource could be stored in your bundle.
>> (Much like org.eclipse.emf.ecore contains model/Ecore.ecore which
>> can be referenced via
>> platform:/plugin/org.eclipse.emf.ecore/Ecore.ecore")
>
> Isn't that a meta-model?
A meta-model is a model isn't it? The point is it's just a resource and
can be loaded like a *.gif, *.properties, or anything else other than
..class files you put into a jar/bundle.
>
>> I suppose an advantage is that the metamodel is located in just one
>> place, and if it weren't done this way, the meta model would be
>> partially contained in the Java project.
>>
>>> So when you're referring to a Java project, you're talking about the
>>> project in which you are developing your model.
>
> Yes, so to continue the previous example, my project is the
> ShapeDrawer and I'm adding new shapes to the system. I want to be
> able to model the configurations of this project from within the EMF
> editor. I'm primarily doing this to create a clear and consistent
> view of the application's architecture.
>
> Thanks again for all of your guidance!
>
> Jeff
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Can I make an Ecore metamodel that enables references to Java classes? [message #874936 is a reply to message #814484] Mon, 21 May 2012 20:33 Go to previous messageGo to next message
Kevin Page is currently offline Kevin PageFriend
Messages: 1
Registered: May 2012
Junior Member
Hi Ed,

I couldn't find an EJavaClass in any of the ECore jars (I checked 2.7.2 and 2.8.0 RC), would you mind pointing me to a jar reference or javadoc?

Thanks!

Kevin
Re: Can I make an Ecore metamodel that enables references to Java classes? [message #875091 is a reply to message #874936] Tue, 22 May 2012 06:15 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Kevin,

It's the name of an EDataType that wraps java.lang.Class. You'll find
the metadata for it in EcorePackage and of course it defined in Ecore.ecore.


On 21/05/2012 10:33 PM, Kevin Page wrote:
> Hi Ed,
>
> I couldn't find an EJavaClass in any of the ECore jars (I checked
> 2.7.2 and 2.8.0 RC), would you mind pointing me to a jar reference or
> javadoc?
>
> Thanks!
>
> Kevin


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] Performances: Relationnal DB or Object DB ?
Next Topic:[xcore] reference to EPackage
Goto Forum:
  


Current Time: Wed Sep 25 01:02:00 GMT 2024

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

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

Back to the top