IBM Support

How to generate an IBM Rational Rhapsody warning while class name and package name are same through a JAVA API?

Question & Answer


Question

How to generate warning while class name and package name are same through a JAVA API in IBM Rational Rhapsody?

Cause

You might have created a class with the same name as package.

Answer

Please write a JAVA API as follows to get a warning message while running Rhapsody with same class name as package:



IRPProject myProj = myApp.activeProject();
IRPCollection myColl = myProj.getNestedElements();
IRPCollection myPack = null;

for(int i = 1; i <= myColl.getCount(); i++)
{
IRPModelElement getitem = (IRPModelElement) myColl.getItem(i);
if(getitem.getMetaClass().equals("Package"))
{
myPack = getitem.getNestedElements();
for(int p = 0; p <= myPack.getCount(); p++)
{
IRPModelElement pckgEle = (IRPModelElement) myPack.getItem(p);
if(pckgEle != null)
{

if(pckgEle.getName().equals(getitem.getName()))
{
System.out.println("Error");
String msg = pckgEle.getName() + " " + "Has Duplicate name " + "\n";
rpyApplication.writeToOutputWindow("Duplicate_Name" , msg);
}
}
}


}

}

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":"PF033","label":"Windows"}],"Version":"8.1.5","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21991351