Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Enumeration.createOwnedLiteral does not validate
icon5.gif  Enumeration.createOwnedLiteral does not validate [message #1750085] Thu, 15 December 2016 22:33 Go to next message
James Clark is currently offline James ClarkFriend
Messages: 8
Registered: December 2016
Junior Member
I am trying to programmatically add Enumeration Literals to a model within Rational Software Architect v9.1.2.2. The literals are successfully added to my model, but the model validation feature of the product flags each literal with an error:
"<Enumeration Literal> Behavioral" should contain "<Enumeration> Enumeration1" in its classifiers list.

The "Quick Fix" feature of RSA corrects each literal; it adds a "classifier" attribute to the ownedLiteral. Here is model fragment before the Quick Fix is applied:
      <ownedLiteral xmi:id="_Nx2GtMMKEea6HrNAvPVpYQ" name="Behavioral">
        <specification xmi:type="uml:LiteralString" xmi:id="_Nx2GtcMKEea6HrNAvPVpYQ" value="B"/>
      </ownedLiteral>

And the model fragment after the Quick Fix is applied:
      <ownedLiteral xmi:id="_Nx2GtMMKEea6HrNAvPVpYQ" name="Behavioral" classifier="_Ige0YMMCEea6HrNAvPVpYQ">
        <specification xmi:type="uml:LiteralString" xmi:id="_Nx2GtcMKEea6HrNAvPVpYQ" value="B"/>
      </ownedLiteral>

And here is the Java method adding an enumeration literal:
private void addEnumerationLiteral(org.eclipse.uml2.uml.Enumeration umlEnumeration, Integer literalNameIndex, Integer literalValueIndex, Integer literalDocumentationIndex, ArrayList<String> attributeFields)
{
        Comment documentation;
        List<Element> annotatedEls;
        Stereotype stereotype;
        
        EnumerationLiteral enumLiteral = umlEnumeration.createOwnedLiteral(attributeFields.get(literalNameIndex));
               
	// Add the literal value, if provided.
	if (literalValueIndex != -1)
	{
		LiteralString value = org.eclipse.uml2.uml.UMLFactory.eINSTANCE.createLiteralString();
		value.setValue(attributeFields.get(literalValueIndex));
		enumLiteral.setSpecification(value);        	
	}
		
	// Add the literal documentation, if provided.
        if (literalDocumentationIndex != -1)
        {
    		documentation = enumLiteral.createOwnedComment();
    		documentation.setBody(attributeFields.get(literalDocumentationIndex));
    		annotatedEls = documentation.getAnnotatedElements();
    		annotatedEls.add(enumLiteral);	
    		stereotype = documentation.getApplicableStereotype("Default::Documentation");
    		if (stereotype != null)
    			documentation.applyStereotype(stereotype);
        }
}

So my question is, is there an API call available to create an enumeration literal that is "valid"?
Re: Enumeration.createOwnedLiteral does not validate [message #1750147 is a reply to message #1750085] Fri, 16 December 2016 12:11 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1176
Registered: July 2009
Location: Canada
Senior Member

Hi,

Have a look at the InstanceSpecification::getClassifiers() API.

HTH,

Christian
icon12.gif  Re: Enumeration.createOwnedLiteral does not validate [message #1750415 is a reply to message #1750147] Tue, 20 December 2016 20:58 Go to previous messageGo to next message
James Clark is currently offline James ClarkFriend
Messages: 8
Registered: December 2016
Junior Member
Thanks, but I didn't see anything applicable. I'm really looking for something like a .setClassifier().
Re: Enumeration.createOwnedLiteral does not validate [message #1750417 is a reply to message #1750415] Tue, 20 December 2016 21:05 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1176
Registered: July 2009
Location: Canada
Senior Member

You add to the list returned by InstanceSpecification::getClassifiers(). This is the standard EMF idiom for manipulating multi-valued features.

Cheers,

Christian
Re: Enumeration.createOwnedLiteral does not validate [message #1750653 is a reply to message #1750417] Fri, 23 December 2016 21:24 Go to previous message
James Clark is currently offline James ClarkFriend
Messages: 8
Registered: December 2016
Junior Member
Ah, I was making it harder than it really was. Adding this line of code did the trick:
enumLiteral.getClassifiers().add(umlEnumeration);

Thanks for your help!
Previous Topic:SySML in Java
Next Topic:How to access Message arguments sent with a signal triggering a transition
Goto Forum:
  


Current Time: Sat Sep 22 22:28:18 GMT 2018

Powered by FUDForum. Page generated in 0.02680 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top