6.3 The Web Model to Code Transformation

6.3.1 The Structure of the Web Code

To implement the Web components , we have to generate code that handles user requests from the Internet and that produces HTML as a response. In general, the complexity of this code can be high. A good MDA tool provides its user with transformations that are highly complex, thus creating a fully functional and working application, using well-established coding patterns. In this book, however, we generate Web code with simple functionality using a simple coding pattern. Although this is clearly not a sufficient MDA solution, we avoid long discussions about complex Web coding solutions.

In this example, the Web part of the application is implemented according to the J2EE standard for Web tiers (Sun Microsystems, Java 2 Platform, Enterprise Edition Specification, Version 1.3, 2001). We generate code that generates simple HTML pages that hold query results only. The components are implemented using JSP (Sun Microsystems, JavaServer Pages Specification, Version 1.2, 2001). Each request from a user instantiates one JSP and the resulting HTML is sent back to the browser. We generate exactly one JSP file for each Web component. At run-time, the JSP produces an HTML page containing a table with rows that correspond to all objects of one type (e.g., all customers) and columns corresponding to the attributes of that type (e.g., address and account number).

The JSPs access the data from the EJB components by iterating over a set of EJB Data Objects and getting the values of the attributes provided by them. The iteration is implemented in embedded Java code. The JSP code uses the EJB data object manager for the retrieval of the data objects. JSP supports the access of get methods for the attributes by simply stating the names of the attributes.

6.3.2 The Transformation Rules

The following rules are used to generate the JSP code from Web Components and the Web Data Classes:

  • For each Web Component one "query" JSP file is generated with the same name as the Web component.

  • Within each query JSP one header is generated containing one name per attribute.

  • Within each query JSP one "useBean" element is generated to get access to the remote interface of the corresponding EJB entity bean.

  • Within each query JSP one iteration is written in embedded Java using the EJB data object manager to get the collection and iterate over the set of EJB data objects.

  • Within each iteration one HTML row is generated with a "getProperty" element for each attribute of the served data class.

  • One JSP named "MainMenu" is generated.

  • For each Web Component one URL is generated in the Main Menu JSP to access the corresponding query JSP.

  • One HTML file is generated that starts up the main menu.

  • One property file is generated with the static text on the HTML pages.

  • One JSP named "AppError" is generated to display exceptions to the user.

In Appendix B, you can find some fragments of the generated code.



MDA Explained. The Model Driven Architecture(c) Practice and Promise 2003
Project Leadership (The Project Management Essential Library)
ISBN: N/A
EAN: 2147483647
Year: 2004
Pages: 118

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net