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);
}
}
}
}
}
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 Synonym
Rational Rhapsody
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21991351