Swing2Script: Migration of Java-Swing applications to Ajax Web applications
Hani Samir(*), Eleni Stroulia(**) and Amr Kamel(*)
(*) Computer Science Department Faculty of Computers and Information Cairo University, Giza, Egypt h.samir@fci-cu.edu.eg a.kamel@fci-cu.edu.eg
Abstract Platform migration is a core problem in software reengineering, since applications are frequently deemed useful in environments other than the ones in which they were originally implemented. The web in particular is becoming a target platform of choice because of its pervasiveness, and a substantial class of applications that could benefit from migration to the web is that of Java Graphical User Interface (GUI) desktop applications. We have recently developed an interaction-reengineering approach, called S2S for Swing2Script, to automatically migrate Java-Swing applications to Ajax-enabled webbased applications. The approach reverse engineers the structure and behavior of the GUI using aspects woven unobtrusively in the original application. Based on the extracted model, it automatically builds an Ajax-enabled front end, which drives the relevant workflows of the original application. In this paper, we describe our migration approach and the middleware on which it relies, and we illustrate it with a case study.
(**) Computing Science Department University of Alberta Edmonton AB, T6G 2H1, Canada stroulia@cs.ualberta.ca
interaction to which desktop applications users have been accustomed in web-based interfaces. Thus, the problem of automatically migrating java Swing applications to the web is recently becoming the subject of much industrial activity. In our work, we have adopted an interaction-based reengineering methodology, which has been successfully applied to the migration of character-based (CUI) and form-based interfaces (FUI). However, the nature of system-user interaction in Java-Swing applications is different from the interaction in these other types of systems, in the following important dimensions. 1. GUIs support multiple top-level windows, at the same time; depending on their modality, one or more of them may be active to receive user input. 2. GUIs offer a large variety of widget types, i.e., basic elements for user input and data display. Furthermore, several GUI widgets are used both to receive user input and to display information. 3. GUIs allow for (and react to) a variety of usergenerated events at any point in time. CUI and FUI systems follow a more restricted client-server architecture style: the client terminal presents the interface to the user, who inputs data and submits it as a whole to the back-end server. The server returns the new user interface with the appropriate response. In GUIs, the user may interact with many different widgets in a single window, creating local changes to a subset of the user-interface elements, to which the application responds. These differences imply that any Java-Swing to web migration method should (a) adopt a rich target userinterface toolkit to implement a client user interface similar in complexity to the Swing interfaces, involving a variety of complex widgets, unlike what is available in HTML forms; and (b) employ a fine-grained mechanism for monitoring the user interaction at the client and emulating it at the server, in order to support the complex and variant event-driven interaction of Java-Swing GUIs. In our work, we have developed S2S a method for migrating Java-Swing applications to the web. To fulfill the first requirement above, we have adopted XUL as the target user-interface representation language. XUL (the XML User Interface Language) is a markup language for creating user interfaces. It is part of Mozilla-based browsers and has language constructs for all of the typical dialog controls, as
1
Introduction
Platform migration is a core problem in software reengineering, since existing applications are frequently deemed useful in environments other than the ones in which they were originally implemented. The World-WideWeb (WWW), in particular, is an important target environment, because of its pervasive infrastructure. Recent research has focused on supporting the migration of text-based legacy applications to the web, when (some of) their functionalities have to be accessed by people outside the organization IT boundaries [4,5,19,21]. More recently, the proliferation of Java-Swing applications has given rise to the problem of migrating this new class of applications to the WWW. Nokia, just to name an example, uses WebCream [23], a commercial tool that constructs HTML front ends for Java applications, to web-enable their networking software. Through its Swing library, Java enables the development of interactive applications with rich user interfaces. Until recently, it was technically difficult to support the same type of rich interaction in web-based applications. However, with advances such as Ajax [17] and rich web user-interface toolkits [22], it has now become technically possible to support a similar type of
well as for widgets like toolbars, trees, progress bars, and menus. JavaScript can be used to program the XUL widget behavior and tie them together. To address the second requirement, our S2S method relies on Ajax and aspects. Ajax is a new paradigm for writing highly interactive web applications. Using Ajax, it is possible to enable finegrained client updates without having to go through a complete HTTP request-response cycle, which makes the web application more responsive. At the server side, to enable the invocation of individual event handlers in the absence of actual Swing user events, we use aspects, seamlessly weaved with the original application code, to emulate the impact of user events to the model elements of the Swing components, thus triggering the appropriate event-handlers responses. The rest of this paper is organized as follows. Section 2 reviews the research in this area. Section 3 describes the essential elements of an interactive Java-Swing application. Section 4 describes the proposed migration approach. The architecture of the migrated application is shown in Section 5, while section 6 presents the migration process. Section 7 illustrates the method with a case study. Section 8 reviews the implementation status of the supporting S2S middleware and Section 9 concludes with an overview of the interesting contributions of this work and our plans for future research.
2
Related Work
In principle, there are black-box and white-box approaches for migrating legacy systems to modern platforms [7] Black-box techniques are agnostic of the system implementation details and rely primarily on wrapping (some of) its implementation within a different environment. Wrapping techniques may be applied to the legacy user interface of the subject system, or to its business-application components or to its back-end data resources. Legacy-System Reverse Engineering and Migration: There is a variety of methods for black-box migration. CelLEST [19] is a semi-automated method for wrapping text-based interfaces within web-accessible front ends. Within the same paradigm, [13] wraps the browseraccessible interfaces of web-based applications with programmatically accessible service specifications. [9] presents a rule-based approach to convert the visual layout structure of HTML forms into an abstract user interface model and acknowledges the difficulty of extracting such a structure from the GUI of Java applications. An interactive wrapping methodology is presented in [5,2], where developers reverse engineer a finite-state automaton for each use case of the legacy application, and construct a model of all possible interactions between the user and the legacy system during that use case. A wrapper is then built, which makes use of this model, to drive the legacy application. The authors acknowledge the substantial user input required by the process and the limitations of the produced wrappers. The problem of reengineering a monolithic application to a client-server environment has also received the
attention of researchers. Panteleymonov [16] discusses a methodology (but no implementation support) for enabling legacy applications to run in a client-server environment, using communication middleware like CORBA. The idea is to separate only the code of the GUI from the legacy application, so that the separated GUI code runs on the client and the code implementing the business logic is placed on the server. Canfora et al [4] discuss an approach for automating the first step of the migration process by decomposing the legacy source code into user interface, application logic, and database components. The method is based on program slicing and is suitable for procedural languages. Zou and Kontogiannis [21] developed a whitebox method for detecting distinct functional components and manipulating the code in order to encapsulate these components and then wrap them. The legacy system is decomposed and components that provide specific functionality of interest are identified. A wrapper is then automatically built to wrap the functional components with CORBA distributed objects and SOAP hence making them accessible as web services. The GUI Ripper tool [14] reverse engineers the GUI model of Java applications, for the purpose of automated test-case generation. The GUI is automatically traversed by opening all windows and extracting each window’s widgets properties and values. Chan et al. [6] dynamically analyze interactive applications with graphical user interfaces to map user actions to the source code. Grechanik et al. [10] describe a method for integrating GUI driven applications in their binary form for purposes of software reuse. The idea is based on wrapping the GUI with programmatically accessible objects, by injecting an ‘agent’ program into the GUI application using code-patching techniques. During this process, techniques specific for Win32 applications are provided for identifying all windows and widgets in the GUI application, intercepting GUI events and replaying GUI events and inputs. It is interesting to note here that the authors acknowledge that “interception of GUI events for browsers or applications written in Java is harder”. AOP and software understanding: To our knowledge, AOP has not been used for rearchitecting monolithic desktop applications to web-based client-server architectures, although Stroulia and Systa [20] discussed the role of dynamic analysis for user interface reverse engineering and mentioned the potential of aspect-oriented programming (AOP) techniques for runtime analysis of object-oriented systems. More generally, there has been substantial research on developing aspect-oriented methods for constructing different types of software analysis methods and tools. Briand et al. [3] used AspectJ to dynamically reverse engineer UML sequence diagrams. AOP has been used in [12] for purposes of dynamic program slicing. ARE [11] is a reverse engineering tool that analyzes runtime features of Java applications using AOP technique. Finally Ng et al. [15] discuss how AOP can be used effectively for static and dynamic program comprehension. User Interface Representation Languages: A prerequisite for enabling multi-platform user interfaces is a
platform-independent language for modeling the elements of a user interface and their behavior. To that end, several user-interface description languages have been developed based on XML. A good overview of several of them can be found in [18]. XUL [24] is a cross platform UI description that it can be rendered by any Mozilla browser. Designed to overcome the shortcomings of XHTML interfaces, it offers a rich notation for describing and laying out graphical userinterface widgets [1], instead of focusing on simple forms. For example, instead of a “Submit” button, assumed to communicate the complete data of the form to the server, XUL allows each widget to be associated with JavaScript implementing the behaviors associated with actions on this widget (much like event handlers deal with their corresponding components in Swing). XUL also has some very sophisticated form-like tags, such as
(a more flexible version of