lieberherr@ccs.neu.edu
csg260-grader@ccs.neu.edu
The teaching assistant is to be determined.
THEME: Reverse Engineering of Java programs using AspectJ
(http://www.eclipse.org/aspectj/ and
$ASD/CCS_AspectJ_Usage.html)
Learn basics of XML by studying Demeter example:
Data type definitions (DTDs), documents and
Java code generation from XML DTDs.
On the WWW,
ASD = http://www.ccs.neu.edu/home/lieber/courses/csg260/f03
DemJ = http://www.ccs.neu.edu/research/demeter/DemeterJava
DJ = http://www.ccs.neu.edu/research/demeter/DJ
D = http://www.ccs.neu.edu/research/demeter/
The directory containing administrative information and homeworks is: $ASD (using the UNIX shell syntax).
Course number: CSG 260
Name:
Account name:
Assignment number:
Date:
Do NOT include your student id number in any work you submit because some of your work may be put on the web.
READING:
Read chapters 1, 3 and 4 of the AP book.
Read: chapter 1: A Quick Tour of Java in the Java book by Arnold/Gosling
or
the approximately equivalent information in your favorite Java book.
You may want to buy and read one of the AspectJ books that are available. See amazon.com.
Skim read the following:
$DemJ/forReadersAPBook/APbookWithDJ.html
$DemJ/forReadersAPBook/APbookWithDemJava.html
$DemJ/forReadersAPBook/simple-example.txt
About UML class diagrams at www.rational.com/uml
About XML: http://www.xml.com/axml/axml.html
(XML = eXtensible Markup Language is a W3C Recommendation,i.e., it
is a standard.)
Read about the Law of Demeter:
You can play with yourself.
You can play with your own toys (but you can't take them apart),
You can play with toys that were given to you.
And you can play with toys you've made yourself.
For more information:
http://c2.com/cgi/wiki?LawOfDemeter
If you detect some incorrect statements in those pages, please drop me a note.
Read about basic pointcuts and intertype declarations in your AspectJ document (either a book or the AspectJ website).
PART A:
==================================
This homework is about reverse
engineering of Java programs using UML.
Reverse engineering means to figure out the design from the program
text.
Reverse Engineering: "the process of analyzing a subject system to identify
the system's components and their interrelationships and create
representations of the system in another form or at a higher level of
abstraction." (Source: Chikofsky and Cross)
Consider the Java program in directory
$ASD/hw/1/binary-tree
The files in directory gen with suffix *.java make up the program.
(Note: The files in gen have been generated by DemeterJ from the
files tree.cd and tree.beh. While you study the Java programs, you also
learn how DemeterJ generates code. The file tree.cd is very similar
to an XML schema or an XML
document type definition (DTD). The code generation process is similar
to the code generation process described in JSR 31
by SUN. This Demeter-like code generation capability is a part of
the Java 2 Platform (Web Services Pack)
http://www.ccs.neu.edu/research/demeter/technology-transfer/XML/index2.html.
The file tree.input that will be used later to create a Java object
is similar to an XML document. So we have the following correspondences:
XML Document type definition or schema :: tree.cd (class dictionary)
XML document :: tree.input (sentence)
Java program processing XML document :: tree.beh (behavior file)
The following file gives you information on the code generation process:
http://www.ccs.neu.edu/research/demeter/DemeterJava/quick-help/TABLE-OF-CONTENTS.txt
Start your reverse engineering effort with file Tree.java.
Most of the organization of this file is described in file tree.cd.
Answer the following questions:
1. Consider the UML class diagram underlying the Java program.
(For information on UML, see http://www.rational.com/uml/)
Turn in a picture of the UML class diagram. Use your favorite drawing tool to create it and turn in the file that your drawing tool (maybe a pen) produces.
Your UML class diagram will contain directed associations.A directed association looks like:
-------- -------- | A | 1 | B | | | ----------------->| | -------- x --------
A is the source class, B the target class and x is the name of the role.
In the Java implementation, A and B are classes and A has an instance
variable x of class B.
Association is a synonym for relation. The directed association above
presents a binary relation. You think of it as a set of pairs, namely (A-object,B-object)
pairs. A natural way to implement such a relation is to store the B-object
which is
associated with a given A-object in the instance variable x of the
A-object.
The name "association" comes from the OMT method. It has found its way into the UML vocabulary.
Do not put methods and their signatures into your UML class diagram.
==============
2. Describe the behavior of the program in English.
Try to summarize the program as much as possible. Do not just translate
the program into English especially when you explain the methods in the
Java program. Focus on explaining the methods
sum_labels()
print_leftTrees()
print_allTrees()
and the methods they call.
Here is a start: When
cd gen
cd classes
java Main < ../../tree.input
cd ../..
runs, the Java virtual machine executes the byte code in file Main.class.
This code will execute function Main.main which creates a tree object from
file tree.input in variable tree using a table-driven parser whose functioning
will not be explained here; the parser is automatically generated by a
parser generator (it is free):
----------
In the following we only explain the behavior of sum_labels().
The behavior is implemented through a traversal which visits all Label-objects
and a SummingVisitor ...
The output produced by the program is in file out.
Now reverse-engineer the program in
$ASD/hw/1/graph
using AspectJ instead of UML.
The goal is to have a running AspectJ program that untangles
code that is given to you. Turn in your AspectJ program.
There are several ways to write the AspectJ program. Turn in
a paragraph about the design of your AspectJ program.
The AspectJ program combined with the base program must have
exactly the same behavior as the enhanced program.
Consider directory $ASD/hw/1/graph/base/gen and directory $ASD/hw/1/graph/enhanced/gen. Directory base/gen contains a basic program created by DemeterJ and directory enhanced/gen contains an enhanced program, also generated by DemeterJ, obtained by modifying the basic program. In this exercise we want to express the modification of the basic program in AspectJ without ever touching the basic program. We want to change the basic program by ADDITION of *.java files and not by MOFIFYING existing *.java files. I have started this process of enhancement in base/gen. To compile and run the program I use file compile which contains
ajc *.java java Main < ../class-graph.inputNote that I use the AspectJ compiler to compile the Java programs and the reason is that there is one file that is not a plain Java program: beh2.java contains the text:
aspect behavior2 { int Cd_graph.countInhRels2() { CountingVisitor v0 = new CountingVisitor(); v0.start(); // allInh(v0); v0.finish(); // return v0.get_return_val(); return 0; } pointcut MainCall() : call (static public void Main.main(..)); after() : MainCall() { System.out.println("result = " + Main.graph.countInhRels2()); } }You can view this aspect as editing instructions which add a little bit of the code in enhanced/gen (but not in /base/gen) to base/gen. Your task is to use AspectJ to add all the code in enhanced/gen.
NOTE ABOUT PART A:
You can answer the questions by studying the files of the form
*.cd and *.beh.
In addition, you should study the generated Java code (in the gen directory)
although it might be confusing. Also keep in mind
that there are several ways to generate the code and you
see here only one way.
For example in the JAXB approach by SUN mentioned earlier there
is a separate file that allows you to control the details
of code generation. DemeterJ uses a fixed method.
You are asked to wade through a tremendous amount of Java code:
for binary-tree:
a few thousand lines of Java code
generated from 67 lines in tree.beh and tree.cd.
When you study the Java code keep in mind that it must be very regular
since it is produced from a small amount of information.
Also keep in mind that not all generated code is actually used
by the simple application programs. You have to focus only
on the code which is used.
Take a look at:
http://www.ccs.neu.edu/research/demeter/DJ/
and get a basic understanding of the package.
Find the unknowns in the following Java program: The program prints the city where an employee lives. You should find the UNKNOWNs by using knowledge from your Java book and by what is in the DJ package documentation. Only after you have found all the UNKNOWNs you may want to run the Java program.
// Main.java import edu.neu.ccs.demeter.dj.*; class Main { static public void main(String args[]) throws Exception { // Build object Employee e = new Employee( new UNKNOWN1( new UNKNOWN2( new UNKNOWN3( new String("Boston")))), new UNKNOWN4(), new Date()); ClassGraph cg = buildClassGraph(); System.out.println("City where Employee lives"); System.out.println(e.get_city(cg)); System.out.println("City where Employee lives: UNKNOWN5 "); System.out.println(e.UNKNOWN6.UNKNOWN7.city.UNKNOWN8); System.out.println("DONE"); } public static ClassGraph UNKNOWN9() { ClassGraph cg=new ClassGraph(true,false); // true: include all fields // false: do NOT include all non-void no-argument methods System.out.println("The UNKNOWN10 version is: " + cg.getVersion()); System.out.println("UNKNOWN11" + "============================="); System.out.println(cg); System.out.println("end class graph " + "============================="); return cg; } } // import edu.neu.ccs.demeter.dj.*; class UNKNOWN12 { UNKNOWN13(PersonalInfo personalInfo_, Date d, Date a) { personalInfo = UNKNOWN14; departure = UNKNOWN15; arrival = UNKNOWN16; } PersonalInfo personalInfo; Date arrival; Date departure; String get_city(ClassGraph cg) { return (String) cg.UNKNOWN17(this, "from Employee through City to java.lang.String"); } } // PersonalInfo.java import edu.neu.ccs.demeter.dj.*; class PersonalInfo { Address address; PersonalInfo(Address address_) { address = address_; } } // Address.java import edu.neu.ccs.demeter.dj.*; class Address { Address(City city_) { city = city_; } City city; } // City.java import edu.neu.ccs.demeter.dj.*; class City { City(String name_) { name = name_; } String name; } // Date.java class Date { }The DJ version is: DJ version 0.8.2
To provide the answers,
use the file $ASD/hw/1/UNKNOWNs
An UNKNOWN may be multiple words.
Compile and run the Java programs in binary-tree and graph on your PC or workstation at work. Just compile the files in the gen directory. Don't regenerate them using DemeterJ.
Please put the rt.jar file into your class path. See:
http://www.ccs.neu.edu/research/demeter/software/docs/install.html
If you use the CCS .software file, use: CLASSPATH=.:/proj/demsys/demjava/rt.jar
Turn in the output produced produced
by running the binary tree program and the output of the enhanced graph program
you compiled.
Write a grammar for atoms:
using the grammar notation you learned in your Principles of Programming Languages or similar course. This is the offical Chemical Markup Language (CML): www.xml-cml.org. Turn in your grammar.
PART E:
Read the Jan/Feb 2001 MIT Technology Review article
http://www.techreview.com/magazine/jan01/tr10_toc.asp
about the 10 most promissing technologies that will change the world.
Read the entry: Untangling Code (see below for a free copy):
http://www.techreview.com/magazine/jan01/tr10_kiczales.asp
Free copy: For educational personal use only by Northeastern students.
Answer the following question: How is Aspect-Oriented Programming called at Northeastern University according to the article?
WHERE
Bring your hw solutions to class or put them into the mail box of the
teaching assistant.
ONE SUBMISSION ONLY PER HOMEWORK
Please submit only once when you are done or on the due date,submit
a partial solution.
You may turn in your hw for full credit up to two working days late. This means, if it is due on Thursday, you can turn it in the following Monday. If it is due on day x, it means 4.30 pm on that day.
For late homework we will deduct 20% per day late, unless you present a very good reason to the teaching assistant.
1. What kind of preparation do I need
for this course?
Experience with object-oriented design and programming
is an absolute prerequisite.
Get an account on Northeastern machines
if you don't have one already and you want one.
You can get access to the necessary information on the WWW.
For all work you can use
any machine of your choice which runs the latest version of Java.
But you are responsible for installing the necessary software
on your own machine.
2. What am I going to do if I join the
class late?
All messages which I send to the class are archived in
$ASD/archive/.
If you join the class late, you can read that archive to get up-to-date.
3. How to download DJ and DemeterJ
The instructions for downloading DJ and DemeterJ are at: http://www.ccs.neu.edu/research/demeter/software/docs/install.html
4. Where can I find the instructions
for DemeterJ?
DemeterJ is not needed for this homework, but if you are curious,
the instructions are at URL:
http://www.ccs.neu.edu/research/demeter/DemeterJava/
5. How can I do my homework on my own computer? If you want to do your homework on your own computer, you need a Java development environment on your PC or workstation and Internet access. In each class usually several students use Windows or Linux to do their homework on their own machine.