Modeling Servlet in EMF [message #1848066] |
Thu, 18 November 2021 16:28  |
Eclipse User |
|
|
|
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 00:35   |
Eclipse User |
|
|
|
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.
|
|
|
|
Re: Modeling Servlet in EMF [message #1848121 is a reply to message #1848079] |
Sun, 21 November 2021 18:08  |
Eclipse User |
|
|
|
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!
|
|
|
Powered by
FUDForum. Page generated in 0.08235 seconds