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.
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.
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
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.
javac -classpath dresden-ocl-injector.jar
tudresden/ocl/test/royloy/*.javajava -classpath .;dresden-ocl-injector.jar
tudresden.ocl.test.TestInjectionRoyloyjava -jar dresden-ocl-injector.jar -r
tudresden.ocl.test.royloy --modify tudresden/ocl/test/royloy/*.javajavac -classpath dresden-ocl-injector.jar
tudresden/ocl/test/royloy/*.javajava -cp .:dresden-ocl-injector.jar
tudresden.ocl.test.TestInjectionRoyloyjava -jar dresden-ocl-injector.jar --clean --modify
tudresden/ocl/test/royloy/*.javaFurther 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.