Dresden OCL Toolkit

Dresden OCL Toolkit - Usage Examples

The Royals and Loyals model

The model presented here is taken (with some modifications) from the book "The Object Constraint Language: Precise Modeling With UML" by J. Warmer and A. Kleppe, where it serves as a showcase for the use of OCL constraints. It has been implemented in Java to demonstrate the abilities of the Dresden OCL Toolkit.

The Royals and Loyals model

You can download the complete model as JAR file (royloy.jar). This allows you to inspect more than the few OCL constraints listed next serving as examples and also to perform the code instrumentation and runtime constraint checking using the toolkit from the command line yourself as explained later.

OCL constraints

Listed below are only those OCL constraints defined within the Company class. Download the complete model and browse the Java files yourself for more constraints.

@invariant manager_is_employee:
  employees->iterate(
    p:Person ; b:Bag(Person)=Bag{} |
    b->including(p)
  )->includes(manager)

@invariant manager_is_employee2:
  manager.employers->includes(self)

@invariant :
  manager.oclIsKindOf(Person)

@invariant numberOfEmployees:
  self.numberOfEmployees=employees->size

Try toolkit on real code

Preparations

To perform the subsequent steps you need to have the Java archive (JAR) dresden-ocl-injector.jar. As it is part of the release version 1.1 you can either dowload the release or you can build it from the SVN sources (see the download page for details) using the ant target ant jar.dresden-ocl-injector. In the latter case, the archive will be created in the build subdirectory.

In addition you need the Royals and Loyals model, of course. While it is also contained in the SVN repository (tudresden/ocl/test/royloy), you might as well download royloy.jar and. You must then extract the archive's contents into the directory that holds the dresden-ocl-injector.jar by copying it there and then typing

jar -xf royloy.jar

at the command line from within that directory.

The example step by step

  1. Compile the example.
    javac -classpath dresden-ocl-injector.jar tudresden/ocl/test/royloy/*.java

  2. Run the example.
    java -classpath .;dresden-ocl-injector.jar tudresden.ocl.test.TestInjectionRoyloy
    No output is being generated as the example code is being executed flawlessly.

  3. Compile the examplary OCL expressions and generate the constraint checking code.
    java -jar dresden-ocl-injector.jar -r tudresden.ocl.test.royloy --modify tudresden/ocl/test/royloy/*.java

  4. Compile the example again.
    javac -classpath dresden-ocl-injector.jar tudresden/ocl/test/royloy/*.java

  5. Run the example again...
    java -cp .:dresden-ocl-injector.jar tudresden.ocl.test.TestInjectionRoyloy
    ...and enjoy the notifications on violations of OCL constraints.

  6. Clean the code to reset the example.
    java -jar dresden-ocl-injector.jar --clean --modify tudresden/ocl/test/royloy/*.java

Further examples

Further examples on the utilization of the Dresden OCL Toolkit have been given along with the integrations of the toolkit into ArgoUML and Together. See the examples on the integration into ArgoUML and Together respectively.