- Documentation
- Developer's corner
Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering
The LogicAJ demo project contains two small applications using a range of aspects that implement different concerns (generic visitor and decorator patterns, mock objects and contract checking). For an introduction to basic ideas behind the aspects used in the demo see: LogicAJ Demo Slides.
Before trying out the project, make sure your LogicAJ installation is up-to-date: See ROOTS update site.
Get the demo project from LogicAJDemoProject_0.5.zip (26.05.2009)
and extract it into your workspace. Then import the project into your Eclipse Workspace via File→Import…→Existing Projects
To execute the applications weave the aspects by opening an aspect (or any file in the demo project) and clicking the button.
All necessary aspects are activated by default (they have all been added to the ''lajbuild'' file (The
lajbuild
file
is found on the top-level of each LogicAJ project. By adding or commenting
out lines of this file you can activate or deactivate aspects as you like.).
Then execute the corresponding Main classes (see below) in the LogicAJDemo-output
project.
Main class: /LogicAJDemo/src/wikiviewer/Main.java
Opens a Swing application window with two buttons, one showing in the left-hand-side pane the original wiki text, the second intended to show the text as html. However, in the base application the second button also shows the orginal wiki text.
Once the DecoratorAspect and the StreamReaderDecorator aspect are woven the wiki text output is decorated with HTML tags. Since the left-hand-side pane is a HTML viewer, the output is formated accordingly.
See the slides and the code of aspects.AbstractDecorator
for details how the decorator
pattern is implemented generically in LogicAJ and aspects.StreamReaderDecorator
for its concretization as a StreamReaderDecorator.
![]() Plain Text View |
![]() Html View |
Main class: /LogicAJDemo/src/html2wiki/Main.java
This application takes an URL string and puts out corresponding
JSP wiki syntax on the console. To achieve this, it uses an aspect-generated visitor that traverses the
HTML abstract syntax tree (toplevel class is HtmlElement
). An “accept” method is introduced to all
elements of the HTML syntax tree as part of a generic Visitor Pattern implementation.
Be aware that the base application is not functional without the woven aspects, since it references visitor classes and methods generated by LogicAJ aspects. In order to let the LogicAJ compiler graciously accept forward references to types or methods that will only come into life during weaving, LogicAJ offers a new feature called non-oblivious call. It is supported by the overloaded method call(..) in the class logicaj.NO (NO for “Non-Oblivious”). By now you have to include this class with every base program (this limitation will be removed in the future). See the Java-Doc for usage details.
The aspects used for this example are the ConcreteVisitorAspect and AbstractVisitorAspect described below. Their main effects are illustrated in the image:
HtmlElement$Visitor
containing visit(<ElementType> elem){}
methods for all subtypes of thhtml2wiki.parser.internal.node.HtmlElement
.Html2WikiVisitor
extends the generated HtmlElement$Visitor
accept(HtmlVisitor v) { v.visit(this);… }
methods to all subtypes of HtmlElement
This optional aspect can be use to parse a local html file (test.html) instead of loading the file from the given URL. For details on the mock aspect see here.