lieberherr@ccs.neu.edu
com1205-grader@ccs.neu.edu
The teaching assistant is Wang, Jing (jing@ccs.neu.edu).
THEME: Reverse Engineering of Java programs
Learn basics of XML by studying Demeter example:
Data type definitions (DTDs), documents and
Java code generation from XML DTDs.
On the WWW,
SD = http://www.ccs.neu.edu/home/lieber/com1205/w01
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/
To comply with college structures, we also maintain:
/course/com1205/w01 = SD and
/course/com1205/.www = http://www.ccs.neu.edu/course/com1205
= http://www.ccs.neu.edu/home/lieber/com1205.html
The directory containing administrative information and homeworks is: $SD
Course number: COM 1205
Name:
Account name:
Assignment number:
Date:
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.
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
PART A:
==================================
This homework is about reengineering of Java programs into an object-oriented
design.
Reverse engineering means to figure out the design from the program
text.
Consider the Java program in directory
$SD/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 planned to
be put into the Java 2 Platform
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 Demeter 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 reengineering 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.
==============
Why work hard when the computer can do it for you?
There is a commercial tool available, called StructureBuilder, which
can analyze your Java classes and create the UML class diagram automatically
for you. The company is called
WebGain
http://www.webgain.com/Products/Structure_Builder/index.htm
They allow you to use their tool for free during the duration of the course. If you want to give it a try (most students do), download the Enterprise edition and use it with:
Key = 2095362198
Name = NEU Class
This may only be used by Northeastern students for educational purposes.
The code works for the duration of the course. The
Enterprise edition is the most powerful of the three available editions
and has good support for Enterprise Java Beans.
Structure Builder has been installed on the Solaris machines.
The path is:
/arch/com/packages/sb4/runSBu
The installation required a hack which places
the user in the sb4 directory. If you wish to save/select files, you
will have to explicitly choose them from the dialogue box.
==============
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 from SUN:
----------
The JavaCC home page is at http://www.suntest.com/JavaCC
----------
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.
Has two subparts: B.1: do points 1-2 as in part A, but
now reverse-engineer the program in
$SD/hw/1/graph
NOTE ABOUT PARTS A AND B:
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.
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
for graph:
a few thousand lines of Java code
generated out of 54 lines in class-graph.beh and class-graph.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 $SD/hw/1/UNKNOWNs
An UNKNOWN may be multiple words.
Try to compile and run the Java programs in binary-tree and graph on your PC or workstation at work.
Please put the rt.jar file into your class path. See:
http://www.ccs.neu.edu/research/demeter/DJ/docs/install.html
If you use the CCS .software file, use: CLASSPATH=.:/proj/demsys/demjava/rt.jar
You need to run "resoft" after the change.
Turn in the output produced produced
by running the program you compiled.
PART E:
Read the Jan/Feb 2001 MIT Technology Review article
http://www.techreview.com/articles/jan01/TR10_toc.html
about the 10 most promissing technologies that will change the world.
Read the entry: Untangling Code:
http://www.techreview.com/articles/jan01/TR10_kiczales.html
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?
COM 1204 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
http://www.ccs.neu.edu/home/lieber/com1205/w01/archive/
If you join the class late, you can read that archive to get up-to-date.
The instructions for downloading DemeterJ are at: http://www.ccs.neu.edu/research/demeter/DJ/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 to do their homework on their own machine.