This chapter gives an overview of the website generation project. Firstly the existed problems in developing website are discussed. Secondly the general idea of the project, typically the functionalities and the applied technologies are introduced. Lastly the objectives of the project are given.
Due to the fast development of web technologies, it is convenient for people to get access to the Internet. The ubiquitous internet access leads to an explosion of websites. In Netcraft (2010)'s report, there are more than 206 million websites in the world, which means the number of websites nearly doubled since 2006. However, in comparison of the rapid growth of websites, the method of developing website remains mostly the same in recent years. To build a website from scratch requires the developers to have complex knowledge and skills. In addition, hand crafting websites tend to make flaws easily. These are the limitations of hand crafting websites.
One possible way to solve this problem is to encapsulate the develop practises into a model and to combine this with automatic generation of the implementation code. Usually, this approach refers to Model-Driven Software Development (MDSD), which will be explicitly explained in 2.1. By using a code generation tool of website, the designers can focus on the content and data rather than to think of the mechanism of building a website. Meanwhile, it releases developers from doing repeated work. On the other hand, automatic code generator limited the ability of developers; developers can not fully control the generated contents.
This project aims to develop a tool that enables the generation of website from models. Because it is build on standard modelling environment (Eclipse Modeling Framework, EMF which will be introduced in 2.1.2), the developers can control and customise the final output.
This project will continue the development of a software tool which is provided by Dr. Andy Carpenter. The existed software is build by using both modelling and website developing technologies. It can generate a data intensive website that applying MVC (Model-View-Controller) pattern. The generated pages can perform all Create, update and delete (CRUD) functionality of the data, with multiple ways to achieve the result. The generated website can be deployed to a web server with modifying minimal places. In addition, it provided a graphical editor which enables the developers to build the website models; some validation features are also provided.
In order to achieve the best development practise of a website, some mature website frameworks are adopted. Spring framework is used as the website architecture. JSF is used as the presentation layer and page navigation technology. For data persistence technology, the generator output is the input of Hibernate. These framework concepts will be introduced in 2.2. With those technologies, the generated code can be assured of minimised amount and clearness.
Although the software gets some achievements, there are still some problems. Firstly, the Spring Framework experienced a major version update in December 2009. With Spring Framework 3.0, a lot of new features and new project management are included; some APIs or configurations are superseded by new realisations. The existed software is developed under Spring Framework 2.5, as a result, it needs to be revised to be compatible with Spring Framework 3 as well as to gain the new features.
Secondly, the existed software does not apply clear web service architecture. By applying web service architecture such as Representational State Transfer (REST) or Simple Object Access Protocol (SOAP), the code of the website will be easy to understand. Especially, RESTful framework allows restricting the building of bloated controllers and treating all function calls as a HTTP request (Main, 2009). In the newest version of Spring Framework, the support of REST template is provided, which makes the migration to a RESTful framework possible.
At last, there is no authorisation & authentication functionality in the software. As an available data intensive website, basic authorisation & authentication such as password protected pages is desired. By adding those security features to the software, it will become a more effective tool of building websites.
From the information presented above, the objectives of the project should be clear:
- Upgrade the generated website to be compatible with Spring Framework 3.0.
- Refine the web service framework of the generated website to a RESTful framework.
- Enables password based authentication of the website.
This chapter will give an overview of the technologies that are important for understanding the project. The first section introduces the technologies of model-driven software development; it helps to understand the model transformations and how the website is generated. The second section introduces the knowledge of the generated website; it gives the idea of what the website will look like. The last section discusses the REST web service architecture, which is important for refining the project.
Model-Driven Software Development
Models provide a physical system abstraction to solve specific problems. The recent innovations of modelling approaches focused on tools that allow the users to describe the system perspectives in terms of that can be mapped into a programming language code. This kind of approaches is usually referred as MDSD. By concentrating on model driven approaches, it is possible to increase the productivity and simplifying the process of design.
The perspectives such as model representation and code generation require an unambiguous way to describe the semantics of the models. Thus, the abstraction model which highlighting properties of the model itself are called as meta-models (Brown, 2005). The process of constructing a collection of meta-models is called metamodeling. For example, the Object Management Group (OMG) proposed a language to write meta-models called the Meta Object Facility or MOF; it defines the widely used Unified Modeling Language (UML) with its meta-models. With UML a complex software system can be described.
The OMG also designed a model-driven software design approach which is known as Model-driven Architecture (MDA) . MDSD follows a lot of the principles of MDA, but they are not the same thing. MDA is restricted by only using the MOF and UML based technologies, in contrast of MDSD can focused on a specific domain such as building website and use customised meta-models.
Eclipse Modeling Framework
Eclipse Modeling Framework (EMF) is one of the most important tools for MDSD. Before introducing EMF, it is necessary to know what Eclipse is. Eclipse is probably the most welcomed multi language software development IDE. It is free and open source software and supports extensible plug-in system. Most of the plug-ins is developed as a part of Eclipse project, one famous example of them is EMF.
EMF is a modelling framework and code generation facility for developing application or tools based on a structured data model. It also provides the ability of define models by any of those forms: Java, XML and UML. In addition, the most important feature provided by EMF is interoperability between the diversities of EMF based tools and application. The modelling technologies used in this website generation project, such as ATL and JET which will be introduced later, are based on EMF.
The meta-model of EMF is called Ecore. The simplified subset of the Ecore metamodel is given in Figure 1. It only shows the essential concepts such as class, attribute, reference and data type. It is a little similar to UML meta-models, but Ecore is a small and simple subset of UML, which only have some naming differences between Essential MOF (EMOF). UML supports more ambiguous kinds of models than that in Ecore. Due to the experience, Ecore is developed as an effective Java implementation of MOF (The eclipse foundation, 2010).
One problem of editing Ecore model is the editor. EMF provided a tree-view graphical editor for Ecore; however, it is not a good solution for writing complex models. To solve the problem, Emfatic provided more human readable syntax which is similar to Java to present and edit Ecore. It supports hierarchy view, hyperlinks, auto code completes (Bigeardel and Garcia, 2010). The model of the website generate project is developed by using Emfatic.
Secondly, the PIM will be transformed to a series of Platform Specific Model (PSM). A PSM contains the implement technology; it is linked to a specific operation system or programming language. For example, the data of a website can be expressed as a PIM; the developer can use several technologies to present the data structure, such as Java classes, database tables or XML document, these are the PSMs. (See Figure 2)
The implementation of model-driven approach can be treated as a sequence of different model transformations. The transformation from a model to another model with a different abstraction level is called Model to Model transformation (M2M). The most common way to use M2M is to transform models from PIM to PSM, or in other words, from a higher abstract level model to the lower one. This result can be achieved by using model transformation languages (MTL).
Although several MTL exist, Atlas Transformation Language (ATL) is probably the most widely used one, due to the two reasons: it has a large user community, and it is a component of EMF. It takes a set of input model and generates the output models. The most important part of an ATL file is the rules that define how the input model elements match the output model elements. Figure 3 shows a basic example of how ATL works. It translates the person model to contact model where only function name equals "Boss" will be translated.
Among those M2T technologies, Java Emitter Template (JET) is an ideal code generator. It is a component of EMF M2T project, with the ability of a generic template engine that can generate Java or other programming language code. The syntax JET used is similar to Java Server Page (JSP). Because of the widely use of JSP, the JSP-like syntax makes it easy to write the code template. The mechanism of JET is like JSP. In JSP firstly the JSP page is defined, then the JSP page is complied to Java servlet that is used to generate HTML page. In contrasting of JET, first of all the JET template should be developed, and then the template is translated to Java classes with a method named "generate()" which is ready to generate code.
Web application framework
Because the web pages and other source code are generated by a model-driven approach, the quality of the code has to be sure of high level. To gain this a proper web application framework should be adopted. By adopting web application framework, it is possible to write code that is easy to read and alter. There are varieties of web application frameworks for Java EE application, such as Spring Framework, Apache Struts 2 or JBoss Seam. The website generation project adopts Spring Framework because the popularity and fast development of Spring.
The Spring Framework is an application framework for Java and .NET platform that provides complex infrastructure, so the developer can focus on the logic of the application rather than the architecture. Although Spring Framework supports to develop any kind of application, the most common use of Spring Framework is to develop Java EE application. It is treated as a light weight alternative to the EJB model in Java community while it gains popularity (springsource, 2010).
The core of Spring Framework is based on the principle of Inversion of Control (IoC) (Chakraborty et al, 2008). IoC means that the application does not control its structure; the Spring IoC framework will do that. For example, if a class A that depends on class B to do some operations, traditionally, A creates a instance of B in a function. In this method A and B are coupled with a hard dependency. When moving the logic to a new environment, the code needs to be changed. By using IoC, it is possible to develop disparate components. In the example, the instance of B will be provided to A at runtime by Spring. It makes the objects reusable by separating the control logic from different objects. By using Spring IoC container, the configuration file will be used to manage the dependencies between different objects.
Spring Framework experienced a major upgrading in December 2009, from version 2.5 to 3.0. A lot of new feature and enhancements are included. Those which are important to the website generation project are listed as below (Springsource, 2010):
- The framework code has been revised to take advantage of Java EE 5.
- New module organisation and build system. The spring.jar artefact which enclosed almost the entire framework does not exist. The framework modules are managed separately with one source tree per jar file.
- Comprehensive REST support.
- Core features from the JavaConfig project have been added to the Spring Framework.
Java Sever Faces
JavaServer Faces (JSF) aims to establish the standard for building server-side user interfaces (Oracle, 2010). It provides an easy user interface programming model that can gain the benefits of the high-performance backend of Java EE technologies. JSF has these parts (Geary and Horstmann, 2007):
- A set of prefabricated UI (user interface) components
- An event-driven programming model
- A component model that enables third-party developers to supply additional components
The traditional relational database model for the data persistence of website will cause the mismatch between the programming model and the persistence model, because most of the programming languages are object-oriented. To solve the problem, Object-relational mapping (ORM) provides a programming model that can convert the object-oriented data to the type systems in relational database. The use of ORM will reduce the code that needs to be written; in addition it will decrease the difficulty of migrate from one database system to another.
Hibernate is an ORM library for Java and .NET platform. It is developed by JBOSS Community as free and open source software. Figure 4 shows that, Hibernate stands in the middle of the programme persistence objects and the database; with the right XML configuration files, Hibernate will generate the SQL scripts for managing the data. Hibernate is widely supported by other programming frameworks, for example, Spring Framework provides the APIs and templates to integrate Hibernate.
With the technologies of Spring, JSF and Hibernate, a data intensive website can be build; nevertheless, in reality more advanced features are desired. Especially, security requirements such as authorisation and authentication are important for a website. Java EE framework has provided some security controls, for example, protecting web pages in particular path. More advanced protections need to be coded by hand. There is software that aims to simplify the security coding of a website, Spring Security is one of the best choice for Spring Framework.
Spring Security is probably the most widely used Spring projects, it is formerly known as the Acegi Security System for Spring. It is easy to learn, deploy and manage, making complete web application security possible by a few XML configuration (springsource.org, 2010). The main features of Spring Security (springsource.org, 2010) are summarised below:
- It is easy to configure by Spring IoC container.
- It can keep the application objects free of security code. In other words, it is non-invasive; when adding security to an application, no big change of the code is needed.
- It provides comprehensive authorization services. It can protect static URLs defined by regular expressions; it provides special authorisation for RESTful requests; and there are a lot of options for accessing control.
- It supports kinds of authentication back ends. Authorisations can be granted by an XML file, database or a property file. Also, the developers can easily implement customised authentication details.
This chapter discusses the research method issues. The agile software development methodology is outlined at first. Then the project framework and initial design are introduced. The test approach is discussed next. The software tools are listed in 3.4. The development plan is given in 3.5 which are presented as a Gantt chart. The limitations of the project are discussed at last.
Software development methodology
Agile software development
The project will be developed under the principle of agile software development. Agile is based on iterative and incremental development. The initiative of iterative and incremental development is to develop deliverable versions of the software incrementally by repeating the development process until the final version is done. The examples of iterative and incremental development are Spiral model, the Rational Unified Process (RUP) and agile.
One significant difference between agile and other iterative development is that agile usually break the functionalities into small increments with minimal time span. An iterative process lasts from one to four weeks in contrasting of Spiral model which will last for months. Each iterative process often consists of a small water-fall process, including planning, requirements analysis, designing, coding and testing. Agile also encourages face to face communication between team members rather than writing documents.
Agile has some obvious advantages over water-fall model. Water-fall model is inflexible because each stage of the process is fixed, it is hard to go back when the requirement changes. In comparison, agile takes working software as the most important measurement of progress; agile will deliver completely developed and tested functionalities after each time period. In other words, if the software developed under water-fall model is cancelled before the coding stage, there is no generated product; however, agile model will get some features if the project is cancelled.
The other claimed advantages of agile are more productivity, higher software quality, higher business stakeholder satisfaction and lower cost (Ambler, 2009). Because agile model is young, there is not sufficient proof of successful large software project, but there are evidences for that agile works well for small team (Boehm, 2003) .
The reasons of why this project adapts agile model are obvious. The project is a small project developed by a small team; the lasting time of the project is about 4 months. The requirements are likely to be changed. If the development process is fast, other features might be added to the project. Because the development of this project is mostly altering the exist code, it is significant to keep every workable version of a development process. If the developer make some wrong when updates the software, it is easy to go back to a workable version. This is a project developed by only one person, as a result, the advantages of communication in agile can not be gained; nevertheless the other parts of the project are suitable for adopting an agile model.
With the understanding of the background knowledge, now the general architecture of the software can be analysed. It is significant to have a comprehensible idea of the model transformation flows, which is shown in Figure 5. Firstly the relevant concepts of the website are explained by the website meta-model; with the understanding of the meta-model, a graphical editor is used to define the website PIM. Then the PIMs are transformed to two major PSMs: persistent PSM and website PSM.
The persistent PSM describes the data entities of the website; it is transformed to the persistence and business logic artefacts. In order to enable the customisation of the website, the user should define the Website Option and Choice model. Combining the original PIM, the website artefacts are generated. The Website PSM and option models define the content, the webpage and the navigating sequence of the website. With the option model, the user can configure to use what kind of HTML tags to present the data - a checkbox, a radio box or something else. The software has some validations during the editing stage. It can tell the user if the model is not formatted, such as illegal model name or duplicated attributes.
The development process of this project is divided into two parts:
- Analysis of the existed code
- The code development stage apply agile model
Because the project has not been delivered to the author, most of the understandings of the project come from the discussion with the supervisor and the project document. As a result, some time for analysing the code is needed. In this stage, the model definitions, the mechanism of model transformations and the code generate templates will be learned. Thus consistent code style and lower mistakes will be gained in the development stage.
The development stage will apply agile model. The development period is divided into several iterating process, each of them lasts for a week. In each iterating process, one or two tasks from the task list is selected, there will be designing, coding and testing for those tasks. In the end of the iterating process, a snapshot of the project is archived, and the working software version will be delivered. Then another iterating process will repeat, until all the tasks are finished.
How to implement the project objects mentioned in chapter 1 is discussed in this section.
Object 1: Upgrade the project to Spring Framework 3.0
The initial work for this object is to upgrade the library of the website by changing the jar files to the higher version. Jar files of the software are needed. Because of the backward compatibility, the project will probably work, but this object is not as easy as only changing some files; the feature of Spring Framework 3 should also be gained.
Spring 2.5 uses XML to manage the dependency injections, but in Spring Framework 3 Java annotations are suggested to be used. Although as a code generator, there is no significant difference between those when writing the template, but considering the manual maintenance of the code, Java annotation has its excellence. When there are a lot of managed beans, the XML file becomes hard to read and maintain; all information is stored in a big XML file. In comparison, Java annotation is easy to read due to its Java grammar, and also the dependency injection management is divided to a set of Java annotation files, which makes it easy to read and maintain.
To achieve this object, most of the work are altering and developing the JET template files. It includes the dependency injection management file and the Hibernate data mapping XML file.
Object 2: Change the web architecture to REST style
As REST web service style gets its popularity, Java provides its own REST support which is known as JAX-RS (Java API for RESTful Web Services, JSR 311). However, as a specification, it is not easy to use with only providing the sever side Java annotation support (Duskis, 2008). To solve the problem, several independent implementations of JAX-RS exist, for instance, Jersey, RESTEasy and Restlet (Poutsma, 2009). Spring MVC 3 also provides both sever and client support to develop RESTful software. But this project did not use Spring MVC as its presentation and middle layer technology, so the new feature of REST cannot be gained in this project. Instead of that, this project will use Jersey to achieve the REST support.
Jersey project offers an implementation of JSR 311. It is developed by Sun, making it easy for developers to use, and provides features not specified in JSR 311 such as client annotations. In contrasting of other implementations, it is agreed by some developers that Jersey is easy to be started with and easy to develop ready to use product (Little, 2008). It is suitable for this project in the point of limited time.
To achieve this object, those works have to be done:
- Configure the web server to make sure the Jersey library work correctly.
- Alter the JET template of the servlet configuration, identify the Jersey library.
- Add relevant Java annotations to every CRUD functionality template. Typically, every CRUD class should be decorated by @path to specify the right URI pattern. @get, @put, @update, @delete should be used to specify the REST request handler method.
- Modify the JSP file template, change URL to rest style and change the request CRUD request to REST style.
Object 3: Enables password based authentication of the website.
There are different authentication methods that are supported by Spring Security. The basic examples are to use a XML file which stores the user name and the encoded password; another is to store the password and user name in the database and map it as the authentication information. In a more complex system, there might be several subsystems; each of them uses their separate database system. In this condition, the user might be required to manage multiple account records, which is not safe and not convenient. One possible solution is to use a central authentication service, each of the subsystem deliver the security request to the server, and the server will grant or discard the request. This approach can be achieved by telling Spring Security the information of authentication class.
To achieve this object, firstly the PSM of webpage should be modified. The attribute of the security option should be added to identify what kind of user can access this page. The persistence should also be added with the security option to identify who can perform a CRUD request of the persistent model. The next work is to write the JET template for the configuration file of Spring Security. Al last, the template of protected JSP files should be covered with the security tags provided by Spring Security.
Test is an important part for software development. Especially in agile model, testing is iterated in each development period to ensure the quality of the delivered software. In addition, the Spring Framework encourages the developer to use test-driven development approach, which suggests writing test case before writing the code. In model-driven world, some automatic test approaches are developed. One possible way to achieve automatic test is to develop a test framework that enables automatic model generation and validating the model (Conrad, 2004). However, there will be much effort on developing test tools and learning how to achieve that; there is not enough time for carrying out an automatic test. Instead of that, the test will mostly be checked manually. Although the test method is largely informal, the developer will try to write comprehensive test case and to keep the quality of the software.
The testing activity in this project will include two stages.
- The first one is to test if the contents of every generated artefact are the same as expected. When one feature is implemented, several small test models will be written and generated. The result will be checked manually by reading the code and deploying it to a web server to see the result. This stage will be combined with the implementing process.
- The second one is to test the functionality of the whole generated website. A complex model will be developed; the generated website will be deployed to a web server. All the CRUD functionality and security functionality will be checked by manually execute the request. This stage will be performed at the end of the implementation period.
The project plan is shown as a Gantt chart in Figure 7. Generally the project plan includes 3 main stages: preparation, implementation and writing up dissertation. Because the project use agile model, in the end of each implementation week a workable version of software should be delivered, so the time for testing is included in the implementation period.
As a result of the limited experience and time of the author, there are some limitations in this project:
- The design of the project is largely based on the understanding of the documentation; the original code is not gained yet. This might lead to a change of plan and development. To reduce the impact, some time is reserved for analyse the code in the project plan.
- The development tools are developed by independent parties, which make dependency management very complex. Developers must pay special attention to the version and dependency library in order to ensure the project work properly.
- The functionality of the generated website is limited. In reality, the feature of the software probably can not satisfy the developers. Especially, more complex business logic is needed to present, which is lacked in this project.
The project is expected to improve the quality and to add new feature to the existed website generation project. In the background report stage, the majority of the work is to learn the needed knowledge and technology. The report also demonstrates the author understands of the project architecture, including both the code generation tool and the generated website. Then the development method - agile model is introduced, and how this project will apply agile model is discussed. The general design of the project is introduced at last, including the design approach for each project object, the used tools and the project plan.
The efforts of improving the software will make the website generation software more applicable for reality use. Limitations exist in the software; it cannot generate functionality that is not provided, the layout of the webpage is simple. However, the project can significantly reduce the repeated work of developing data intensive website.
The further work of the project is to make the software more applicable for real world use. The possible features that should be added to the project includes:
- Change the layout of the webpage, enables the configuration of CSS style or use a theme library to change the looking of the webpage, such as to use JQuery to decorate each presentation component.
- Enable more business logic choices. It can be achieved by providing a portal for the customised code. The developer can develop their own logic class then tell the software the information, and the software will combine those classes.
- Enable the generation of more kind of webpage. Especially, the index page is useful for a website, which is not included in this project.
- AllAppLabs.com (2009). 'HIBERNATE - Overview of Hibernate'. http://www.allapplabs.com/hibernate/overview_of_hibernate.htm.
- S.W. Ambler (2009). 'Answering the "Where is the Proof That Agile Methods Work" Question'. http://www.agilemodeling.com/essays/proof.htm.
- Barry (2003). Balancing agility and discipline: a guide for the perplexed. Addison-Wesley.
- M.G. Bigeardel (2010). 'Emfatic'. http://wiki.eclipse.org/Emfatic.
- J.M. Chakraborty (2008). Pro Spring 2.5. Apress.
- S.Duskis (2008). 'Java RESTful clients and JAX-RS'. http://java.dzone.com/articles/java-restful-clients-and-jax-r.
- T.eclipse foundation (2010). 'ATL/User Guide - Overview of the Atlas Transformation Language'. http://wiki.eclipse.org/ATL/User_Guide_-_Overview_of_the_Atlas_Transformation_Language#Structure_of_an_ATL_module.
- R.T. Fielding (2000). Architectural Styles and the Design of Network-based Software Architectures. Ph.D. thesis, UNIVERSITY OF CALIFORNIA, IRVINE.
- T.E. Foundation (2010). 'Eclipse Modeling Framework Project (EMF)'. http://www.eclipse.org/modeling/emf/? project=emf.
- D.G. Horstmann (2007). Core JavaServer Faces, Second Edition. Prentice Hall.
- M.Little (2008). 'A Comparison of JAX-RS Implementations'. http://www.infoq.com/news/2008/10/jaxrs-comparison.
- J.Main (2009). 'The (Many) Benefits of RESTful Development'. online.
- Netcraft (2010). 'March 2010 Web Server Survey'. http://news.netcraft.com/archives/2010/03/17/march_2010_web_server_survey.html.
- Oracle_Corporation (2010). 'JavaServer Faces Technology'. http://java.sun.com/javaee/javaserverfaces/.
- A.Poutsma (2009). 'REST in Spring 3: @MVC'. http://blog.springsource.com/2009/03/08/rest-in-spring-3-mvc/.
- Springsource (2009). 'New Features and Enhancements in Spring 3.0'. http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/new-in-3.html.
- Springsource (2010a). '1. Introduction to Spring Framework'. http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/overview.html.
- Springsource (2010b). 'Spring Security C Main Features'. http://static.springsource.org/spring-security/site/features.html.
- Springsource (2010c). 'Welcome to the Spring Security Website'. http://static.springsource.org/spring-security/site/index.html.
- I.Sturmer & M.Conrad (2004). 'M.Conrad: Code Generator Testing in Practice'. GI Jahrestagung 2:33-37.
- A.B. Tropeano (2005). Model-Driven Software Development. Springer.