Showing posts with label jsp. Show all posts
Showing posts with label jsp. Show all posts

Friday, October 1, 2010

Using EMF to detect loops within a JSP

After my post explaining how to create EMF models from JSP pages, someone posted a comment on TheServerSide to know if the EMF model could be used to detect loops in the JSP (http://www.theserverside.com/news/thread.tss?thread_id=60980).

In fact, you can integrate loops in a JSP with several ways. The EMF model will represent these ways differently.

If you write a scriptlet containing a loop in Java (for, while, ...):

the EMF model created from this JSP will contain a JSPScriptlet object which contains the text of the scriptlet.
The discoverer currently provided by MoDisco does not parse the content of the scriptlet. It will be provided in a future version (after Indigo) by using the Java metamodel to represent the Java fragments contained in a scriptlet.

Another way for looping in a JSP can be achieved by using the "forEach" tag:

In this case, the EMF model will contain a JSPAction object whith the name of the tag ("c:forEach" here):

This EMF object contains children which are the attributes of the tag (var, items, varStatus, ...) and the sub elements of the tag (a JSPAction "c:choose" and an Element "tr"):


Monday, September 27, 2010

How to create EMF models from JSP pages ?

The next release of MoDisco (version 0.9) is under development and is planned to be released with Indigo. This release will come with new components for creating EMF models from the source code of JEE applications.

The current version (version 0.8) already provides components for creating EMF models from java source code (see this older post). In next version, new components will be dedicated to JSP reverse-engineering. They have been developped by Fabien Giquel and Nicolas Guyomar of Mia-Software.

They are composed of:
  • a metamodel for describing a JSP
  • a discoverer for creating a model from a set of JSP pages
  • a generator for generating JSP pages from a model
The JSP metamodel (defined with Ecore) is an extention of the XML metamodel (also provided by MoDisco) which contains types such as Page, JSPScriptlet, JSPExpression, JSPTagLib, etc.


The discoverer, is a component which analyzes JSP pages and creates an EMF model conforming to the JSP metamodel.

It can be launched from a project, or directly from JSP pages.

The result is an EMF model which can be opened with the MoDisco Model Browser.


The generator allows regenerating JSP files from an EMF model (conforming to the JSP metamodel). While it still needs to be improved to support a better formatting, yet it can already be used to produce JSP files.

With these new components, you can reverse-enginer JSP files and use EMF APIs in order to control coding norms, detect patterns, document existing pages or refactor them by applying transformation at the model level (and then use the generator to get a new version of your JSPs).