An Aocl Example
March 5, 2020



Although OCL is a complex language, at its core is an elegant sublanguage of Relational Algebra, written in an OO syntax, with special names for right-semijoins (a.k.a. association traversals).  This reduced language is Aocl, which can be implemented in pure Java 8.0.  Given a textual specification of a class diagram, a tool generates the Aocl package for that class diagram to write metamodel constraints or to write model transformations.  This example previews the Aocl toolset. A class diagram is given with its generated Aocl Java package, and with Java programs that illustrate/execute Aocl expressions.


Installation

Copy the files of this distribution into a fresh directory DIR.  Place the following Jars In the DIR/dist/ directory onto your Java CLASSPATH:
On windoze this is:
> set CLASSPATH=%CLASSPATH%;DIR\dist\MDELite9.1.jar;DIR\dist\Meta4.0.jar


On Macs, try:

> export CLASSPATH=$CLASSPATH:DIR\MDELite9.1.jar:DIR\Meta4.0.jar

Also, make sure that dot (.), the current directory, is also on your CLASSPATH!  To compile the source code of this distribution type:
Dir> java *.java

Please note: by doing the above, you have installed the binary version of Aocl.

Overview

I created an example for you to try Aocl.  It has all you need to pose and execute queries and constraints on the class diagram below.  The diagram has 3 classes:
Further, there are 3 associations:

% a line-comment begins with %

classDiagram Alleg.

table(Emp,[name,age:int]).
table(Dept,[name,'city']).
table(Div,[name]).

assoc(Anc,Emp,parOf,BLANK,Emp,chldOf,BLANK).
assoc(Job,Emp,employs,BLANK,Dept,worksin,BLANK).
assoc(DD,Div,inDiv,BLACK_DIAMOND,Dept,hasDept,BLANK).


To the right of the diagram is a textual specification of the diagram itself.  Briefly:
This textual specification is called a CDSpec (for Class Diagram Specification), and is stored in a file named, for example, alleg.cdspec.pl
Note: there is some constraint checking in CDSpec. It could be improved, like having a CDSpec conformance program.  On my TODO list.

Meta4 Tool

A Java tool, Meta4, translates a CDSpec file into a Java package that implements tables, tuples, and databases and operations on them.  You have Meta4 in this distribution.  If you want to see what it does, type:
> java M4.Meta4 alleg

or

> java M4.Meta4 alleg.cdspec.pl


The contents of directiory Allegory/Alleg will be generated.  (I've already given it to you in this distribution, so you can skip this step. Note: the first letter of a package name is capitalized by Meta4).  There is a Java class file for:
Of course, you'll need a database (a relational database encoding of an object-diagram) on which you are to execute your queries.  I've provided one x.alleg.pl (x is the name of the database whose schema  is alleg.schema.pl).


Running Aocl

3 programs that You can edit and run 3 Java programs:
Run any of the above (like Driver) without arguments:
> java Driver
All output is to Standard.out.  A bash script to clean the directory is clean.script.

Have Fun!  Send complaints and comments to batory@cs.utexas.edu.