IBM Support

Using Java API to delete a model element from the project that has references in Read-Only unit file

Question & Answer


Question

How to delete a model element from the project that has references in a read-only unit file using Java API?

Cause

IBM Rational Rhapsody will not allow you to delete a model element without first getting rid of its references.

Answer

The solution is to first remove these references and then delete it from the model. Using the API, you can iterate over the references of the model element and then delete them from the project.It is important to check if the unit in which the references reside is 'Read-Only' or not.In the former case,the unit has to be set to 'Read-Write' before deleting the references. Otherwise, the deletion would fail.

See a sample code below. The selected element is a class that has references in another Read-Only package:

    [Code]
    IRPModelElement elem = (IRPModelElement)app.getSelectedElement();
    for(Object o:elem.getReferences().toList())
    {
    IRPModelElement ref = (IRPModelElement)o;
    IRPUnit unit = ref.getSaveUnit();
    if(unit.isReadOnly() == 1)
    {
    unit.setReadOnly(0);
    ref.deleteFromProject();
    unit.setReadOnly(1);
    }
    }
    elem.deleteFromProject();


    [/Code]

    Disclaimer

    All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

[{"Product":{"code":"SSB2MU","label":"IBM Engineering Systems Design Rhapsody"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"General Information","Platform":[{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"}],"Version":"7.5.1;7.5.0.1;7.5","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21420247