This chapter describes, how to use the instrumentation tool. Section contains an example quickly demonstrating the main features. Section provides a complete reference of the command line options.
First, get the following files: dresden-ocl-injector.jar, xerces.jar and royloy.jar. These files are available on our website at dresden-ocl.sourceforge.net or may be produced from the sources using the makeJar script. Put these files into one directory and change into that directory.
The file royloy.jar contains the example code. To unzip it type:
Now it's time to start the OCL tool. Type the following command on a single line. Note, that the wildcards require a Unix shell to be expanded.
To check this, compile the modified java code (again type everything on a single line):
Run the test main function provided:
Clean the code from the modifications the OCL tool made.
Note, that the code actually was cleaned. No backups involved. To check this, try the following:
Synopsis is below.
Options recognized are below. Most options have a short and a long version. Long versions try to be self explanatory and should be used in scripts.
Enables modifying java files. If not provided, the modified java code is written to file.java.injected. This switch serves as a safety check, whether you really want to replace your source code with the output of the OCL tool.
Performs cleaning of source files instead of instrumentation. After cleaning, the source code should show no differences to the version before running the OCL tool.
Specifies the text file containing the constraints. Usually not needed, since constraints may and should be placed into javadoc comments. See section .
Specifies the java packages containing the model covered. If there is a constraint context Person, the type checker will look for class Person in all packages given by this option. This is some kind of ``import for OCL''. For multiple packages use multiple options.
Specifies the name adapter. Default is none. If you don't use code generated by Argo/UML, the default is sufficient. Further information on name adapters is available at [FF00] section 3.5.1 and 3.5.6.
[all|private|protected|package|public|explicit]
Specifies the the scope of invariants used. See section for a detailed explanation. Access modifiers select methods having the same or a more public access modifier. Thus, all and private are equivalent. Default is all.
Specifies what to do, if a constraint fails. This string is inserted verbatim into the code. The OCL tool appends a pair of parents enclosing a suitable message string. Good candidates are System.out.println (the default) or throw new RuntimeException. Note, that the latter must be enclosed in "" on Unix shells.
The exception thrown must not be a checked exception as specified by [GJS96] section 11.2. Otherwise the modified code will not compile!
Performs type tracing of collection elements. See section for details. The information gathered is written to a log file specified by property tudresden.ocl.injection.lib.TypeTracer.log.
Note, that the log file must be specified when running the user program, not the OCL tool! For example use -Dtudresden.ocl.injection.lib.TypeTracer.log=example.ocltypetrace. If not specified, the type information is written to standard out.
Triggers immediate insertion of wrapper methods. Otherwise wrapper methods are inserted at the end of each class. Immediate insertion allows easier tracing of the modifications. This option is mainly useful for debugging.
Adds code logging each constraint checked on an object to standard out. Useful for debugging.
Uses simple hash functions in HashSize, instead of the sophisticated hash functions in HashExact. Simple hash functions just return the size of the collection, so they will detect insertions/deletions only. Reduces CPU load for big models.
Uses hash functions in HashModCount, instead of the hash functions in HashExact. HashModCount functions are even better in modification detection than functions in HashExact. Also, they are almost as fast as HashSize. However, they heavily depend on internals of the java collections implementation. Use at your own risk. See section .