Defining model libraries

You can define code libraries as model libraries and during reverse engineering, Rational® Rhapsody® will load only those classes that were referenced in your code.

When modeling applications in IBM® Rational Rhapsody, you may find it useful to have your model include classes that you use from predefined libraries.

One of the drawbacks of including such libraries in your model is that they are often quite large and therefore may use a lot of resources if loaded in full into the model you are working on. The model library feature makes it possible to load only those classes that are referenced in your model.

This feature can only be used for Java libraries.

Rational Rhapsody uses this feature to selectively load library classes for developers who are using the Android SDK. You can use this feature to define additional libraries that you use in your work.

Defining a model library

Procedure

To define a model library and then use it in a model:

  1. Create a Java model.
  2. Import the code for the library into the model (Tools > Reverse Engineering). In the Reverse Engineering window, select the Interface Visualization option.
  3. Apply the ModelLibrary stereotype to the top-level package created for the library.
  4. Save the model. The top-level package created for the library is saved as an .sbs file. This is the file that you will load when you want to use the library in a model.

What to do next

Once you have created the model library, you can then use the library as a reference in your models.

Using a model library that you have defined

Procedure

Carry out the following steps in the models where you would like to use the library:

  1. Add (as a reference) the .sbs file that represents the model library you created (File > Add to Model).
  2. Unload all of the units in the package that represents the library. (The simplest way to do this is to unload the top-level package created for the library.)

Results

The next time you reverse engineer or roundtrip code that uses a class from the library, you will see that the package that contains the referenced class has been loaded. The remaining library classes are displayed as stubs and have the U (unloaded) symbol next to them. For example, if your code includes the statement import android.gesture.GesturePoint;, then after the code is reverse engineered or roundtripped, the android.gesture package will be loaded in the model while the unused packages remain unloaded.

Feedback