CMPT 318 99-1: Assignment #4Updated: Mar 4Updates to this assignment will be sent to the mailing list if they are required. |
Mar 22 during the first announced 10 minute break in class, not before, not after. 5% will be deducted for assignments handed in outside this time. You can also drop it into the box until the beginning of class (17:30).There will be no late assignments accepted.
Note: I recommend starting early on this assignment: it can be tricky.
10% of your final mark
This assignment will give you experience with Sun's Java component architecture called JavaBeans. You will gain some experience in composing components in a composition editor. In addition you will learn the basics for building and packaging beans and gain practical experience in doing it. Some emphasis will be placed on understanding how and why JavaBeans satisfy the basic requirements for being a component architecture.
Part I: Preparatory Work and Introduction to Assignment |
You will are not required to know the details of bean introspection and reflection (I mentioned it briefly in class). You can thus safely ignore the parts of the tutorial that deal with the "core reflection API", the "Reflection API trail", the "java.beans.Introspector" class, and similar references. You can also omit the section on "Constrained Properties". You do not need to read the "JavaBeans API Specification" document: it is tedious and fairly unilluminating. You don't have to read the sections on "Bean Customization" or "New JavaBeans Features" either.
These sections are geared towards using Sun's BDK. You do not absolutely need to run or use the BDK to do the tutorial if you have a different composition editor or and IDE with one (such as IBM's Visual Age for Java). If you are thinking of using these in the future, I recommend you doing the tutorial using them in order to get used to them now. However no matter which composition editor you use, you must understand and perform the analogous steps taken to construct, customize, and hook up the beans.Note: Sun's JavaStudio apparently does not support certain JavaBeans features, including bound properties. I recommend that you do not use JavaStudio for this assignment.
Much of Assignment #2 was about the structure of object-oriented programs. The structuring issues included:JavaBeans is a component architecture. It is therefore meant for component composition. JavaBeans consequently provide one answer for structuring an application. The question asked in this assignment is: how can the bean architecture be applied to the structuring issues of Assignment #2?
- How GUIs are hierarchically composed/decomposed using a composition hierarchy of GUI components. The components were
java.awt.Component
components. They were flexibly composed usingjava.awt.Container
to hold them and the delegation-based AWT 1.1 Event Model to connect them to other parts of the program. Although the composition was done "by hand", this was component composition, nonetheless. AWT components were instantiated, then customized (setFont()
, etc.) and then connected through events. We covered this in class, and you needed to know it to create an applet using UI component composition.
- How the application as a whole was separated into a Model being controlled by (multiple) Controllers and being viewed by (potentially multiple) Views. This was the MVC architecture. In the first part of the assignment you explored how the Model, View and Controller classes could be made reusable by using inheritance or delegation to remove connection information from the main classes and into either sub-classes or delegate classes. We learned that the delegation solution made it possible to connect them at run-time rather than at compile-time.
If UI elements are beans, it should be possible to compose UI elements to generate a UI's composition hierarchy. It might also be possible to compose the non-GUI architectural units if these architectural units could be made to be beans also. In reality, these beans are usually called "non-visual" beans because they are not part of the UI. The coding work that follows explores these ideas.
Part 2: Assigned Work and Questions |
In all assignment in this course I expect the English to be clear and precise and marks will be deducted where appropriate.
For the following, begin with the applet in the jar file given
here. This is a modified version of the
assignment #3 solution. If your browser has trouble downloading
the jar file correctly, you'll find the files individually placed
here. If you have trouble with getting the
gnu-regexp-1.0.6.jar working with you compiler or
appletviewer, please consult your JDK documentation on how to
set your CLASSPATH properly.
|
One of the most important functions of the composition editors is to build user interfaces from UI components. UI beans must be subclasses of ajava.awt.Component
. With a little work, the simple AWT-based classes in the original query applet can be made into UI beans.
- Convert
MaxHitControl
andSearchControl
into UI beans that each provide a bound property:MaxHitsControl
provides amaxHits
property andSearchControl
provides aquery
property. Do this by following the following steps:
- Both classes have an
java.awt.Panel
that is returned bygetComponent()
. Change these classes so that they inherit fromPanel
rather than have the panel as part-of the class. You will have make some changes to the other methods (e.g. the constructors) to correctly make this change.
- The bean now inherits all the methods from
Panel
. Override the beans'setFont()
,setBackground()
, andsetForeground()
so that when these properties are set, it sets the properties of all of its sub-components in addition to its own properties. This way the default customizers for the bean will modify its sub-components. For example, when aMaxHitControl.setBackground()
is called, all of the checkboxes will be set to the same colour.(You might want to make separate property setters for the colors of the different components in the search control. You would have to add a special customizer for the bean.)
- Follow the steps (given in the tutorial) to add support that allows
maxHits
andquery
to be properties that can be bound to other beans.
- Make sure your bean is serializable. Make sure that only those properties that should be serialized are. You can test out the serialization in Sun's BeanBox within the BDK.
Rename these two classes
AVHitControl
andAVSearchControl
respectively.
(Remember you can use Eckel'sch13/BeanDumper.java
to introspect your constructed beans. The BDK also has a report generator that can tell report your bean properties and events.)(8 marks)
- Create a manifest file for these classes and package them into a jar file called
AVControls.jar
. You can test these beans out in your favourite bean editor that supports bound properties. Did you notice what happens when you resize theAVHitControl
and run the generated applet?Be sure to include your manifest file when you hand in the code listings for your beans.
(For those of you who are interested, you can see the entire manifest format documentation online).
(1 mark)
- The beans you constructed above were composed from standard AWT classes. Many composition editors include the AWT components as UI beans already. Some composition editors allow beans to be composed into composite beans, which can in turn be used as an ordinary bean. Allowing the user to compose beans like this means they can create composite beans, that is, it allows for hierarchical composition. In a sense, the new beans you made are simply pre-packaged compositions.
Using a few short sentences, give three reasons why it might be helpful (or just better) to have supply users with pre-packaged compositions rather than just allowing users to build them using hierarchical composition in the composition editor.
(3 marks)
(16 marks total)
AResultsModel
instance is an object that will generate a set of events when the query text is changed. In the MVC paradigm, the events were generated bynotifyObservers
and the events were handled byObserver
s. JavaBeans component architecture uses the AWT 1.1 Event model to perform events. In the JavaBean world, these events:
- are named and identified by type (i.e.
XxxEvent
, which is an extension ofjava.util.EventObject
)- are registered by specific methods (i.e.
addXxxListener()
)- and are fired at listeners of a particular type (i.e. ones that implement
XxxListener
interface, which is an extension of thejava.util.EventListener
)
- Change
ResultsModel
into an invisible bean as follows:
- Change the event generation so that it fires
HitEvent
s at all of the registeredHitListener
s whenever new hits come in. Yes, you're obviously are going to have to construct the appropriateHitEvent
andHitListener
classes/interfaces sinceHitEvent
is a non-standard event. MakeHitEvent
save a reference to the new hit (pass it in during its construction), and provide a getter method for it. Remove theObservable
and theObservable
-style event generation. (3 marks)
- Make the
hit
,doneQuery
, andhitCount
so that they could be bound to a target bean. Sincehit
is an indexed property, add a method to retrieve the entire array (you will have to rename the private fieldhits
to simplyhit
to conform to the naming convention). Make sure a property change event occurs whensetQuery()
is called informing thathit
property has been updated. Make sure the property change events are fired whenever they change. (3 marks)Rename this
ResultsModel
to beAVQuery
.
(Most composition editors have debugging beans that display events that other beans generate. These can help you debug your bean. In the BDK, it is theEventMonitor
bean.)(6 marks subtotal)
- Now
AVQuery
updates the hits list and firesHitEvent
events whenever it updates it. ChangeListView
into a UI bean that can interact withAVQuery
as follows:
- Convert the class into a UI component as you did for the controllers, but inheriting from
List
instead ofPanel
.
- Make the new bean implement the
HitListener
interface you created for theAVQuery
to remember. In your listener method, retrieve theHit
thatAVQuery
stores in theHitEvent
through the getter method and add its title to the list. This replaces the formerupdateFrom()
method.
- Add a new boolean property
queryDone
. In its setter method, do aremoveAll()
on the list ifqueryDone
is being set tofalse
.Rename the class
AVList
. Now you can hook upAVList
beans toAVQuery
beans by binding theAVQuery.queryDone
property to theAVList.queryDone
property and also binding theHitEvent
s so thatAVList
has them fired at it. It should be possible to customize and hook up severalAVQuery
beans that are customized to query different engines.(3 marks)
- Create a manifest file and create a
AVQuery.jar
file that includesAVList
andAVQuery
and the support classes. You will need to include the class files in thegnu-regexp-1.0.6.jar
also. Read the jar documentation if you are uncertain about how to do this (you will likely have to un-jar thegnu-regexp-1.0.6.jar
first). Make sure you hand in your manifest file along with your code.(1 mark)
(10 marks total)
Part 3: Bean Technology Evaluation |
After Part I, you will have effectively created a set of beans that can be hooked up into an applet that is equivalent to theAVQuery
applet that was originally provided for you. The difference is that the customization and hookup code can be done in a composition editor rather than "by hand".Create an applet or application using your composition editor and the beans you created in this assignment such that the structure is analagous to the original MVC-based structure of
AVQuery
. (You'll haveAVQuery, AVList, AVHitControl
andAVSearchControl
beans hooked up).Note, you do not need to connect theYou should not hand this applet in, but use it to answer either question a or question b below.AVList
up so that it makes the browser load the URL specified when anActionEvent
occurs, but that is a good exercise. (See the objecthitSelection
in the originalAVQuery
). Also, if you do not wish to create an applet you can create an application instead by downloading and using an applet bean such as Sun's HotJava bean or the Ice Browser Lite bean.(If you did an alternate programming project, then you will have composed different UI and non-UI beans together instead, but the principle will be the same).
- Draw an object interaction diagram for your applet. This should be similar to the object interaction diagram avq-mvc.gif that was given to you in the sample solution to Assignment #2. You must include all listener and adapter objets, all AWT objects, and all bean instances. Label object with their type (class) and method calls between objects with the method names. Clearly show all event sources. Neatness and completeness count.
Note that in the unlikely case that your composition editor does not generate code that you can read, you should still be able to figure out what is needed since the tutorial describes how connections are made and events are fired. You can refer to the sample code made by BDK and placed in the lecture notes. You can add print statements to you constructors andaddListener
methods to trace which objects are being passed around.)
- Write a very short essay (1-3 paragraphs) that compares and contrasts the connections and decomposition of the original
AVQuery
(which used theObserver/Observable
method and the AWT 1.1 events) with the methods used by your composed JavaBeans. In your comparison, consider the following issues:Your little essay will be marked based on how well you identify comparable or contrastable features, and how well you execute the comparisons and contrasts.
- the mechanisms used for event generation/firing and event listening/reception.
- how sub-system elements are created and referenced
- the use of standard interfaces and how these affect independent composition. For instance, what are the requirements for using other beans with your JavaBeans as compared to using other classes in the original
AVQuery
applet?(10 marks)
If you have never written a JavaBean (or other similar components such as a VisualBasic custom control) before this course, write one paragraph (3-6 sentences) describing the most significant difficulty you had in learning how to implement and use JavaBeans. Suggest one thing that could be done to make JavaBeans development easier.If you have done JavaBean programming before this course (or written other similar components such as VisualBasic custom controls), write one paragraph (3-6 sentences) describing the the most significant problem you feel exists for JavaBeans (as they are implemented in Java 1.1). Suggest one thing that you think can be done to reduce this problem and explain why your suggestion would help.
For either category, your answer will be marked primarily on how well you describe your difficulty and the inventiveness of your answer. Marks will be taken off for answers that are do not earnestly try to answer the question well (e.g. joke answers).
(4 marks)