Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Modeling Servlet in EMF
Modeling Servlet in EMF [message #1848066] Thu, 18 November 2021 21:28 Go to next message
Joel Craig is currently offline Joel CraigFriend
Messages: 2
Registered: November 2021
Junior Member
I'm writing a simple servlet and would like to model it with EMF. I would like to extend javax.servlet.http.HttpServlet, which of course extends javax.servlet.GenericServlet which implements javax.servlet.Servlet.

When I create a new EClass "MyServlet" in the ecore, how do I extend javax.servlet.http.HttpServlet?

I can create an EClass, MyServlet, in the ecore and set its instance type name to javax.servlet.http.HttpServlet. When the code is generated, I see

public class MyServletImpl extends MinimalEObjectImpl.Container implements HttpServlet {


Of course, this is illegal, since HttpServlet is an abstract class and not an interface. The code generator doesn't create a MyServlet.java interface class.

The "ESuper Types" list doesn't include javax.servlet.http.HttpServlet . I can create a custom data type, HttpServletV which uses the Instance Type Name javax.servlet.http.HttpServlet, but that custom data type doesn't appear in the "ESuper Types" list.

I attached a pic of my simple Ecore file.

I can create a Servlet class outside of EMF (File->New->Other...->Web->Servlet) and it will compile cleanly, but I'd like to use the EMF modeling tool to model the new servlet.

In case it's relevant, I'm using AdoptOpenJDK 11.0.11, Eclipse 2021-06 (4.20.0), Eclipse Modeling Tools 4.20.0.20210612-1200, EMF - Eclipse Modeling Framework SDK 2.27.0.v20210816-1137.

Thanks for any pointers that you can provide!
Re: Modeling Servlet in EMF [message #1848074 is a reply to message #1848066] Fri, 19 November 2021 05:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
You cannot do so directly... Sometimes things you want are not possible, i.e., it's not possible to implement the class "public class Bogus<E> implements List<E>, Map<E, E>" which I'll leave as an exercise to the reader...

More similar, you might also say, I want my HttpServlet to be a java.util.List. That you could make that happen, but you'd need to implement the entire List hierarchy's API from scratch because you cannot also inherit from the class AbstractList<E>. The same is true for EObject, but even more so because the API is even more complex and the implementation class must also implement InternalEObject. And EMF provides no mechanism to generate an EObject/InternalEObject implementation into an arbitrary base class...

So that leaves you with the "normal" approach of either using a modeled class that delegates to an HttpServlet class or vice versa (or perhaps some two-way delegation). But you will be implementing some parts of that yourself., e.g., perhaps you implement, by hand, a method (operation) that returns the modeled object's HttpServlet delegate in which you can implement the intended links between your model class and the servlet implementation.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Modeling Servlet in EMF [message #1848079 is a reply to message #1848074] Fri, 19 November 2021 08:22 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

For a simple example, I'm not sure that it's worth struggliing, but for research purposes, anything goes.

I think you can achieve what you want by

a) modeling an abstract interface HttpServlet EClass whose instance name is javax.servlet.http.HttpServlet

b) modeling a regular MyServlet EClass that does NOT specify HttpServlet as a supertype

c) specifying rootExtendsClass="javax.servlet.http.HttpServlet" in your genmodel

The last step imposes a supertype on all EClasses, so if your model is bigger than MyServlet, you may need multiple EPackages and multiple genmodels so that you have a distinct EPackage/genmodel for each irregular rootExtendsClass. You can probably have a single master genmodel that uses all the partial genmodels so that you can still generate code in one step.

Since MyServletImpl extends HttpServlet rather than EObjectImpl, you will have to implement/delegate all the inherited EObject functionality just as Ed Merks observed. But since you're not really using EMF perhaps the default stubs will do.

If you plan to do significant work with Ecore and HttpServlet you would probably benefit from manually crafting an EHttpServlet that merges the EObject and HttpServlet inheritances allowing the resulting usage in Ecore to be regular.

Regards

Ed Willink

[Updated on: Fri, 19 November 2021 08:52]

Report message to a moderator

Re: Modeling Servlet in EMF [message #1848121 is a reply to message #1848079] Sun, 21 November 2021 23:08 Go to previous message
Joel Craig is currently offline Joel CraigFriend
Messages: 2
Registered: November 2021
Junior Member
Thanks to you both for your time! I've been using EMF for several years and thought that it would be difficult at best, but wanted to ask the experts. I appreciate the guidance. If our company moves in the direction of creating many servlets, I'll consider crafting the EHttpServlet. Thanks for the help!
Previous Topic:[CDO] Documentation is unavailable
Next Topic:[CDO] Startup error on linux getConfig().getBufferProvider() == null
Goto Forum:
  


Current Time: Thu Apr 25 22:22:17 GMT 2024

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

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

Back to the top