Eds.IOS Press, 2002 An Automatic Method for Refactoring Java Programs Seiya YAMAZAKI Graduate School of Science and Technology, Keio University 3–14–1 Hiyoshi, Kouhoku-ku, Yokohama 223-8
Trang 1K Salmenjoki and R Jdntti / Using Mobile Devices for Personalized Information 159
Information centric data integration
Figure 5 Information centric (XML Protocol enhanced web services), original source
http://www.w3.org/2001/04/roadmap/ws.svg
In this approach one is looking for combining the previously discussed networking andXML technologies using common dictionaries and shared ontologies, which enable atighter exchange of strictly defined data sources The connection between services andVHE is that the service can use authentication, routing etc functions provided by thenetwork through the common framework interface of OS A One problem here presently is ascattering of the XML technologies, especially in the Schema section, and vendor and usercommitment to these standards (instead of inventing new ones like Microsoft's C# orNokia's Mobile Internet Technical Architecture MITA efforts) Gradually, when theapplications will contain in-build XML usage, a tighter integration of various networkedinformation sources will be enabled In Figure 5 above web services will finally enable thechange from traditional paper trail into electrical transactions The critical components torequire from the network systems are service privacy, QoS, reliable messaging, routing,security and binary attachments
5 Service portability and openness - the Virtual Home Environment and Open System Architecture
Personalization of services requires that the service provider keeps track of user profiles In
a personalized setting the user must be able to define certain look and feel and functionalproperties for his mobile terminal Some of this personification information can be storedlocally in terminal and hence be available regardless of the access network There are,however, several drawbacks with this concept User could have several terminals in hisdisposal, the memory of the terminal could be very limited for storing such information,and a lot of bandwidth would be wasted by transmitting this information from mobile to theservice provider
Trang 2160 K Salmenjoki and R Jantti / Using Mobile Devices for Personalized Information
In the virtual home environment concept (VHE), the user has the same personalizedindividual interface and service mix available in his mobile terminal regardless of whichnetwork he is currently using In that case, the network has to take care of transmitting userprofiles, charging information, service information, etc from the user's home network, i.e.the network storing this information and in charge of charging the user, to the accessnetwork he currently is using Although this concept sounds simple, the involved signallingtasks from the network side are demanding
In a 3G network, Customized Applications for Mobile Enhanced Logic (CAMEL,[13]) service capability is extension of the Intelligent Network (IN) concept utilized e.g inGSM and PSTN systems While IN is network specific and does not carry information fromnetwork to network, CAMEL is designed to handle also mobility and roaming betweennetworks With networks that implement both CAMEL and MExE it is possible to achievetruly ubiquitous personalized mobile services
VHE is currently under standardization [14] It promotes the view that 3G servicearchitecture called Open System Architecture (OSA) should be a layered architecture, withstandardized interfaces between the layers The OSA APIs are implemented over adistributed processing environment, making the actual runtime location of servicesinsignificant These properties of OSA enable the network operators to be less dependent onparticular vendor's products, but more importantly third party service providers to accessthe network resources in a standardized manner making them less dependent on singlecarrier provider's network
VHE/OSA is joint effort of the Third Generation Partnership Project (3GPP),International Telecommunication Union (ITU), and Universal Telecommunication SystemsForum That is, it is driven by the telecommunications industry and teleoperators Anotherstakeholder in the service development process is the Parlay Group [11], which has beenformed to support creation of communications applications by specifying and promotingopen APIs that intimately link IT applications with the capabilities of the communicationsworld The convergence trend between telecommunications world and the rest of the ITworld can be seen in the co-operation between VHE/OSA development group and theParlay group
The VHE/OSA model is shown in figure 6 Applications access the servicecapabilities through a common framework interface The key component of both OSA andParlay is the framework server and its API These allow the applications to discover theavailable network functionalities The service capability servers such as MExE providefunctionalities to construct services These functionalities are grouped into logicallycoherent interface classes called Service Capability Features (SCFs) The SCFs offer ageneralized view of the network functionality to third party application developers viastandardized interfaces
Trang 3K Salmenjoki and R Jantti / Using Mobile Devices for Personalized Information 161
Figure 6 VHE OSA model
In figure 6 we note that the critical network properties, like service privacy and QoS, ofFigure 5 can be obtained via the OSA API interface
6 Concluding remarks- user centric services
In the previous chapter we saw the trends in present web based application and servicedevelopment with upcoming standards for mobile platforms When the services will includemore automated features utilizing the user settings and preferences using the previouslydiscussed XML technologies like RDF, we will see fully integrated personalized services,where the user is embedded in a network of transparent devices discreetly serving his needsand interrupting his other activities as little as possible The critical factors in thisdevelopment are the UI issues, application and data integration and user preferences andacceptance Figure 7 gives an idea of a transparent user view, which can dependent also ontime and user location Also the activation of the application can be provided by the onlineweb services components
Tirru
view
e and place related user
Ac ivities via services
Work Hobby
Figure 7 User centric or fully personalized services (like unified messaging applications, GIS based
applications or RDF based calendar and communication applications)
With more personalized devices and integrated applications users can start to use ubiquitouscomputing and various existing networks in the vicinity of the user according to his
Trang 4162 K Salmenjoki and R Jantti / Using Mobile Devices for Personalized Information
preferences, timing and personal activities Pervasive computing will become ubiquitous sothat computers are a natural extension of our everyday life
Finally IT is moving from information management into knowledge managementand "knowledge based applications" in efforts like the Semantic Web by W3C, see [16].Some parts of the application have to become more agent type, so that they communicatewith the user and his preferences when necessary, but are also able to help the user byworking independently of the user using only his preferences and networked informationsources (possibly communicating with user's other agent and other networked agentapplications and web based services)
7 References
[1.] 3GPP TS 22.057 V4.0.0 (2000-10) 3rd Generation Partnership Project TechnicalSpecification Group Terminals Mobile Execution Environment (MExE) ServiceDescription, Stage 1 (Release 4), 2000
[2.] 3GPP TS 22.057 V4.0.0 (2000-10) 3rd Generation Partnership Project TechnicalSpecification Group Terminals Mobile Execution Environment (MExE) ServiceDescription, Stage 2 (Release 4), 2000
[3.] 3GPP TS 22.121 v4.0.0 "Virtual Home Environment" (Release 2), 2000
[4.] 3GPP TS 22.12 v4.0.0 "Virtual Home Environment/Open Service Architecture", 2000[5.] P J Brown, J.D Bovey, and X Chen, "Context-aware applications; From thelaboratory to the marketplace," IEEE Personal Communications, October 1997 pp 58 -63
[6.] J Burkhardt, H Henn, S Hepper, K Rintdorff, T Schack, "Pervasive computing,"Addison-Wesley 2002
[7.] Y.-F Chen, H Huang, R Jana, S John, S Jora, A Reibman, and B Wei,
"Personalized Multimedia Services Using A Mobile Service Platforme," In Proc IEEEWireless Communications and Networking Conference WCNC 2002, Vol 2., Mar 2002, pp.918-925
[8.] F Daoud and S Mohan, "Strategies for Provisioning and Operating VHE Services inMulti-Access Networks," IEEE Communications Magazine, January 2002, pp 78-88[9.] H Kaaranen, A Ahtiainen, L Laitinen, S Naghian V Niemi: UMTS Networks, JohnWiley, 2001
Trang 5K Salmenjoki and R Jiintti / Using Mobile Devices for Personalized Information ] 63
[13.] TSG SA WGl Specifications, (http://www.3gpp.org/TB/SA/SAl/specs.htm), 2002[14.] VHE: Virtual Home Environment organization, 2002
[15.] W3C: XML standard, (http://www.w3c.org/XML/), 2002
[16.] W3C: Semantic Web effort, (http://www.w3.org/2001/sw/), 2002
[17.] WDVL (Web Developers Virtual Library): XML section,
(http://wdvl.internet.com/Authoring/Languages/XML/), 2002
Trang 6This page intentionally left blank
Trang 7Program Understanding, Reuse,
Knowledge Discovery
Trang 8This page intentionally left blank
Trang 9T Welzer etal (Eds.)
IOS Press, 2002
An Automatic Method for Refactoring
Java Programs
Seiya YAMAZAKI
Graduate School of Science and Technology, Keio University
3–14–1 Hiyoshi, Kouhoku-ku, Yokohama 223-8522, Japan
Morio NAGATA
Dept of Administration Engineering, Faculty of Science and Technology
Keio University 3–14–1 Hiyoshi, Kouhoku-ku, Yokohama 223-8522, Japan
Topic: Program understanding, programming knowledge, learning of
programming, modeling programs and programmers
Abstract In order to increase productivity of the software development, it is
desired to write understandable and reusable programs Thus, a refactoring method,
which transforms programs into understandable ones, has been an attracted research
issue Existing refactoring tools only replace a specified part of the program with
another text by the programmer However, it is difficult to find the part of the
program to be replaced Thus, we think that the tool should refactor programs
automatically Moreover, it should tell the programmers the refactoring strategy to
be applied This paper proposes a tool refactoring Java programs automatically Our
tool provides the following two common facilities for refactoring small parts of
given programs The first one is to hide methods of a class For example, if a public
method is used only within own class, the method is replaced with the private one.
The other facility is to reduce the scope of a variable For example, a variable is used
only within "for", "while", or "if statement in a method, the variable is declared
where the statement is needed Our tool has succeeded in refactoring many Java
programs automatically.
1 Introduction
Software products have become too large to be understood and modified by programmers.Refactoring [1] is one of the ways that transform programs into understandable and modifiableones without changing those behaviours In refactoring, the first step is to understand a currentstructure of the program The second step is to improve the structure The third one is torewrite the source by hand The final step is to execute and test the rewritten source program
In the future, it is easier for the same programmer or the other programmers to understand therefactored programs than original programs
Though refactoring is so attractive to the programmers, it has not been used yet When theprogrammers would like to apply refactoring to their programs, there are four difficulties; inspecifying the part of the program to be replaced; in specifying the method of refactoring to becarried out; in understanding the processes of refactoring; and in carrying out refactoring Inmost cases of applying refactoring, programmers have to improve programs by hand.Therefore, it often causes much trouble
Trang 10168 S Yamazaki and M Nagata /An Automatic Method for Refactoring Java Programs
There exist several tools for supporting refactoring, for example "Xrefactor"[2], "jFactor"[3],and "jBuilder 6 Enterprise"[4], These tools only substitute a part of the program into anothertext Thus, these tools cannot resolve above issues
2 An Outline of Our Automatic Method for Refactoring
We propose an automatic method for supporting programmers to refactor their Java programs.Methods of refactoring to be applied usually depend on a certain situation If there existseveral possibilities of refactoring, the tool cannot always determine a particular methodautomatically The following two methods can be always applied to improve programswithout depending on the situation
- To hide methods of a class
- To reduce scopes of variables
It is assumed that any Java program is transformed into an XML form by Javaml [5] beforeapplying our method
3 To Hide Methods of a Class
We can hide some methods of a class by reducing their scopes After our proposed toolconfirms that a method is not used in the other classes, it transforms the method into alocalized one For example, if a public method is used only in own class, the method istransformed into the private one If a public method is used within its subclasses, it istransformed into a protected one If a protected method is used only within own class, it will
be transformed into a private one
3 1 Example
class ClassA{
public method(){
class ClassB extends ClassA{
ClassA instance = new ClassA();
class ClassB extends ClassA {ClassA instance = new ClassA();private foo(){
If our tool transforms above program, the following processes are executed The first process
is to detect "method()" in the ClassA, and "foc()" in the ClassB The second process is to findthat "method()" is used in the ClassB
Trang 11S Yamazaki and M Nagata /An Automatic Method for Refactoring Java Programs 169
The third process is to understand that ClassB's parent class is ClassA The final process is totransform the "public method" into protected one because the public method in the ClassA isused only within its subclasses
3.2 Steps of hiding methods of a class
- [Stepl] Get all names of methods and classes.
- [Step2] Inspect where the method is used
- [Step3] Get an instance of the method
- [Step4] Get a name of the class appeared on the instance
- [Step5] Examine a parent-child relationship between the original class and the referred
class
- [Step6] Modify the method to be localized if the method is not used in another class
- [Step?] Transform the Javaml format into the Java program
In step3, we search the following pattern to get an instance of the method
instance, method
In step4, we search the following pattern to get the name of a class
ClassA instance = new ClassA();
3.3 Exceptional cases
Above method almost succeeds in refactoring programs However, there are someexceptional cases
3.3.1 the same constructor
At first, in case that there are the same constructor in a class For example, if
ClassA instance = new ClassA(): ClassB instance = new ClassB():
are in the same class, the tool might get a different class name
3.3.2 Factory method
Next, suppose that the program produces an instance by using a factory method, for example,
class FMFactoryl extends FMFactory{
public FMFactoryl (String s){
super(s);
public FMBase getInstance(){
return new FMl(msg);
Above program does not include ClassA instance = new ClassA (); , therefore the tool
cannot find out this pattern
Trang 12170 S Yamazaki and M Nagata /An Automatic Method for Refactoring Java Programs
4 To Reduce Scopes of Variables
In case that a variable is used only within "for", "while", and "if statements in a method, thevariable is declared where the statement is used
If our tool transforms above program, the following processes are executed The first process
is to detect "int i = 0;" The second process is to search for "i" from behind the variable in themethod description except the conditional branch In case of that there are no other "i", thetool declares "int" in front of "i = 1" in the conditional branches
4.2 Steps of Reducing Scopes of Variables
- [Step 1 ] Search int variable = number;
- [Step2] If the variable is used only in the conditional expressions, then the declaration
"int" is moved into the conditional expressions
- [Step3] Transform the Javaml format into the Java program
4.3 Exceptional cases
In some cases, our method fails to transform the programs into correct ones
4.3.1 long, double and float
The tool does not support long, double, and float constructors
»-void foo(){
if(someCondition) {j= int i;
\} '
Above transformation shows a wrong case This kind of a program is transformed by ourmethod However, there are no initialization of "i" in the transformed program Thus, theprogram cannot be compiled
Trang 13S Yamazaki and M Nagata/An Automatic Method for Refactoring Java Programs 171
4.4 Improved Reducing Scopes of Variables
j=i;
To eliminate 4.3.2 incorrect transformation, we changed the way of reducing scopes of
variables The first process is to detect "int i = 0;" The second process is to search for "i"from behind the variable in the method description except the conditional branch In case ofthat there are no other "i", the tool declares "int i = 0;" in front of "i" in the conditionalbranches
4.4.1 Steps of Improved Reducing Scopes of Variables
- [Step 1 ] Search int variable = number;
- [Step2] If the variable is used only in the conditional expressions, then the declaration
"int i - 0;" is moved into the conditional expressions
- [Step3] Transform the Javaml format into the Java program
There is no change in steps of hiding methods of a class The change is in the way of "thedeclaration is moved into the conditional expressions." Not only "int" is moved into theconditional expressions, but also "int i = 0;" is moved as it were Though this method has tomove more text than former way of reducing scopes of variables, it can be always applicable
We adopt this improved one
5 Concluding Remarks
Our tool successfully modified many Java programs in above situations We set two criteria
of automatic transformations The first one is that a programmer decides the execution ofrefactoring The second one is that a transformation is carried out when the programmerunderstand the difference between the original program and the transformed program Afterthe transformation, programs will be converted to be understandable, reusable, andmodifiable ones for programmers by applying refactoring In other words, refactoring is amethod for programmers Therefore, our tool always notices to programmers when refactoring
is applied Moreover, the notification will be useful information when the programmer writesthe same kind of the program in the future
We would like to explain our tool's advantage in terms of maintenance of programs Both
proposed ideas are concerned with scope Our tool can reduce scopes of methods or variables.
When a programmer maintains programs, which have the reduced scopes, he/she can watchthem without paying attention to the vanished scopes
Trang 14If a programmer who does not use our tool, he/she must watch the program with payingattention to scope of "method()" as left side of above figure If a programmer who uses ourtool, he/she watches only the reduced scope of "method()" as right side of above figure.
If a programmer who does not use our tool, he/she must watch the program with payingattention to scope of "i" as left side of above figure If a programmer who uses our tool,he/she watches only the reduced scope of "i" as right side of above figure
Our tool can reduce valid scopes of methods or variables, which should be checked, forprogrammers to understand their programs easily
References
[ 1 ] Martin Fowler Refactoring: Improving the design of existing code, Addison Wesley Longman 1999 Refactoring Home Page http://www.refactoring.com/
[2] Xrefactory: A Refactoring Browser for Emacs http://xref-tech.com/speller/
[3] jFactor: Refactoring tools to professional Java IDE http://www.instantiations.com/jfactor/
[4] jBuilder 6 Enterprise: The leading Java TM development solution http://www.borland.com/jbuilder [5] Javaml: An XML-based Source Code Representation for Java Programs
Trang 15T Welzer et al (Eds.)
Abstract A major activity in software development is to obtain knowledge and
in-sights about the application domain Even though this is supported by a wide range
of tools and techniques, a lot of knowledge remains implicit in the resulting artefacts
(e.g class diagrams) Examples of such implicit knowledge are amongst others the
links between the different artefacts, the knowledge that is lost as a result of iterative
refinements, and the knowledge that is regarded common sense by the involved parties.
Most of this knowledge resides in the heads of the stakeholder, the domain experts,
and the developers As it is likely that they can no longer remember it or that they
are no longer available when software reuse and maintenance activities are initiated,
this poses a problem In this paper we present ongoing research in which we focus
on our use of an ontology as a medium to tackle this problem Making the different
kinds of knowledge explicit will be accomplished by representing them as concepts in
the ontology Subsequently we will link these concepts to the artefacts created during
analysis, design and implementation This enables a bi-directional navigation between
the concepts and the artefacts which consequently will serve as a vehicle to start reuse
and maintenance activities.
1 Introduction
During the software development life-cycle the system to be built is conceived through anddocumented by different kinds of artefacts Besides modelling the final solution, these arte-facts (such as class diagrams) reflect our knowledge about the application domain to a consid-erable extent Unfortunately a lot of this knowledge remains implicit and most often resides
in the heads of the different people concerned The most important of this implicit edge are amongst others the links between the different artefacts, the knowledge that is lost
knowl-as a result of iterative artefact refinements, and the knowledge that is regarded knowl-as commonsense by the involved parties This includes the link between the conceptual artefacts andtheir concrete realizations in the implementation
Especially in the context of software maintenance and reuse activities it is imperative tohave access to the afore-mentioned knowledge elements This is not surprising, for these ac-tivities require a major effort in understanding the existing system For achieving this under-standing, it is helpful if you can rely on the people who were involved with the development
of the original system In practice however it is likely that they are no longer available or, ifthey are available, that they no longer have the specific knowledge you seek As a result youwill spend a major part of your time trying to figure out which concepts are represented bywhich parts of the code, and vice versa
Trang 16174 D Deridder / A Concept-oriented Approach to Support Software Maintenance
On top of this it is likely that the artefacts are not always internally consistent as well
as externally consistent Both types of consistency refer to the correct and consistent usage
of terminology and concepts For internal consistency this usage is confined to one artefact
In the case of external consistency it boils down to the consistent and correct usage betweendifferent artefacts Most of the time these inconsistencies are a direct result of the implicitness
of knowledge such as the links between the artefacts Let's say that a person wants to consider
a certain artefact for reuse, both violations of consistency will be quite confusing and willseriously hamper performing this task
To overcome these problems we propose the use of an ontology as a store for this edge and as a driving medium to support the persons who are charged with executing reuseand maintenance activities For this purpose the different concepts, that are represented inthe artefacts, will be defined and stored in the ontology To obtain an initial set of concepts
knowl-we will complement the already existing application engineering cycle with a domain
engi-neering cycle This combination is quite similar to the dual life-cycle as presented by Reifer
in [6] Subsequently these concepts will be "glued" to the different (elements of) artefactsthrough extensional and intensional concept definitions This will enable a bi-directionalnavigation between the concepts represented in the conceptual artefacts (e.g Car FleetManagement) and their concrete realizations in the code (e.g a group of classes)
This research was partially performed in the context of the SoFa project ("ComponentDevelopment in a Software FActory : Organization, Process and Tools") During this project
we delimited our scope of investigation to Business Support Systems Such systems are
char-acterized by the fact that they support knowledge intensive, enterprise critical processes thatare cooperatively performed by groups of knowledgeable business workers In what follows
we will assume that the applications of which we speak comply to this characterization
In this paper we will mainly focus on the concept-part of the approach we envision Sincethis depends heavily upon the use of an ontology we will provide a detailed description inSection 2 In it we will briefly discuss our motivation for selecting ontologies as a mediumfor our approach Next we will elaborate on our view on ontologies where we will present
a notion of concept networks and concept roles To conclude the section we will presentthe SoFaCB (SoFa ConceptBrowser) ontology tool In Section 3 we will sketch how we putthis ontology tool into effect to support reuse and maintenance activities In this section wewill present intensional and extensional concept definitions as a way to couple concepts toartefacts/code To end the section we will propose task ontologies as a way to overcome thegap between broad concepts and their narrow concrete realizations
2 An Ontology in a Concept-oriented Approach
In computer science there are many different interpretations of what an ontology is or should
be Most of the time this interpretation is depending heavily upon the application in whichthe ontology is used We prefer to use the popular but rather abstract definition of Gruber [4],being that an ontology is an explicit specification of a conceptualization If we instantiate thisdefinition for our work we get that an ontology represents a certain view on an applicationdomain, in which we define the concepts that live in this domain in an unambiguous andexplicit way An important aspect of an ontology, which we believe is not covered by thedefinition of Gruber, is the referential role that this explicit specification (the concepts) plays.This means that it is used as a work of reference and that there exists a strict commitment from
Trang 17D Deridder/A Concept-oriented Approach to Support Software Maintenance 175
the users towards the meaning of these concepts i.e an ontological commitment is enforced.
To avoid confusion we would like to stress that it is not our goal to create rigorous formalontologies for the application domains under consideration Instead we prefer a lightweightapproach where it is desirable but not necessary to end up with a set of concepts that is usable
as a standard for a larger community
In the following subsection we will motivate the choice of an ontology as a mediumfor our approach Next we will zoom in on our view on an ontology in terms of a conceptnetwork and the way the concepts in such a network can play different roles depending on theapplication context We will conclude this section with a brief discussion of our lightweightontology tool SoFaCB
2 / Ontology as a Medium : Motivation
If we keep our definition in mind and we retake the issues of implicit knowledge and nal/external consistency, it should become clear why we chose an ontology as a medium forour approach
inter-First of all, since an ontology is supposed to be an explicit specification of a
conceptu-alization, it is natural to use it to capture and store this knowledge That way we obtain ameans to share this knowledge, which would otherwise remain inside the heads of the peoplewho built the original system Secondly, since an ontology is intended to define the kinds
of things that exist in a domain, it provides a number of standard concepts to capture andorganize these things Examples of such concepts are identity, essence, and the subsumptionrelationship Thirdly, since the knowledge is now made available in an explicit form it be-comes possible to refer to it from within the different artefacts This will greatly reduce theabove-mentioned consistency problems which is mainly a result of the enforced ontologicalcommitment from the artefact-creators towards the used terminology and concepts Moreoverthis explicit specification will also prove beneficial for the comprehensiveness of the artefactsthey produce This could be attributed to the fact that a novice to the software system willhave a cross-referenced dictionary-alike documentation of the artefacts to his or her disposal
2 2 Concept Networks and Concept Roles
In Figure 1 we show an example of a partial concept network which we will use out this text To enhance readability we will refer to these concepts by their preferred-labelinstead of their unique concept numbers The Toy Example domain contains three con-cepts (clouds): Car Fleet Management, Car, and Company Car In the core do-main we have only shown two principal concepts: Concept, and Domain All of theseconcepts are defined by their surrounding definitions These definitions are connected to theconcepts by relations (arrows) For instance for the Car concept, the definition slots usedare: has-preferred-label, has-definition, and has-image To introduce anew concept it suffices to "instantiate" the concept Concept and fill in the correspond-ing definition slots Doing so you obtain a network structure that is very similar to conceptualgraphs [8]
through-In a concept network we adhere the view that every element in it is a concept This meansthat the relations we use are also represented by concepts Thus the system is said to be self-contained To group a set of related concepts we have introduced a Domain concept The