Evaluating Large Scale Modular Web-Based Application ...

unalaskaweepingInternet and Web Development

Jul 19, 2012 (5 years and 1 month ago)

592 views


Evaluating Large Scale Modular

Web
-
B
ased Application Development
with Google Web Toolkit

Model View Presenter





















M A R T I N F I N N S T R Ö M
















































M a s t e r o f S c i e n c e T h e s i s


S t o c k h o l m, S w e d e n
201
1




Evaluating Large Scale Modular

Web
-
B
ased Application Development
with Google Web Toolkit

Model View Presenter
















M A R T I N F I N N S T R Ö M






Master’s Thesis in Computer Science (
30 ECTS

credits)


at the School of Computer Science and Engineering


Royal Institute of Technology year
201
1



Supervisor at CSC was
Stefan Nilsson


Examiner was
Stefan Arnborg



TRITA
-
CSC
-
E
201
1
:
104


ISRN
-
KTH/CSC/E
--
1
1
/
104
--
SE


ISSN
-
1653
-
5715







Royal Institute of Technology


School of Computer Science and Communicatio
n



KTH

CSC


SE
-
100 44

Stockholm, Sweden



URL: www.kth.se/csc







Abstract
This thesis evaluates the model view presenter pattern that can be
used when developing web applications with Google Web Toolkit.The
project produced a prototype of a calendar module as a means of test-
ing the pattern practically and incorporates dependency injection via
Google Gin.The prototype uses a dispatcher model with action re-
sult handler for communication from client to server.This thesis also
gives backgrounds to all the frameworks which are used and their fu-
ture stability and level of documentation.This is meant to establish a
foundation for building a large modular application entirely in Google
Web Toolkit.
Evaluering av storskalig
webbaserad utveckling med
Google Web Toolkit Model
View Presenter
Sammanfattning
Denna avhandling utvärderar model view presenter mönstret som kan
användas vid utveckling av webbapplikationer med Google Web Toolkit.
Det byggdes en prototyp av en kalendermodul för att pröva på mönstret
praktiskt och modulen använder sig av dependency injection via Google
Gin.Prototypen använder sig av action result handlers för att kommu-
nicera mellan klient- och serverdel.Avhandlingen kommer också att ge
en bakgrund till alla de verktyg som användes och deras dokumenta-
tionstandard och framtida stabilitet diskuteras också.Detta projekt är
tänkt att bidra med en grund för att bygga ett stort modulärt projekt
helt i Google Web Toolkit.
Contents
1 Introduction 1
2 Important Results 3
3 Background 5
3.1 Eclipse...................................5
3.2 Google Web Toolkit...........................5
3.2.1 Model View Presenter......................6
3.3 Gin and Guice..............................6
3.4 Apache Maven..............................7
3.5 Spring Security..............................7
3.6 Hibernate.................................7
3.6.1 Hibernate Annotations......................8
3.7 EasyMock.................................8
4 Problem Statement 9
5 The Frameworks 11
5.1 Licensing and Open-source.......................11
5.1.1 Eclipse...............................12
5.1.2 Google Web Toolkit.......................12
5.1.3 Apache Maven..........................12
5.1.4 Spring Security..........................12
5.1.5 Hibernate.............................12
5.1.6 EasyMock.............................13
5.2 Documentation..............................13
5.2.1 Eclipse...............................13
5.2.2 Google Web Toolkit.......................13
5.2.3 Apache Maven..........................13
5.2.4 Spring Security..........................13
5.2.5 Hibernate.............................14
5.2.6 EasyMock.............................14
5.3 Version Stability and Backwards Compatibility............14
5.3.1 Eclipse...............................14
5.3.2 Google Web Toolkit.......................14
5.3.3 Apache Maven..........................15
5.3.4 Spring Security..........................15
5.3.5 Hibernate.............................15
5.3.6 EasyMock.............................15
6 Method 17
6.1 Current Approaches to Developing with GWT............17
6.1.1 Only GWT............................17
6.1.2 GWT MVC............................17
6.2 Requirements...............................18
6.2.1 Modified Requirements.....................19
6.3 Planning..................................20
6.4 Setting Up The Environment......................20
6.5 Execution.................................24
6.5.1 Introducing the Patterns.....................28
6.6 Performance................................35
6.6.1 Scalability.............................35
7 Results and Conclusion 37
7.1 Results...................................37
7.2 Conclusion................................37
Bibliography 39
Chapter 1
Introduction
This thesis focuses on web-based application development and will evaluate some of
the currently most widely used tools to make such projects efficient.The thesis will
be carried out for the company Synergica,located in Stockholm,which develops
a product called Team Engine.This is an online project collaboration platform
which uses elements such as forums,online file managers and calendars to enhance
the productivity of multi-member projects or simplify the running of board groups
or apartment owner associations.Synergica is currently developing a new version
of the collaboration tool called MyTE using newer technology than the current
product uses today.The development of a modular component in MyTE using
GWT MVP touches on a large amount of different technologies currently used in
software development.It ranges from modern database tools like Hibernate to
security implementations using Spring Security to dependency injection using Gin
and Guice.This thesis focuses on using the tools of our trade,frameworks and
patterns,to develop elegant and modern solutions in a large-scale fashion.
1
Chapter 2
Important Results
• Google Web Toolkit using the Model View Presenter pattern are suitable for
developing large scale modular web applications.
• The incorporation of Google Web Toolkit,gwt-presenter,gwt-dispatch,Gin
and Maven is not trivial.
• The leaning curve for using these patterns is steep.
• Understanding of the patterns is required to be able to utilize the patterns
effectively.
• Google Web Toolkit is a good platform for building web applications and has
been in use for quite some time by a large community.
• The model view presenter pattern solves the problem of"seperation of con-
cerns"making the presenter handle all the logic interactions with the model
while the view stays passive so the user does not have direct influence over
the datasets viewable.
• Dependency injection ensures modularity and improves maintainability over
a large set of classes.
• Dispatching asynchronous actions works well in a web environment where
request can take a variable amount of time to send and process.
• UiBinder removes code responsible for styling elements from the view and
provides readability and changeability.
3
Chapter 3
Background
This section contains some background to Google Web Toolkit (GWT) and the
other tools we will integrate with GWT for easing the process of development,
introducing scalability and maintainability of the final product.The prototype that
was produced as a result of this project uses a Maven project structure,with GWT
Model View Presenter on the client side using Gin for dependency injection and is
using Hibernate annotations as a means of storing and accessing data.
3.1 Eclipse
Eclipse is a popular Integrated Development Environment (IDE).The program’s
code is open source and has a lot of customization options available for developers
focusing on a specific programming language or use many different ones.At Syner-
gica this is the most widely used IDE and all development with GWT is done with
the help of Eclipse and its plugins.Plugins that will be installed and used with
Eclipse include the GWT plugin,the Maven plugin for eclipse and the Spring and
Hibernate plugins.
3.2 Google Web Toolkit
Google Web Toolkit is a development tool for creating advanced web applications
and it is used today,amongst other things,for development within Googles Wave
and AdWords applications.The GWT software development kit consists of a Java
Application Programming Interface (API),a Java-to-JavaScript compiler and a de-
velopment server.The Java-to-JavaScript compiler compiles code written in Java
to JavaScript producing several versions of the application,one for each major
browser,and then only provides the correct version per browser on request,so that
each browser only downloads the code optimised for that particular browser.This
reduces the amount of JavaScript code downloaded and makes the experience as
smooth as possible for the end user.GWT has standard widgets that covers all of
the standard HTML tag behaviours and can be used to quickly set up a site with
5
CHAPTER 3.BACKGROUND
basic functionality.These widgets also include handlers for user interaction within
the objects and these can all be handled in Java code.Developers can easily make
their own specialized widgets,with inheritance and extensions offered through Java,
customize existing widgets or make completely new ones.
3.2.1 Model View Presenter
Model View Presenter (MVP),shown in Figure 3.1,is a design pattern for effec-
tively splitting up your widgets so that different MVP components can be changed
at any time without affecting the others.This also makes it easier for multiple de-
velopers to work on the same widget simultaneously and still merge their view and
presenter components seamlessly,provided they do not change the structure of the
connecting interfaces.The Model is a Plain Old Java Object (POJO) for storing
some information that should be accessible to the widget;this object is handled
by the Presenter,which is responsible for all the logic within the widget,and also
handles events from the user interface component;the View.The View should be
as dumb as possible and only contain the structure of UI elements and ways for the
presenter to fetch them.
View
Presenter
Model
Fetch
Update
RetrievePush
Figure 3.1:The Presenter does all the work.
3.3 Gin and Guice
Gin and Guice are tools for providing Dependency Injection (DI) to GWT develop-
ment.Guice is the server side DI tool and Gin is built on top of Guice to provide the
GWT client side code with the same options for dependency injection.Dependency
injection is another mean for making the entire application more loosely coupled,by
removing the need for classes themselves to initiate everything necessary for their
own dependencies before they can be run individually.The DI frameworks in this
case are responsible for providing a fully instantiated instance of some class A to
the current class B so when changing the implementation of class A,class B just
gets injected with the new class A instead and is blissfully ignorant of the changes
to class A.The upsides to this are very clear when dealing with multiple classes
which all are dependent on class A but have all instantiated the class themselves,
which makes reworking all the classes a chore in large projects.
6
3.4.APACHE MAVEN
Injector
Class A
Class B
creates
injects
3.4 Apache Maven
Apache Maven is a project management tool that provides a standardized struc-
ture and customizable options for building and managing a multi project structure.
Maven does this by using a Project Object Model (POM) for every project.The
pom is an XML file that handles all the project wide dependencies and version con-
trols.The plugin for Eclipse called maven2eclipse also automatically ensure that the
environment has those dependencies available by downloading them from a central
repository of projects.The plugin also works well with GWT while using the GWT
development mode.
3.5 Spring Security
Spring Security was formerly known as Acegi Security but has since then been
incorporated into the Spring Portfolio of tools as the standard way of securing Spring
applications.Spring Security is the authentication and access control branch of the
Spring Framework and provides the application with very customizable options for
user management and security.This security can be configured in many different
layer from sub-url security within a domain,down to method security on a per user
and method call level.
3.6 Hibernate
Hibernate is a object/relational mapping (ORM) library that translates the logical
representation of objects into an atomized form that is capable of being stored in a
database[19].This solves the problem that arises when using plain old java objects
(POJOs) together with for example collections,which are not suitable for being
stored in the basic form of integers and strings that a relational database offers.
Hibernate offers this functionality to"persist"Java objects,making them accessible
between different sessions of the application.
7
CHAPTER 3.BACKGROUND
3.6.1 Hibernate Annotations
Hibernate Annotations provide developers with a convenient way to configure Hi-
bernate specific configurations within their Java classes,eliminating the need for
the traditional XML configuration file,and also places the configuration in a more
human readable form right next to the classes they are affecting.This ensures the
least possible amount of XML configuration specific to Hibernate and removes one
layer of complexity in the project.
3.7 EasyMock
EasyMock is a Java"mocking"tool for writing complex tests involving multiple
objects that only work in unison.Mocking in this case is the creation of dummy
objects with fixed behaviour which simplifies testing.EasyMock provides the means
of mocking away the instances of classes that are of no importance to the current
test and expect,record and play back methods finding errors in the results and
execution.These mock objects are only affected by the fundamental changes and
not by small re-factorings,making Easymock a good way of handling testing on an
ever-changing code-base[4].
8
Chapter 4
Problem Statement
Efficient development,maintainability and stability is what companies should be
interested in when developing a product that will hopefully be used for many years
to come,by a large number of users.Can these frameworks and tools be combined
and used efficiently to meet the standard that is required on today’s competitive
market?
9
Chapter 5
The Frameworks
So why should we use all these different tools to do things that most people han-
dle the old fashioned way,without using any external frameworks?First of all it
introduces a new level of complexity with each new layer to the application which
makes the knowledge requirements for developers higher.This can in turn be out-
weighed by structural improvements and maintainability of the code-base,which
will stabilize and ease development in years to come.But do the pros outweigh the
cons?
5.1 Licensing and Open-source
Since the final product in this case will be sold commercially and the code will not
be released to the public,the individual licences of the frameworks determines if
the tools can be used or not.The licensing of computer software range from open
and free for all to closed and usable only through end-user licence agreement by
the user of the product.When talking about open-source software the majority
of the software uses some version of the GNU public license (GPL) as written
by Richard Stallman of the GNU Project[18].Software that uses the GPL are
considered copylefted as opposed to copyrighted,this play on words enhances the
feeling of opposition between the two,since the copyrighted material can not be
redistributed freely and the copylefted material has to be available freely and also the
software that uses these products must be free and open-source.The GPL can thus
not be used in commercial software where the code is not public and we shall avoid
using software with this license attached.So we need open-source projects with
fewer restrictions for using it in proprietary software.This is where the BSD,MIT
and Apache licenses come in,they all provide developers with access to the source
code of the projects while not restricting their use in commercial software with a
non-open-source code base.These are called permissive free software licenses[20].
11
CHAPTER 5.THE FRAMEWORKS
5.1.1 Eclipse
Although the Eclipse IDE is released under the copyleft Eclipse Public License
(EPL),which is an alteration of the GPL,it is not the source code we alter and use
but the program itself.As stated on the OSS Watch’s explaination of the EPL[17]:
• The Eclipse Foundation makes clear that,in their opinion,merely interfacing
or interoperating with an Eclipse plugin does not make your code a derivative
work of the plugin.
• Therefore original software developed using the Eclipse platform can bear any
licence its author chooses when distributed.
Hence this does not affect our ability to use eclipse in commercial development.
5.1.2 Google Web Toolkit
GWT is released under the Apache 2.0 License and this requires us to release our
product with a copy of the license attached and we also need to state in any files
we change which changes we have introduced.This also means we can attach any
other license we want to our own product when finally distributing it.
5.1.3 Apache Maven
Maven is also distributed under the Apache 2.0 License but since this software will
not be distributed with the product and no changes will be made to the actual code
in this case the license does not need to be attached on account of this software.
5.1.4 Spring Security
Some of the Spring Security framework will be shipped as the access control func-
tionality within the product and since the framework is distributed under the same
license as GWT (Apache 2.0) Spring we already have this covered.
5.1.5 Hibernate
Hibernate states on their homepage[12]:
Hibernate is licensed under the Lesser GNU public License v2.1(LGPL).
The LGPL is sufficiently flexible to allow the use of Hibernate in both
open source and commercial projects.The LGPL guarantees that Hi-
bernate and any modifications made to Hibernate will stay open source,
protecting our and your work.
Lesser GPL is a alteration to the standard GPL which removes the copyleft portion
of the license.
12
5.2.DOCUMENTATION
5.1.6 EasyMock
EasyMock is also released under the Apache 2.0 License and will be covered by the
copy we will attach.
5.2 Documentation
Since some of these frameworks are old and some quite new the documentation
provided for each plays a big role when learning and using them in your product.A
good documentation can help bring new people up to speed and help solve problems
that developers are bound to run into when working with new tools.A bad or non
existent documentation can on the other hand make the framework all to taxing to
use to make it worth the effort of introducing it to your team.
5.2.1 Eclipse
The documentation for Eclipse is kept up to date with all new versions released and
can be found at Ecilpses homepage[7].It provides all its information in a categorized
and searchable interface,which makes it very easy and efficient to find what you
are looking for.
5.2.2 Google Web Toolkit
GWT’s documentation is wrapped in a pretty tutorial and feature showcase[10].Its
easy to browse and provides examples for using most of the standard widgets and
systems provided in the toolbox.When developing a bit more advanced applications
the Java doc overview can sometimes be more helpful when figuring out how to
solve the problem you are faced with,this is also provided by Google here[9].All
the GWT sub-projects like GWT-MVP,GIN,and UiBinder are also explained and
documented on Google code,which is Googles project database.
5.2.3 Apache Maven
Maven is all about structure and configurations and while their documentation[6]
have some"getting started in 5 minutes"-guides the process of understanding Maven
and what it is trying to accomplish takes quite a bit longer.Following the docu-
mentation can be tedious at times but gets the job done if you follow it to the
letter.
5.2.4 Spring Security
Spring Security’s documentation[16] consists of a reference manual and a javadoc.
The reference manual is html based,only text and contains some code examples for
configuration specifics and the javadoc is in the standard format.
13
CHAPTER 5.THE FRAMEWORKS
5.2.5 Hibernate
Hibernate’s documentation[2] features a html based web page which includes some
getting-started tutorial downloads.It is thorough and easy to follow.
5.2.6 EasyMock
The documentation for EasyMock is shorter than all the other frameworks we have
looked into so far,but its not the functionality of EasyMock that is hard to under-
stand,it is using it effectively and correctly since the ideas might be different from
the regular testing developers are used to.
5.3 Version Stability and Backwards Compatibility
The products developed at Synergica will hopefully be used a long time to come
and the management is therefore interested in whether the frameworks being used
will be maintained and updated with bug fixes and fixes for other issues,since the
service they provide demands a certain amount of reliability and security.The
product is only as secure as its weakest link and even a small hole in some part of
the system can amount to a severe leak of information.
5.3.1 Eclipse
According to Jeffrey S.Hammond’s publication about IDE Usage Trends[11] the
Eclipse IDE is used by 70 percent of all Java developers on the market and has been
around for close to 10 years now.In addition to fixing bugs,many new features and
enhancements have been introduced with each version of the IDE building upon the
already solid base.One might argue that when such a big majority of the field uses
this one development environment its quality will continue to improve as the user-
base demands more features and submits bug reports of their daily use.Eclipse
ensures that they support backwards compatibility on their own software[7] but
some issues may occur with plugins installed prior to upgrading to a new version of
Eclipse.From personal experience and from the extensive daily testing done by the
developers using eclipse every day,I would qualify the Eclipse IDE as a very stable
working environment with a very small chance of disappearing from the market.
5.3.2 Google Web Toolkit
As GWT has been around for 5 years now a lot of the infancy bugs and glitches
have been worked out since Google released the milestone release 2.0 in November
of 2009.The community is growing large as more and more companies discover
how much GWT can help them in quickly develop simple JavaScript widgets and
web pages.This community is also good at writing articles and help improving
the framework by means of writing bug reports and submitting fixes themselves.
Some methods stay in the API as deprecated each new version to provide backwards
14
5.3.VERSION STABILITY AND BACKWARDS COMPATIBILITY
compatibility while making room for new and improved functions.GWT has the
potential to stay around the web development scene for a long time to come.
5.3.3 Apache Maven
Maven also ensures backwards compatibility in their release notes[6]:
• Maven 3 aims to ensure backward compatibility with Maven 2,improve us-
ability,increase performance,allow safe embedding,and pave the way to
implement many highly demanded features.
Support for Maven can be accessed through the Maven homepage and the developers
encourages Maven users to subscribe to the"Maven Users Mailing list"where all the
questions and answers are archived for future viewing.The project can be actively
contributed to by user who feel like helping out,making it constantly evolve.The
core development crew can also be contacted via IRC.
5.3.4 Spring Security
According to Borys Burnayev’s guide for upgrading from version 2 to 3 of Spring
Security[1] is seems like upgrading is not something that the team themselves have
made any effort to make easier for their users.This suggests that future releases
might suffer from the same lack of compatibility which is not optimal.Fortunately
we will use Spring Security 3 from start and not have to worry about the transition
from version 2 to version 3.
5.3.5 Hibernate
Hibernate is today actively being developed by people at JBoss Inc as a part of the
Red Hat company.It is being reviewed by an increasingly larger number of devel-
opers as it is growing in use on the market.Today they are working on releasing the
major milestone version 4.0.0,which was alpha released on May 5,2011.Hibernate
also gives the users access to migration guides[3] as a helping hand when moving
projects across versions,they are short guides on a per version-to-version basis with
concise information of the steps needed to safely upgrade to a new version while
staying compatible with the old functionality.
5.3.6 EasyMock
The EasyMock 3.0 Documentation[5] states that:
• EasyMock 3 still has a Class Extension project (although deprecated) to allow
an easier migration from EasyMock 2 to EasyMock 3.It is a source not a
binary compatibility.So the code will need to be recompiled.
15
CHAPTER 5.THE FRAMEWORKS
• EasyMock 2.1 introduced a callback feature that has been removed in Easy-
Mock 2.2,as it was too complex.Since EasyMock 2.2,the IAnswer interface
provides the functionality for callbacks.
This basically states that backwards Compatibility exists and some changes which
will increase productivity have been added,so these should be changed where ap-
plicable.
16
Chapter 6
Method
This section contains the work preformed by me when constructing the proof-of-
concept (PoC) for the calender module.The execution of the development phase
will include setting up a new working environment,planning the project and devel-
opment of the proof of concept calender module widget.Some of the requirements
have already been defined by the board of administration but some alterations and
refinements are required to fit the scoop of the PoC.
6.1 Current Approaches to Developing with GWT
Google announced GWT at the JavaOne conference in 2006 and was released on
May 16 that same year.Since then it has spread at a rapid pace through the
web development scene and is today used by many thousands of developers for
developing AJAX web applications[8].So lets take a look at how these developers
have used it over the years.
6.1.1 Only GWT
At first GWT was only used as a standalone kit for web page development with
the built-in Java-to-JavaScript compiler making it easy for developers to get up
basic functionality quickly.The result of this is a JavaScript front-end with GWT
generated components and is suitable for displaying information in the standard web
page fashion and some simpler client-side computations such as mortgage calculators
and keeping track of shared expenses[14].As the Tool Kit became bigger with more
added functionality and user wanted more advanced web sites developers required
a better way to structure their bigger projects.This helped bring together GWT
and some older design patterns such as model view controller.
6.1.2 GWT MVC
The Model View Controller (MVC) design pattern was first introduced in the late
70’s by Tryngve Reenskaug and was conceived as a general solution to the problem
17
CHAPTER 6.METHOD
Model
View
Controller
modifies
user input
updates
modifies
of users controlling a large and complex data set[15].It is a predecessor to the MVP
pattern but is not as loosely coupled as the view monitors the model for changed and
interacts with the controller.Some MVC frameworks that has been used together
with GWT include Spring MVC and gwt-mvc.Gwt-mvc is a stand-alone project
that eases the structuring of GWT application to the MVC pattern.
6.2 Requirements
The requirements as specified for the complete calendar module:
• Users should be able to create a calendar or have one created for them.
• Users should be able to edit their calendar.
• Users should be able to save their calendar.
• Users should be able to import their own and others calendars from Google
Calendar and similar services.
• Users should be able to export their own calendars to Google Calendar and
similar services.
• Users should be able to have multiple calendars within the same view.
• Users should be able to customize some aesthetic aspects of their calendars,
like individual calendar colouring.
• Each user should have a personal calendar.
• Each place should have a calendar that all members of the place has access
too.
• Access control should be in implemented,allowing only authorized personnel
to make changes in the place calendars.
18
6.2.REQUIREMENTS
• The calendar should feature different views encompassing different number of
days being displayed.
• Each calendar entry should be editable via a separate view and via a drag-
and-drop resizing feature.
• Each entry should contain all the necessary information required to effectively
keep the appointment.
• Notifications of upcoming events.
• Smooth handling of displaying overlapping events.
6.2.1 Modified Requirements
Modification to the requirements to fit the scoop of the PoC include removal of
inter-application communication and removal of the access control lists on a per
calendar basis and only put into effect the database access control layer.The
reduced scoop will help focus the project to framework integration and operation
while still retaining its use as a proof of concept for future development.
The new requirements consists of these points from the original requirement:
• Users should be able to create a calendar or have one created for them.
• Users should be able to edit their calendar.
• Users should be able to save their calendar.
• Users should be able to import their own and others calendars from Google
Calendar and similar services.
• Users should be able to export their own calendars to Google Calendar and
similar services.
• Each user should have a personal calendar.
• Each place should have a calendar that all members of the place has access
too.
• The calendar should feature different views encompassing different number of
days being displayed.
• Each calendar entry should be editable via a separate view and via a drag-
and-drop resizing feature.
• Each entry should contain all the necessary information required to effectively
keep the appointment.
19
CHAPTER 6.METHOD
6.3 Planning
The planning phase requires a lot of time when working with best practices methods
involving many frameworks.Since there are a lot of different patterns that needs
to be able to function together,some problems will always arise during the pro-
gramming phase and these problems can be lessened some by research and planning
beforehand.
The Calendar needs standalone testing capabilities as well as integration capabili-
ties with the MyTE product and this functionality will be provided by the modular
structure we will apply to the project.The Calender will in the future both be avail-
able as a personal calendar and as a calendar for workspaces or places.These can
use the same layout with the only difference being access control on features related
to specific calendars.Each calendar should also be able to contain multiple custom
made sub-calendars.The solution to this is that the"calendar"you see is in fact a
collection of several calendars being displayed in the same view.This enables users
to subscribe to places of which they are members of,giving the users an overview
of all their activities in all places in their own calendar.User should also be able
to create private sub-calendars within their own calendar and this is also solved via
collections of calendars instead of a single calendar per calendar view.Storing the
calendar data can be done with the help of calendar servers using the CalDAV com-
munication scheme.By communicating with the server via the CalDAV standard
we maintain the modularity and can easily change server implementation at a later
date if one shows some more advantages over the others.Some things like creating
accounts for users logging on to the server might nor be the same for all the Cal-
DAV servers but this can be fixed by using an interface for this and swapping the
back end implementation.While planning is a necessity one can not foresee all the
difficulties one will face and there might even be some changes to the specification
that will alter major parts of the project and require us to rethink some aspects of
the set-up,nonetheless its nice to have a solid ground to stand on.
6.4 Setting Up The Environment
After we have planned the project we need to get all our tools together so that
we can begin executing the plan.Fist of all we need to download the Eclipse IDE
since its with its help we will puzzle together most of the other tools required for
this project.Eclipse can be downloaded from several places and the best being
Eclipse’s own download section on www.eclipse.org.The newest version at the time
of writing is version 3.6 (Helios) so we will use that.Eclipse comes packaged in a
archive which can be unpacked and placed at ones own discretion,the eclipse folder
is mostly self-sufficient and can be moved around if need arises,no installation nec-
essary.When first starting eclipse we will need to specify a workspace where we
want to put our project and then we are inside the Eclipse workspace.Now we
will need to install all the nifty plugins that will help us piece this puzzle together.
20
6.4.SETTING UP THE ENVIRONMENT
Eclipse uses a update-site style installation where repositories with plugins reside
somewhere on the web which we can connect to and then download and install plu-
gins from within eclipse itself.Some kind of version control system is a must when
developing large scale applications and I choose to go with subversive svn which
can be downloaded from the standard eclipse update-site and integrates nicely with
Eclipse.
Now we need the Google Plugin for Eclipse 3.6 v2.3.1.r36v201105092302 which will
provide us with eclipse integration for GWT features,the Google Web Toolkit SDK
2.3.0 v2.3.0.r36v201104261928 which contains all the software development tools
needed to get started with GWT and the Maven Integration for Eclipse-plugin which
will let us use many of the features of Maven directly in Eclipse.The first two can be
obtained fromGoogle’s update site for Helios http://dl.google.com/eclipse/plugin/3.6.
They have separate version of the plugin for all the recent builds of eclipse so we
need to go to the right update-site,in our case 3.6.The Maven integration plugin
is distributed by Sonatype and can be gotten from the m2eclipse Core Update Site:
http://m2eclipse.sonatype.org/sites/m2e
To install the m2eclipse plugin in the Eclipse IDE as specified by the Sonatype
team:
• Select Help > Install New Software.This should display the"Install"dialog.
• Paste the Update Site URL into the field named"Work with:"and press
Enter.Pressing Enter should cause Eclipse to update list of available plugins
and components.
• Choose the component listed under m2eclipse:"Maven Integration for Eclipse
(Required)".
• Click Next.Eclipse will then check to see if there are any issues which would
prevent a successful installation.
• Click Next and agree to the terms of the Eclipse Public License v1.0.
• Click Finish to begin the installation process.Eclipse will then download and
install the necessary components.
• Once the installation process is finished,Eclipse will ask you if you want to
restart the IDE.Sonatype strongly recommends that you restart your IDE
after installing m2eclipse.
That is it for the plugins required.Maven will handle the downloading of the
other libraries we need when we start building our project structure.To be able
to create the server connectivity required for storing the calendar data we must
first have a CalDAV server operational at the office.While researching the different
options for CalDAVservers i came across several different implementations in several
different languages and structures,all following the standard RFC4791 as set forth
by IETF Trust in 2007[13].
21
CHAPTER 6.METHOD
• DAVical
Open Source/PHP/PostgreSQL
Implementation of CalDAV Access and Scheduling with web-based adminis-
tration.
• DavMail
Open Source/Java
DavMail is a POP/IMAP/SMTP/Caldav/LDAP exchange gateway allowing
users to use any mail/calendar client with an Exchange server through Outlook
Web Access.
• Dingo Calendar Server
Open Source/Perl/CGI
Dingo is a CalDAV compatible server using MySQL,written in Perl as a CGI
script.
• ModCalDAV
Open source/cross-platform
Apache plugin implementing CalDAV Access.
• Oracle Beehive
Commercial
Implementation of CalDAV Access and Scheduling.
• Radicale
Open Source/cross-platform
Implementation of CalDAV Access.
• SabreDAV
Open Source (alpha)
SabreDAV is a free WebDAV server and includes support for CalDAV.
• Sun Java Calendar Server
Commercial
Implementation of CalDAV Access and Scheduling.
• Zimbra (VMWare)
Commercial/Open Source
Implementation of CalDAV Access and Scheduling.
• Chandler Server (Cosmo)
Open Source
Java-based server that includes support for CalDAV.
• Bedework
Open source/cross-platform
Implementation of CalDAV Access and Scheduling.Java-based.Includes a
Web UI.
22
6.4.SETTING UP THE ENVIRONMENT
I choose to look more into Bedeworks implementation since it uses technologies
which are most similar to the ones we’re working with.It is built in Java with
a hibernate solution as the back end.Bedeworks is used primarily by universities
all around the world including Yale,Brown,Julliard,Duke in the United States
and Stockholm University in Sweden.It has been deployed for a long time and it
can be considered stable enough to suit our needs at Synergica.I proceeded to set
up their quick-start server version on my local computer as a temporary solution
for internal testing.After trying to get it to run without succeeding for a while,i
started looking into the system requirements for the Bedeworks server.
• JDK 6
• JAVA HOME environment variable must be set in your command/shell win-
dows
• Hardware for testing:most current desktop or laptops will be adequate.
• Hardware for production:A server class machine generally with at least 2Gigs
allocated to the JVM (more is better).
• An adequate database system.In particular,the database should support
Unicode.Most Bedework installations use PostgreSQL,MySQL or Oracle.
The quickstart ships with Apache Derby,It isn’t recommended for production
systems.
Why I could not get it to work might have something to do with the 2 Gigabytes
of required ram to be allocated to the Java Virtual Machine (JVM).This amount
may be acceptable for a production servers but not for testing purposes on my de-
veloping laptop which has a total of 2 Gigabytes of ram.
The situation required me to look in a different direction for the temporary devel-
opment server and I finally settled on the Chandler Server Cosmo.Compared to
Bedeworks,Cosmo was lightweight and it was easy to set up a server with basic
functionality.The reason it wont be an option later in the process can be summed
up by this quote from Nathan Willis,a freelance Linux and open source writer.
Cosmo supports a wide array of iCalendar and CalDAV extensions,
including free/busy information,email notifications,and even CardDAV
address book synchronization.Still,site administrators should give care-
ful consideration to Cosmo because its future is uncertain.OSAF has
halted development on Chandler,and while Cosmo is still in working
order,if you run into trouble several years from now,you may have a
harder time finding support.
That they have stopped maintaining the Cosmo server makes it unsuitable for future
use while in production.This is the beauty of working with standards,when one
server fits our production needs and one server fits our testing needs we can use
both since they support the same standard and can be swapped without making any
23
CHAPTER 6.METHOD
changes in our own implementation.Bedeworks high requirements and stability can
be swapped in when its time for production and Cosmo can be used for lightweight
testing and development.
6.5 Execution
So now that we have a working development environment and a working test server
we can start building the project structure for our GWT module.First of all we
need to create a base project structure in accordance with both Mavens project stan-
dard and the GWT standard directory and package layout.The standard Maven
Figure 6.1:Standard GWT layout
project structure contains a pom.xml
file to handle all the project configu-
ration,a resources folder for storing
web resources and a target folder in-
stead of the GWT war folder for en-
capsulating the built project.Figure
6.1 displays the standard GWT lay-
out with the src folder containing all
the Java classes and the war folder
hosting the deployed project instead
of the target folder.
The Maven integration for Eclipse
plugin we installed earlier helps
us with the problem of combin-
ing these structures so that we can
use the standard way of building
Maven while maintaining the abil-
ity to use the standard GWT devel-
oping tools.While creating a new
project through the New Project
wizard in Eclipse we should choose
New Maven Project in the Maven
subcategory and in the second step pick the archetype we want to create a project
for.We want to use codehaus’s gwt-maven-plugin with group id org.codehaus.mojo
and use the latest version 2.2.This will prompt us to name our project and specify
the module name.Maven will then proceed to build and configure our project for
us creating all the folders and even a sample project which can be run out of the
box.The resulting structure is shown in figure 6.2.
That the project contains errors at creation time is the result of some of the build
goals that the project contains.When installing the module the first time the goals
i18n and generateAsync will be run and these will create the files that we are miss-
ing right now.We will use our own implementations of both of these later but the
project can be run as-is now.We will use Synergicas own language module since the
24
6.5.EXECUTION
product requires us to change the language of the entire site at runtime and this is
not supported by the standard nationalization package.As for the generateAsync
build goal we will replace the standard GWT Async classes with gwt-dispatch and
following the gwt-presenter structure so that we can utilize the MVP pattern it
provides us with.Now that we have a working base project we need to start cus-
tomizing it and download all the things we will depend upon,our"dependencies".
Figure 6.2:GWT Maven
Dependencies are organized by Maven with the
help of the pom.xml file in our Maven project.The
pom-file is a simple xml file specifying everything
Maven needs to know to be able to download,main-
tain,update and configure our project.If we spec-
ify another projects pom as a dependency to our
project Maven will proceed to download everything
that project has specified as dependencies as well as the
project itself.Maven does this process recursively un-
til everything needed by us and our dependencies has
been downloaded and included in our project.This is
very convenient when distributing the project amongst
co-workers and via Mavens repositories,as one only
need to say that we want the base project we intend
to use and will automatically have all its dependencies
downloaded as well.There are a very large number of
options available to be configured in the pom file and
the Maven plugin for eclipse supplies us with an graph-
ical user interface,see figure 6.3,to ease the stress of
configuring everything manually.The image also gives a hint about everything that
may be customized with the pom as the sub menus at the bottom correspond to
the major sections of the pom file.
As we talked about earlier we want to replace the inherent asynchronous structure
with gwt-dispatch to use the Action-Result-Handler pattern,see Figure 6.4.This
method is a asynchronous client-server communication where the client sends an
Action that is serializable through the dispatcher which is then handled by the cor-
responding Handler on the server side which then sends a serializable Result back
to the client.The Action and Result can be either dumb objects without any infor-
mation or can contain any serializable Java structure which are used to carry the
necessary information to the server-side and back again.Any combination of these
Action and Results can be used depending on the functionality required by the call,
for instance an insert into some database can contain the data in the Action object
but can return an empty Result on success.The method onSuccess or onFailure
is executed when the asynchronous call returns.They correspond to a successful
asynchronous call and a failed asynchronous call.
25
CHAPTER 6.METHOD
Figure 6.3:pom.xml GUI
Dispatcher
onSuccess
onFailure
Action
Result
Handler
Client Server
Figure 6.4:Action-Result-Handler pattern
To add gwt-dispatch as a dependency we open up the pom-file and switch to
the Dependency tab.When pressing add here we are asked to search the standard
Maven repositories for the dependency we are looking for.Most of the projects
we want are already on the standard repository and can be browsed to via the
search and find functionality.If the project we are looking for does not exist on
the repository we need to add its external repository to our pom file so that Maven
knows where to look for the project.One project we will want to use in the future
is Caldav4j,a Java project with caldav connectivity as an extension of HttpClient.
This project is not found on the global Maven repository but can instead be found
at a repository hosted by Google.We could add the repository via the Repositories
tab in the pom GUI or we could simply add these line directly into the pom-file
26
6.5.EXECUTION
after the dependencies section.
<repositories>
<repository>
<id>caldav4j.repo</id>
<name>CalDav4J Repository</name>\\
<url>https://caldav4j.googlecode.com/svn/maven/</url>
</repository>
</repositories>
So we search for gwt-dispatch in the add menu and find a match called net.cus
tomware.gwt.dispatch,double-click the latest version and the entire package will
be added to our pom.Now we do the same for the gwt-presenter project which
will help us structure our project in the GWT MVP pattern and find that it is
the same provider for both of them as they are meant to work together.When we
save the pom file the jars we just requested will be downloaded for us and placed
in the Maven Dependencies jar folder.We can now clean up the project from
errors,removing the language related code and the references to the asynchronous
implementation which would have been created for us at runtime,as we want to use
the gwt-dispatch method instead.To be able to use dependency injection within
our project we need to also depend on the Gin library provided by Google.This
dependency will be specified as com.google.gwt.inject in our pom and we will use
version 1.5.0.
Before we begin structuring everything,we want to be able to start the module
stand alone for testing and development and for this we need an entry-point class.
The entry-point class contains the method onModuleLoad() and its function is to
act as Java’s main method but for GWT.Here we request the presenter via Gin
and bind and display its display on the root panel of our html,creating the widget
on an empty page.When we want to integrate the widget with the final product we
need another module without an entry-point specified and for these two separate
configurations we use different module-gwt-xml files.These files functions a lot like
dependencies in Maven,specifying every other module this module depends upon
and this file is used when importing this module into other encompassing modules.
In the base module XML file we inherit our dependencies for the core libraries we
use and not specify an entry-point,while in the entry-point XML we will inherit
the base module and specify an entry-point keeping the separate configuration to a
minimum,seen in Figure 6.5.
Now we have all the necessary libraries for implementing the client server com-
munication according to the patterns we are investigating and can begin structuring
our project around all these patterns.This next part requires us to do extensive
re-factoring of our project and add many new files,which of none will compile until
everything is linked up and connected properly.This will take a long time when
doing it for the first time since the myriad of patterns in play are not entirely trivial
to set up.The more you read and understand about the individual patterns the
27
CHAPTER 6.METHOD
Calendar.gwt.xml
<?xml version="1.0"encoding="UTF-8"?>
<module>
<!-- Inherit the core Web Toolkit stuff.-->
<inherits name="com.google.gwt.user.User"/>
<!-- Inherit the UiBinder stuff.-->
<inherits name="com.google.gwt.uibinder.UiBinder"/>
<inherits name="com.google.gwt.user.theme.standard.Standard"/>
<!-- Dependency Injection -->
<inherits name="com.google.gwt.inject.Inject"/>
<!-- Inherit gwt-presenter -->
<inherits name="net.customware.gwt.presenter.Presenter"/>
<!-- Inherit gwt-dispatch.-->
<inherits name=’net.customware.gwt.dispatch.Dispatch’/>
<!-- Specify the paths for translatable code -->
<source path="client"/>
<source path="shared"/>
</module>
CalendarEntryPoint.gwt.xml
<?xml version="1.0"encoding="UTF-8"?>
<module rename-to="Calendar">
<!-- inherit all the required things for the calendar -->
<inherits name="se.synergica.myte.calendar.Calendar"/>
<!-- class containing onModuleLoad() for stand-alone entry-point usage -->
<entry-point class="se.synergica.myte.calendar.client.Calendar"/>
</module>
Figure 6.5:The base gwt.xml on top,entrypoint gwt.xml below
easier it will become to see the pros of using them together,nonetheless it requires
time and study to be able to incorporate them without help.
6.5.1 Introducing the Patterns
We’ll begin with introducing the Model View Presenter pattern on the client-side
because this is the most fundamental pattern we will use.When starting our entry-
point for the module we use the entry-point class to initiate and"bind"our modules,
more on bindings later,the entry point class acts as a basic application starter.Here
we will create our topmost presenter-view and attach that to the root-panel of the
html page that acts as a container for our module.But before we can add and
bind we need to create the presenter and view files.Since I needed a wrapper for
the different calendar views my topmost element became the CalendarWrapperP-
resenter which is displayed by the corresponding CalendarWrapperView.The class
extends WidgetPresenter which is an abstract GWT presenter class found in the
gwt-presenter package we added via Maven.The parameter is our own display
interface we specify within this class,the CalendarWrapperPresenter.Display.By
extending this class we get are forced to implement the onBind(),onUnbind() and
28
6.5.EXECUTION
public class CalendarWrapperPresenter extends
WidgetPresenter<CalendarWrapperPresenter.Display> {
public interface Display extends WidgetDisplay {
}
public CalendarWrapperPresenter(Display display,EventBus eventbus) {
super(display,eventbus);
}
protected void onBind() {
}
@Override
protected void onUnbind() {
}
@Override
protected void onRevealDisplay() {
}
}
Figure 6.6:CalendarWrapperPresenter.java
onRevealDisplay() abstract methods we get from the superclass of the WidgetPre-
senter class,the BasicPresenter."Binding"is the process of initializing all handlers
and configuration for that specific widget presenter and is called via the bind()
method in BasicPresenter.The unbind() method provides us with a safe way of
removing our handlers when we remove the widget again and also calls onUnbind()
method for specilized configuration at removal.The method onRevealDisplay() is
called when the widget is attached to the page.
The display interface will be implemented by our view class and here we will specify
all the possible interactions the presenter can have with the view.We will use inter-
faces as return types to be able to freely change the components in the view amongst
those that implement the same interfaces.Take for example a button which turns
a section of the page red.If we specify this as;
public interface Display extends WidgetDisplay {
public Button getRedButton();
}
we need to change this interface if we want to exchange it for a HyperLink instead
since there is a type conflict.But if we specify the method in the interface as;
public interface Display extends WidgetDisplay {
public HasClickHandlers getRedChanger();
}
we can change the object in the view to any object that implements HasClick-
Handlers,for example Anchor,Button,ButtonBase,CheckBox,CustomButton or
Hyperlink.The Display needed as an argument is our own display which will be
used within this class to retrieve objects fromthe view before interacting with them.
We should also get used to register our handlers so that the unbind() function au-
tomatically removes them on unbinding of the module.
29
CHAPTER 6.METHOD
protected void onBind() {
registerHandler(display.getRedChanger().addClickHandler(
new ClickHandler() {
public void onClick(ClickEvent event) {
//Change to red.
...
}
}));
}
The EventBus is a application-global bus that enables different presenters to listen
to and fire events across the entire application.
Now that we have specified a method we need to create our view.As said earlier
the view implements the display interface located in our presenter and require us
to implement its methods.This class also extends Composite which is encapsulates
a Widget.
import {...}.client.wrapper.CalendarWrapperPresenter.Display;
...
public class CalendarWrapperView extends Composite
implements Display {
Button button;
public CalendarWrapperView() {
button = new Button("Red");
button.setSize("80px","60px");
}
@Override
public HasClickHandlers getRedChanger() {
return button;
}
}
This way of building user interfaces is a bit outdated and there are many more com-
pelling alternatives than old-school Java swing code where you have to program-
matically set sizes and such.One of these is the UiBinder method which connects a
declarative layout in HTML,which can contain entire GWT widgets,with the view.
You can declare your own xmlns link on the top to import your own custom widgets
to the ui.xml file,this file contains the uibinder link represented by"ui"and the
standard gwt widget library link represented by"g".We can style the elements with
css directly in the uibinder-file by linking them with styleName="style.buttonstyle"
eliminating the need to style them in Java.Since we are working with web this
approach feels more appropriate and makes it easier both to change things and to
"see"the layout a bit more.This does requires some changes in the view and we
need to add UiBinder as a inheritance in the gwt.xml file if we have not done so
yet;
<inherits name="com.google.gwt.uibinder.UiBinder"/>
The view-changes needed can be seen in the modified View code below and while
it might look confusing it is just a local interface extending a UiBinder class of
which an instance is then produced with GWT.create().GWT.create is a special
30
6.5.EXECUTION
<!DOCTYPE ui:UiBinder SYSTEM"http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style>
.buttonstyle {
height:60px;
width:80px;
}
</ui:style>
<g:FlowPanel>
<g:Button styleName="{style.buttonstyle}"
text="Red"ui:field="button"/>
</g:FlowPanel>
</ui:UiBinder>
Figure 6.7:CalendarWrapperView.ui.xml
GWT function which is needed when working with GWT since the many different
compilations that are produced with the GWT compiler has some special quirks.
This feature is called deferred binding.The CalendarWrapperUiBinder object is
the initialized in the constructor and it searches for the current class name as a
ui.xml file in the current directory,which is why it is important that the view and
uibinder-file have the same names.The elements we wish to link into the Java class
has to be annotated with the tag @UiField so that the parser can correctly connect
the elements together.Now we can do all our styling in pure css and just handle
the functionality in Java.
import {...}.client.wrapper.CalendarWrapperPresenter.Display;
...
public class CalendarWrapperView extends Composite
implements Display {
interface CalendarWrapperUiBinder
extends UiBinder<Widget,CalendarWrapperView> {
//Empty
}
private static CalendarWrapperUiBinder uiBinder =
GWT.create(CalendarWrapperUiBinder.class);
@UiField
Button button;
public CalendarWrapperView() {
initWidget(uiBinder.createAndBindUi(this));
}
@Override
public HasClickHandlers getRedChanger() {
return button;
}
}
31
CHAPTER 6.METHOD
Let’s switch over to the presenter again and take a look at dependency injection.
Dependency injection with Gin is specially made for use with GWT applications
and the thought behind it is to move the creation of objects required for a class to
function outside of the class itself.This way the class knows what it needs and we
use the dependency injection pattern to supply a implementation of that require-
ment when the object is being created.This enables us to change implementation of
the provided object via outside wiring without having to notify the created object
of the change.
public class CalendarWrapperPresenter extends
WidgetPresenter<CalendarWrapperPresenter.Display> {
public interface Display extends WidgetDisplay {
}
private CalendarSevenDayPresenter calendarSevenDayPresenter;
@Inject
public CalendarWrapperPresenter(Display display,EventBus eventbus,
CalendarSevenDayPresenter calendarSevenDayPresenter) {
super(display,eventbus);
this.calendarSevenDayPresenter = calendarSevenDayPresenter;
}
protected void onBind() {
calendarSevenDayPresenter.bind();
registerHandler(display.getRedChanger().addClickHandler(
new ClickHandler() {
public void onClick(ClickEvent event) {
//Change to red.
...
}
}));
}
@Override
protected void onUnbind() {
}
@Override
protected void onRevealDisplay() {
}
}
We add whatever module we think we will need in the argument-list in the construc-
tor and annotate the constructor with @Inject which signals to Gin that it should
locate the appropriate implementations for all the arguments when constructing
this object in the future.To help Gin along the way in between all the presenters,
views and displays we need to map up which should be provided where.This is
done with the help of ginmodules and ginjectors.Ginmodules is in charge of the
mapping between interfaces and implementations and the Ginjector acts as the first
stepping stone when introducing your topmost module in the app-starter.A gin-
jector is not needed for the sub modules as we can include their ginmodules in the
main ginjector interface and have them be configured that way.
@GinModules( { CalendarGinModule.class })
32
6.5.EXECUTION
public interface CalendarGinjector extends Ginjector {
CalendarWrapperPresenter getCalendarWrapperPresenter();
}
public class CalendarGinModule extends AbstractPresenterModule {
protected void configure() {
bind(EventBus.class).to(DefaultEventBus.class)
.in(Singleton.class);
bindPresenter(CalendarWrapperPresenter.class,
CalendarWrapperPresenter.Display.class,CalendarWrapperView.class);
bindPresenter(CalendarSevenDayPresenter.class,
CalendarSevenDayPresenter.Display.class,CalendarSevenDayView.class);
}
}
We will now use the Ginjector inside our entry-point class to retrieve our first
presenter which will in turn inject and initilize all the sub-modules.
public class Calendar implements EntryPoint {
private final CalendarGinjector ginjector =
GWT.create(CalendarGinjector.class);
public void onModuleLoad() {
CalendarWrapperPresenter calendarWrapperPresenter =
ginjector.getCalendarWrapperPresenter();
calendarWrapperPresenter.bind();
RootPanel.get().add(calendarWrapperPresenter.getDisplay().asWidget());
}
}
Too explain a little behind the reasoning for using the injection pattern instead of
using new everywhere let us try an analogy.Lets say we have a class Mixer that
takes an object in its constructor and when the function powerOn() is called the
Mixer calls mix() on the object provided in the constructor.The Mixer knows that
it should mix the object it gets injected with but it does not know the resulting
juice,that will be regulated with the object we provide,be it an Apple or an Orange
object.Outside configuration affects the end result with the Mixer just doing its job.
Finally we will incorporate the gwt-dispatcher in our presenter for client-server
communication with serializable objects.Now that we are using dependency injec-
tion we will add a DispatchAsync in the constructor and include the StandardDis-
patchModule available in the gwt-dispatcher package in our ginjector,which will
bind DispatchAsync to an implementation of StandardDispatchAsync.All of this
can be customized extensively,with building our own DispatchAsync class and hav-
ing multiple servlets running simultaneously,but that is not in the scope of this
project.
private final DispatchAsync dispatcher;
@Inject
public CalendarWrapperPresenter(Display display,EventBus eventbus,
33
CHAPTER 6.METHOD
DispatchAsync dispatcher,CalendarSevenDayPresenter
calendarSevenDayPresenter) {
super(display,eventbus);
this.dispatcher = dispatcher;
this.calendarSevenDayPresenter = calendarSevenDayPresenter;
}
@GinModules({ CalendarGinModule.class,StandardDispatchModule.class })
We will need an implementation of a dispatch servlet on the serverside to handle
our asynchronous requests from the client.For simple cases we can use the Sim-
pleDispatchServlet available in the example in gwt-dispatch’s documentation.Here
we register our handler so that it catches actions intended for it and returns the
appropriate result.
public class SimpleDispatchServlet extends RemoteServiceServlet
implements StandardDispatchService {
private Dispatch dispatch;
public SimpleDispatchServlet() {
InstanceActionHandlerRegistry registry =
new DefaultActionHandlerRegistry();
registry.addHandler(new OurHandler());
dispatch = new SimpleDispatch(registry);
}
public Result execute(Action<?> action) throws DispatchException {
try {
return dispatch.execute(action);
} catch ( RuntimeException e) {
log("Exception while executing"+
action.getClass().getName() +":"+
e.getMessage(),e );
throw e;
}
}
}
We need to be able to communicate with the CalDAV server from our back
end and for that we need some way of connecting Java to CalDAV.After some
research I found a project supplying this service on Google code and it is called
caldav4j.Caldav4j is,at the time of writing,not available through the standard
Maven repository so we need to add a remote repository as a dependency to be able
to access the caldav4j project through Maven.This is done with the repositories tag
as shown earlier when discussing the pom file.Caldav4j has classes helping us with
building the queries for our CalDAV server and implements all the functionality
as descried in the CalDAV specification[13].This library enables us to connect to
and interact with calendars and events stored on our server.When working on the
server side and while not having to worry about ui-elements we can make full use
of the EasyMock framework for testing our methods that will send and retrieve the
data from the server.With Easymock we can mock the requested results from the
34
6.6.PERFORMANCE
server and thus test just the functionality of one methods,one at a time,without
having to have a fully operational server already in place.This enable us to use
small,fast unit tests without network connectivity within continuous integration
tools that continuously test our code on commits or specified times of the day.
With this final addition we can start building our application.With all these
patterns in mind we use standard Java to add functionality while doing all the
styling in HTML-like environments with CSS.This feels familiar to everyone that
has worked with web before which makes it easy to work with.The patterns is
what really brings complexity to the ordeal and that can set back the project quite
some while at first.Some of GWTs standard widgets,like the Horizontal- and
VerticalPanels,generates tables when compiled which creates clutter in the result-
ing HTML.Nestling such elements make for complex and confusing HTML after
compilation.The rest of the implementation pertains to mostly standard program-
ming problems and does not contribute valuable information to understanding and
evaluating the frameworks.
6.6 Performance
Due to the project taking longer than expected making a thorough testing of the
performance of the frameworks have not been carried out.The fact that the server
will be stateless speaks for the fact that simultaneous usage will not be a problem.
Stateless server does not depend on previous results to answer requests from users
but will handle all requests individually.That GWT uses deferred bindings within
the code results in optimized JavaScript code for the user’s preferred browser and
this helps reduce the bandwidth.The browser also caches the version it has re-
quested which speeds up further request since the uses does not have to download
the entire application again.Since we want the module to function standalone we
should host the CalDAV server separately.This will require us to minimize the
time requests between the GWT server and CalDAV server take to execute.The
different browser most popularly used today range in their effectiveness of executing
JavaScript and old browsers can struggle with heavy JavaScript applications.The
frameworks in themselves,when combined,provide quite a large overhead in the
Java-code but this is then highly optimized by the GWT compiler producing a very
compact JavaScript end-product.
6.6.1 Scalability
If the server load rises above reasonable levels the statelessness of our server provides
us with the option of simple load-balance between several machines running the
same service.
35
Chapter 7
Results and Conclusion
7.1 Results
I have built a prototype calendar module for the MyTE web application using
Google Web Toolkit.I have incorporated current design pattern which are supposed
to help companies develop stable,scalable and modular applications.The scope
was reduced during development to not include the use of Spring or Hibernate since
similar solutions where already present in open-source libraries which may be used
in future development on the module.To realise the MVP pattern I used gwt-
presenter and gwt-dispatch providing modularity and serializable communication
with the server respectively.The dependency injection for the GWT application
was done with Google Injection,Gin.I used UiBinder for structuring the visual
components of the module in HTML instead of using Java to programmatically
build the user interface.
7.2 Conclusion
The frameworks in themselves all provide a new take on old problems and try to
solve these problems in a better way.They all use their own special syntax for
accomplishing their tasks and this can get overwhelming when trying to start from
scratch.The learning curve is pretty steep and one almost needs to see the problems
the patterns are trying to solve before realizing the potential and gain from using
them.There are useful tutorials provided for most of the patterns so newcomers can
copy and paste their way to a functioning application without really knowing the ins
and outs of the solutions provided to them.I believe that understanding the tools
is as much a part of crafting as using them and understanding should therefore be
encouraged when introducing new personnel to the patterns.Developing without
understanding makes developing difficult.
37
Bibliography
[1] Borys Burnayev.How to upgrade spring security 2 to spring security 3.
http://blog.burnayev.com/2010/04/how-to-upgrade-spring-security-2-to.html.
[2] JBoss Community.Documentation - hibernate.
http://www.hibernate.org/docs.
[3] JBoss Community.Hibernate3 - migration guides.
http://community.jboss.org/wiki/Hibernate3MigrationGuides.
[4] EasyMock.Easymock.http://easymock.org/.
[5] EasyMock.Easymock 3.0 readme.http://easymock.org/EasyMock3_0_Documentation.html.
[6] Apache Foundation.Maven - welcome to apache maven.
http://maven.apache.org/index.html.
[7] Eclipse Foundation.Eclipse documentation.
http://www.eclipse.org/documentation/.
[8] Google.Google web toolkit.http://code.google.com/intl/sv-SE/webtoolkit/.
[9] Google.Gwt javadoc 1.5.http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/index.
[10] Google.What’s new?http://code.google.com/intl/sv-SE/webtoolkit/overview.html.
[11] Jeffrey S.Hammond,Carey Schwaber,and David D’Silva.Ide usage trends,
02 2008.
[12] JBoos Community Hibernate.License - hibernate.
http://www.hibernate.org/license.
[13] IETF.Calendaring extensions to webdav (caldav).
http://www.ietf.org/rfc/rfc4791.txt.
[14] mark at ociweb dot com.Gwt - who’s using it?
http://www.ociweb.com/mark/programming/GWT.html#WhoIsUsingIt.
[15] T.Reenskaug.Models-views-controllers.Technical note,Xerox PARC,Decem-
ber,1979.
39
BIBLIOGRAPHY
[16] SpringSource.org.Spring security - documentation.
http://static.springsource.org/spring-security/site/reference.html.
[17] OSS Watch.Oss watch - the eclipse public license.
http://www.oss-watch.ac.uk/resources/epl.xml.
[18] Wikipedia.Gnu general public license.
http://en.wikipedia.org/wiki/GNU_General_Public_License.
[19] Wikipedia.Object relational mapping - wikipedia.
http://en.wikipedia.org/wiki/Object-relational_mapping.
[20] Wikipedia.Premissive free software licensing.
http://en.wikipedia.org/wiki/Permissive_free_software_license.
40
TRITA
-
CSC
-
E
201
1
:
10
4

ISRN
-
KTH/CSC/E
--
1
1
/
10
4
-
SE

ISSN
-
1653
-
5715







































www.kth.se