• Ei tuloksia

JavaFrames Patterns for JHotDraw and Struts

Chapter 7 Case Studies

7.1 JavaFrames Patterns for JHotDraw and Struts

The experiments with metapatterns and design patterns provided a way to try out the idea of creating patterns by extending one pattern from another. After that it was time to move on to building reuse interface annotations for real frameworks.

As a combined case study with Jukka Viljamaa, we annotated the reuse interface of the Struts servlet framework (recall Chapter 3.2.3) by using the library of hier-archical patterns. After that, Jukka Viljamaa created another annotation for the Struts framework by using his semi-automatic Pattern Extractor. In his PhD the-sis, Jukka Viljamaa compared the results of the semi-automatically made patterns to yet another “flat” annotation of Struts where he had removed the pattern hier-archies. The hierarchies were removed because Pattern Extractor does not pro-duce hierarchical patterns.

I, in turn, chose to re-annotate the JHotDraw framework that I had already used in my licentiate thesis. There were two reasons for this. Firstly, I wanted to make a case study with a more traditional OO framework; Struts is a bit exceptional, since it heavily utilizes XML and JSP instead of subclassing. Also, by re-annotating a framework that was tested with the earlier (Fred 1.3) version of JavaFrames I was able to get more material for comparing “flat” and hierarchical framework reuse interface annotations.

For the JHotDraw framework I picked the latest stable version (5.3) from [www.jhotdraw.org]. Similarly, the Struts case study involved the latest version (1.1) of the Struts framework available at [struts.apache.org]. Recall the descrip-tions on the sizes and characteristics of the frameworks in Chapter 3.2.3.

In the case studies with the JHotDraw and Struts frameworks I managed to spec-ify the reuse interfaces of the frameworks nicely by specializing new framework-dependent patterns from my library of reusable patterns. The following figures provide a high-level view to the patterns. The full versions for the patterns are available in Appendix B.

Figure 7.1 shows the top-level of the reuse interface annotation for the JHotDraw framework. At the highest level, the JHotDrawFramework architecture contains one pattern (Initialization) and nine inner architectures: ConnectionFigure, Con-nectorBasics, FigureBasics, FigureChangeListener, FigureConnections, Han-dleBasics, HandlesForFigures, Storable, and ToolBasics. The Initialization pat-tern is used for specifying the main class for the application and for instantiating the central application objects. Note that all the patterns recursively inside the JHotDrawFramework architecture extend patterns from the reusable pattern li-brary; in this top-level figure the extensions are only shown for the Initialization pattern.

Figure 7.1: The top level of the of JHotDraw reuse interface specification

Figure 7.2 shows the ToolBasics pattern. It is used for creating and restricting the properties of classes that represent JHotDraw tools. Tools will be visible in the program’s tool bar. Tools are employed for creating, selecting, and manipulating figures and connectors. The patterns in the ToolBasics architecture are based on each other: AbstractTool extends Tool and the other patterns, in turn, extend Ab-stractTool.

The HandlesForFigures architecture (Figure 7.3) is used for attaching handles to figures. The ConnectorBasics pattern, on the other hand, is used for creating and restricting the properties of connectors. They connect figures to each other.

The patterns in the FigureBasics architecture (Figure 7.4) are used for creating and restricting the properties of classes that represent figures drawn in JHotDraw applications. The FigureChangeListener pattern is used for adding listener be-havior into classes. The listener receives notifications about changes in figures.

«architecture»

Figure 7.2: JHotDraw reuse interface specification — ToolBasics

Figure 7.3: JHotDraw reuse interface specification — HandlesForFigures and Connec-torBasics

Figure 7.4: JHotDraw reuse interface specification — FigureBasics and Figure-ChangeListener

The patterns in HandleBasics architecture (Figure 7.5) are used for creating and restricting the properties of classes that represent figure handles. Handles are

«architecture»

used for manipulating figures. The Storable pattern is used for making objects persistent.

Figure 7.5: JHotDraw reuse interface specification — HandleBasics and Storable The patterns in the ConnectionFigure architecture (Figure 7.6) are meant for cre-ating and restricting the properties of figures that represent connectors. The Fig-ureConnections pattern can be used for attaching connectors and figures to each other.

Figure 7.6: JHotDraw reuse interface specification — ConnectionFigure and Figure-Connections

Figure 7.7 represents a top-level view of the reuse interface specification of the Struts framework. In this specification I arranged the patterns in a little bit differ-ent manner compared to the JHotDraw reuse interface annotation. This was due to the simpler Java implementation of Struts. Consequently, there is only one ar-chitecture element in the Struts annotation and the patterns extend the generic OO patterns and bean patterns, but not each other.

At the highest level, the Struts Framework architecture contains nine patterns:

JavaServerPageFile, TagSupport, DeployServlet, ConfigurationFile, Documen-tation, Logging, UserDataBean, ActionForm, and Action. All the patterns, be-sides Documentation, extensively use the patterns from the reusable pattern li-brary.

The JavaServerPageFile pattern can be used for creating the JSP files needed in a Struts application. The pattern supports the generation of the central JSP tags

«architecture»

ConnectionFigure

«pattern»

ConnectionFigure

«pattern»

LineConnection

MethodOverriding

«architecture»

FigureConnections

«pattern»

FigureConnections

MethodOverriding

«architecture»

HandleBasics

«pattern»

ChangeConnectionHandle

MethodOverriding, Class

«pattern»

AbstractHandle

MethodCall, Constructor

«pattern»

Handle

«architecture»

Storable

«pattern»

Storable

MethodOverriding

that allow, for example, invoking the specified actions and accessing the User-DataBeans of the application. The TagSupport pattern allows the application de-veloper to create new custom JSP tags for JSP files. The DeployServlet pattern offers support for creating suitable Ant scripts [ant.apache.org] for compiling and packaging the finished application into a WAR file [java.sun.com/j2ee/tuto-rial/1_3-fcs/doc/WCC3.html] and installing it in a Java servlet container such as Apache Tomcat [jakarta.apache.org/tomcat/]. The ConfigurationFile pattern helps the application developer in providing the Struts configuration file. The configuration file glues together the various parts of a Struts application. The Documentation pattern captures general level documentation related to the Struts framework and its the reuse interface specification. The Logging pattern provides support for implementing a logging facility that monitors executed actions during application run-time. UserDataBean offers support for creating JavaBeans that contain the application data. The ActionForm and Action patterns are for creating and restricting the properties of action form and action classes, respectively.

Figure 7.7: Struts reuse interface specification