AN APPROACH TO DOMAIN DRIVEN WEB APPLICATION DEVELOPMENT MSC IN COMPUTER SCIENCE GAYAN DASANAYAKE UNIVERSITY OF MORATUWA SRI LANKA OCTOBER, 2007 i AN APPROACH TO DOMAIN DRIVEN WEB APPLICATION DEVELOPMENT Gayan Dasanayake This dissertation was submitted to the Department of Computer Science and Engineering of the University of Moratuwa in partial fulfillment of the requirement for the Degree of MSc in Computer Science. Department of Computer Science and Engineering University of Moratuwa Sri Lanka October, 2007 ii Declaration I hereby declare that the work included in this dissertation has not been submitted in part or whole for any other academic qualification at any institution. .................................................................. W. G. P. Dasanayake .................................................................. Mr. Chandika Mendis (Supervisor) iii Abstract Over the past years programming languages have evolved from machine languages to assembly language and to high level languages. All this time the development abstraction has steadily moved up towards the domain. Today through Domain Driven Development (DDD) the application developer significantly benefits from the ease of application creation and maintenance. Thus DDD has become a very promising new area of research. However in DDD more information is needed in the domain model and more effort is needed in the subsequent transformation to the other end. The model needs to capture and represent all the necessary information of the business solution and the transformation should transform it to the target feature rich IT solution. This concept of “programming” at the domain level fundamentally differs from mere code generation. The focus here is on creating complete, readily executable applications from the model. This paper presents a framework and methodology for rich web application development based on the domain model. This includes a UML profile for web application modeling, XMI based model serialization, model transformation logic utilizing XSLT/XPath, a web application utilizing a component based web framework with a wide range of emerging technologies and a tool as proof-of-concept which can effectively be used for domain driven web application development. iv Acknowledgments This thesis is the result of a research project carried out with the invaluable assistance of many people for whom I must be thankful. Firstly, I wish to express my sincere thanks to my supervisor Mr. Chandika Mendis who gave me this very interesting research project idea, and also gave me invaluable knowledge in this area. The support and guidance he gave especially on “where to look” in a huge world of tools and technologies was imperative to the success of the project. My earnest thanks go to Dr. Sanath Jayasena for the support he gave. If it wasn’t for the continuous motivation he gave to all of us to do the project, it would have been impossible to finish the project in time. I must also be thankful for my employer IFS R&D International Pvt Ltd for granting me adequate leave for me to attend to the research. Finally, I wish to thank all my MSc batch mates who gave ideas and their views on my project which was also extremely helpful. Thank you all! v Table of Contents DECLARATION ........................................................................................................................................... II ABSTRACT ................................................................................................................................................ III ACKNOWLEDGMENTS ............................................................................................................................. IV TABLE OF CONTENTS ................................................................................................................................ V LIST OF FIGURES ...................................................................................................................................... IX LIST OF TABLES ......................................................................................................................................... X LIST OF SYMBOLS, NOTATIONS, ABBREVIATIONS AND ACRONYMS ....................................................... XI 1. INTRODUCTION ........................................................................................................................... - 1 - 1.1 PROBLEM DEFINITION ......................................................................................................................... - 2 - 1.2 OBJECTIVES ....................................................................................................................................... - 3 - 2. LITERATURE REVIEW ................................................................................................................... - 4 - 2.1 LITERATURE REVIEW ON METAMODELING .............................................................................................. - 4 - 2.1.1 Meta Object Facility (MOF) .................................................................................................- 5 - 2.1.2 UML metamodel ..................................................................................................................- 5 - 2.1.3 UML Extension Mechanisms ...............................................................................................- 6 - Graphical representation of extension mechanisms ..................................................................................... - 8 - 2.1.4 UML Profiles versus Metamodel extensions .......................................................................- 8 - 2.2 LITERATURE REVIEW ON MODEL SERIALIZATION ...................................................................................... - 9 - 2.2.1 XML Metadata Interchange ................................................................................................- 9 - 2.2.2 Drawbacks of XMI ............................................................................................................. - 10 - 2.3 LITERATURE REVIEW ON MODEL TRANSFORMATION .............................................................................. - 11 - 2.3.1 Model transformation techniques ................................................................................... - 11 - 2.3.2 QVT and model transformations ...................................................................................... - 13 - 2.3.3 XSLT based transformations ............................................................................................. - 13 - XSLT ............................................................................................................................................................... - 13 - XPath ............................................................................................................................................................. - 14 - XSLT Processing ............................................................................................................................................. - 14 - XSLT Processors ............................................................................................................................................. - 14 - LITERATURE REVIEW ON WEB APPLICATION TECHNOLOGIES .............................................................................. - 16 - 2.3.4 Web application frameworks ........................................................................................... - 16 - 2.3.5 Tapestry ............................................................................................................................ - 17 - vi 2.4 LITERATURE REVIEW ON OBJECT RELATIONAL MAPPING ......................................................................... - 18 - 2.4.1 ORM frameworks.............................................................................................................. - 18 - 2.4.2 Hibernate .......................................................................................................................... - 19 - 2.4.3 Active Record .................................................................................................................... - 19 - 2.5 LITERATURE REVIEW ON RELATED WORK .............................................................................................. - 20 - 2.5.1 Rails ................................................................................................................................... - 20 - Convention over Configuration .................................................................................................................... - 20 - 2.5.2 Grails ................................................................................................................................. - 21 - 2.5.3 Trails .................................................................................................................................. - 22 - 2.5.4 Model Driven Architecture (MDA) .................................................................................... - 22 - 2.6 DOMAIN DRIVEN DEVELOPMENT IN PRACTICE ....................................................................................... - 23 - Benefits of the approach .............................................................................................................................. - 23 - Changes in the organization ......................................................................................................................... - 24 - 3. MODELING ................................................................................................................................ - 25 - 3.1 CREATING THE UML PROFILE ............................................................................................................. - 25 - 3.1.1 Stereotypes ....................................................................................................................... - 25 - 3.1.2 Tagged Values for DomainEntity ..................................................................................... - 26 - 3.1.3 Tagged Values for PropertyString .................................................................................... - 26 - 3.1.4 Tagged Values for PropertyNumber ................................................................................ - 26 - 3.1.5 Tagged Values for PropertyDate ...................................................................................... - 27 - 3.2 TOOL SUPPORT FOR CUSTOM PROFILES ................................................................................................ - 27 - 4. MODEL SERIALIZATION ............................................................................................................. - 29 - 5. MODEL TRANSFORMATION ...................................................................................................... - 30 - 5.1 XSLT STYLESHEETS ........................................................................................................................... - 30 - 5.2 NAVIGATING THE MODEL ................................................................................................................... - 30 - 5.3 TRANSFORMATION PARAMETERS ......................................................................................................... - 31 - 5.4 GENERATING MULTIPLE FILES .............................................................................................................. - 31 - 5.5 PRETTY PRINTING THE OUTPUT ............................................................................................................ - 32 - 6. TARGET WEB APPLICATION ...................................................................................................... - 33 - 6.1 SYSTEM OVERVIEW ........................................................................................................................... - 33 - 6.2 PROVIDING FUNCTIONALITY ................................................................................................................ - 33 - 6.3 ASSOCIATED DOMAIN ENTITIES ............................................................................................................ - 36 - 6.4 AGGREGATED DOMAIN ENTITIES ......................................................................................................... - 37 - 6.5 CONFIGURABLE PROPERTIES................................................................................................................ - 38 - 6.6 VALIDATIONS ................................................................................................................................... - 40 - vii 7. ORM AND OBJECT PERSISTENCE ............................................................................................... - 41 - 7.1 HIBERNATE USAGE ............................................................................................................................ - 41 - 7.2 POSTGRESSQL USAGE ....................................................................................................................... - 42 - 8. THE TOOL .................................................................................................................................. - 43 - 8.1 SETTING TRANSFORMATION PARAMETERS............................................................................................. - 43 - 8.2 PERFORM XSLT TRANSFORMATION ..................................................................................................... - 44 - 8.3 SETTING THE XSLT PROCESSOR ........................................................................................................... - 44 - 8.4 BUILD AND DEPLOY ........................................................................................................................... - 45 - 8.5 BROWSING THE GENERATED FILE STRUCTURE ......................................................................................... - 46 - 8.5.1 Providing syntax highlighting ........................................................................................... - 46 - 9. ANALYSIS ................................................................................................................................... - 48 - 9.1 COMPARISON WITH RAILS .................................................................................................................. - 48 - 9.2 COMPARISON WITH TRAILS................................................................................................................. - 49 - 9.3 COMPARISON WITH MDA TOOLS........................................................................................................ - 49 - 10. FUTURE DIRECTIONS ................................................................................................................. - 50 - 10.1 MORE CROSS CUTTING CONCERNS .................................................................................................. - 50 - 10.2 MORE MODELING SCENARIOS ........................................................................................................ - 50 - 10.2.1 State Chart Diagrams ....................................................................................................... - 51 - 10.2.2 Enumeration type classes ................................................................................................. - 51 - 10.2.3 Special handling for inheritance hierarchies .................................................................... - 51 - 10.3 MORE FEATURES ......................................................................................................................... - 52 - 10.3.1 Domain Entity Search ....................................................................................................... - 52 - 10.3.2 Full AJAX support .............................................................................................................. - 52 - 10.3.3 Application Search ............................................................................................................ - 52 - 10.4 DECOUPLING FROM TECHNOLOGIES ................................................................................................ - 53 - 11. REFERENCES .............................................................................................................................. - 54 - 11.1 GENERAL .................................................................................................................................... - 54 - 11.2 MODELING ................................................................................................................................. - 55 - 11.3 MODEL SERIALIZATION ................................................................................................................. - 56 - 11.4 MODEL TRANSFORMATION ........................................................................................................... - 56 - 11.5 TARGET WEB APPLICATION ............................................................................................................ - 57 - 11.6 ORM AND DATABASE .................................................................................................................. - 58 - 11.7 TOOLS ....................................................................................................................................... - 58 - viii 12. APPENDIX A .............................................................................................................................. - 60 - ix List of Figures Figure 2-1 UML Metamodel – Top level packages ......................................................................... - 6 - Figure 2-2 UML Metamodel – The Foundation package .............................................................. - 6 - Figure 2-3 UML 1.4.2 Extension Mechanisms ................................................................................ - 7 - Figure 2-4 Graphical representation of extension mechanisms ................................................... - 8 - Figure 2-5 Basic concepts of model transformation ..................................................................... - 11 - Figure 2-6 XSLT Processing model ................................................................................................. - 14 - Figure 2-7 Active record example .................................................................................................... - 19 - Figure 6-1 System overview ............................................................................................................... - 33 - Figure 6-2 Page control classes created per domain entity .......................................................... - 34 - Figure 6-3 Service classes created per domain entity .................................................................... - 35 - Figure 6-4 Association example class diagram ............................................................................... - 36 - Figure 6-5 List of Values AJAX popup ........................................................................................... - 37 - Figure 6-6 Aggregation example class diagram .............................................................................. - 37 - Figure 6-7 Sample Domain Entity - Customer .............................................................................. - 38 - Figure 6-8 Configurable properties .................................................................................................. - 39 - Figure 6-9 Configuring a property .................................................................................................... - 39 - Figure 6-10 Translated display names .............................................................................................. - 39 - Figure 6-11 A typical range validation ............................................................................................. - 40 - Figure 8-1 The UI for setting the transformation parameters .................................................... - 43 - Figure 8-2 UI for one click generate, build and deploy ................................................................ - 44 - Figure 8-3 GUI for browsing the generated files .......................................................................... - 46 - Figure 10-1 Sample state chart diagram .......................................................................................... - 51 - x List of Tables Table 1-1 Savings in model driven approaches ................................................................................ - 2 - Table 2-1 Traditional four layer meta-modeling architecture ........................................................ - 5 - Table 2-2 OMG four layer meta-modeling architecture ................................................................ - 5 - Table 2-3 UML Extension Mechanisms ........................................................................................... - 7 - Table 2-4 Relationship between releases of XMI and releases of MOF ................................... - 10 - Table 2-5 List of model-to-model transformation approaches .................................................. - 12 - Table 2-6 List of model-to-text transformation approaches ....................................................... - 13 - Table 2-7 Popular XSLT Processors ............................................................................................... - 15 - Table 3-1 Stereotypes in the Proposed UML Profile ................................................................... - 25 - Table 3-2 Tagged Values for DomainEntity .................................................................................. - 26 - Table 3-3 Tagged Values for PropertyString .................................................................................. - 26 - Table 3-4 Tagged Values for PropertyNumber ............................................................................. - 27 - Table 3-5 Tagged Values for PropertyDate .................................................................................... - 27 - xi List of Symbols, Notations, Abbreviations and Acronyms AJAX Asynchronous JavaScript CRUD Create Retrieve Update Delete DDD Domain Driven Development DI Diagram Interchange DTD Document Type Definition GUI Graphical User Interface HTML Hyper Text Markup Language JAXP Java API for XML Processing JMI Java Metadata Interchange MDA Model Driven Architecture MDE Model Driven Engineering MOF Meta Object Facility OCL Object Constraint Language OMG Object Management Group ORM Object Relational Mapping PIM Platform Independent Model POJO Plain Old Java Object PSM Platform Specific Model QVT Query View Transform UI User Interface UML Unified Modeling Language W3C World Wide Web Consortium XMI XML Metadata Interchange XSD XML Schema Definition XSL Extensible Stylesheet Language XSLT Extensible Stylesheet Language Transformation