OCL (Object Constraint Language) is
the standard constraint language for MDE. Personally, I never
liked it because it had the look and feel of a "hacked" language; it
was not elegant nor simple.
AOCL is a pure-Java replacement for OCL. It is
literally a Java package that supports the operations and almost
matches the syntax of OCL that is generated directly from a Violet
class diagram or a CDSchema file. Both are documented in this
manual and how to transform these inputs into an AOCL package. Here
is the table of contents for this document:
A Violet class
diagram can be used to specify an AOCL package. Here
are the rules for creating Violet Class diagrams.
Abstract
classes are indicated in Violet by their name: "Abs_X" denotes class X
is abstract. The AOCL package will produce
a class "abstract class X" as a result. The figure below will
produce an abstract class with name "A"; it will have (by default
String) fields with names r, s, and t.
Violet
associations must be of one of 4 kinds:
BLACK_DIAMOND -- an association has
one end with a BLACK_DIAMOND and the other end with nothing; roles (x,y
below) must be supplied on both sides and so too a middle label (M, below).
DIAMOND -- an association has one
end with a DIAMOND and the other end with nothing; roles (x,y below)
must be supplied on both sides, and so too a middle label (M, below).
NM -- an association has no
cardinality end designators (BLACK_DIAMOND) or (DIAMOND) on either end;
roles
(x,y below) must be supplied on both sides AND that a middle label, to
indicate the name of a manufactured "association" class must be
supplied.
TRIANGLE --- a Violet association
encodes an inheritance relationship the TRIANGLE indicator at the
super-class end and nothing at the other end; no roles can be used.
Looped
associations (that start and end at the same class) are permitted and
follow the above rules for (a)-(c). The figure below shows a
diamond loop association, which has roles and a middle label:
Attributes
should be typed; if no type is specified "String" is assigned by
default. If "N" is given as an attribute name (i.e., N is
surrounded by quotes), N is a quoted string (and all of its values must
be quoted strings). If N is given by itself (without quotes), its
values must be non-quoted --- essentially meaning an Java
identifier. An attribute with name N and primitive type T is
written (on a separate line) as N:T. MDELite currently supports
the following primitive types:
int
float
double
bool
The figure below
shows an example of each attribute:
Use the
following tool to create an allegory package.
> java MDL.V2Aocl
CDschema Files
A cdschema file
is an intermediate representation of a class diagram. It is a
purely textual specification. Consider the class diagram to the
below left and its cdschema specification to the right:
starts with a declaration 'classDiagram X.' where X is the name of the diagram.
a sequence of one or more table definitions, exactly like those specified in a dbase schema, except only attributes of primitive types are permitted.
a sequence of zero or more subtable definitions, exactly like those specified in a dbase schema.
a sequence of zero or more association definitions.
The only
declaration that is in some sense new is an association
declaration. The order in which tables are listed is
important. Look at the following figure (a), which shows a Violet
association and how it is mapped to an association declaration (b).
For the case of
an NM association, because it is symmetrical, Emp or Dept could have
been listed first, followed by its role label, followed by its
association type (NM in this case), followed by a table (Dept) and its
role (worksin), followed by the middle label (Job) which will become
the name of an association class.
A more typical association is below. The first table listed is at
the BLACK_DIAMOND or DIAMOND end of an assoc declaration. The remaining parameters follow.
Converting a cdschema File into an AOCL package
Use the
following tool to create an allegory package.
> java MDL.V2Aocl
AOCL Examples
Consider the following class diagram (right) and its cdschema (left) as the basis for our AOCL examples.