Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Applying stereotype to property as association end throws IllegalArgumentException
Applying stereotype to property as association end throws IllegalArgumentException [message #896064] Tue, 17 July 2012 07:02 Go to next message
Martin Benedict is currently offline Martin BenedictFriend
Messages: 22
Registered: June 2012
Junior Member
I have a problem in an M2M-transformation with ATL, but I think this is more a UML2 specific problem, so I decided to post my question here.

I want to apply a stereotype which is defined for UML-Property to a property used in an association. The problem I have is that an IllegalArgumentException is thrown in the case of using the stereotype for an association-associated property. If I apply the stereotype to an property which is used in a class as an attribute everything is fine.

Here is a code snippet from the exception throwing part:


-- ...
p1: UML!Property(
		
	upper <-a.associationEnds.first().conformance.upperBound,
	lower <- a.associationEnds.first().conformance.lowerBound,
	name <- a.associationEnds.first().name,
	type <- firstMemberType,
	opposite <- p2,
	isComposite <- true
),

p2: UML!Property(
		
		upper <-a.associationEnds.last().conformance.upperBound,
		lower <- a.associationEnds.last().conformance.lowerBound,
		name <- a.associationEnds.last().name,
		type <- secondMemberType,
		opposite <- p1
	),

as:UML!Association(
		name <- a.name,
		ownedEnd <- Set{p2}
		navigableOwnedEnd <- Set{p1}
		)
	do {
p1.applyStereotype(thisModule.getStereotype('xsdElement')); -- here an exception is thrown: see below
}


The following IllegalArgumentException is thrown.


Here appear some other resulting stacktraces.
......

Caused by: java.lang.IllegalArgumentException: org.eclipse.uml2.uml.internal.impl.StereotypeImpl@21ee05 (name: xsdElement, visibility: <unset>) (isLeaf: false, isAbstract: false) (isActive: false)
	at org.eclipse.uml2.uml.internal.operations.ElementOperations.applyStereotype(ElementOperations.java:1413)
	at org.eclipse.uml2.uml.internal.impl.ElementImpl.applyStereotype(ElementImpl.java:510)
	... 18 more


It seems like that p1 is not a property any longer. Anyone an idea? Would be great. thanks,
Martin

EDIT: I've missed to mention that I use UML=http://www.eclipse.org/uml2/3.0.0/UML.
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #896072 is a reply to message #896064] Tue, 17 July 2012 07:18 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

This looks like an ATL/ATL-user problem. UML provides APIs and it
appears that they are not being used correctly.

I've never understood ATL semantics so I cannot comment on the validity
of your p1 or getStereotype() usage; both are potentially suspect.

I suggest using the debugger, though if you're lucky someone on the ATL
newsgroup might rexcognise the problem.

Regards

Ed Willink


On 17/07/2012 08:02, Martin Benedict wrote:
> I have a problem in an M2M-transformation with ATL, but I think this
> is more a UML2 specific problem, so I decided to post my question here.
>
> I want to apply a stereotype which is defined for UML-Property to a
> property used in an association. The problem I have is that an
> IllegalArgumentException is thrown in the case of using the stereotype
> for an association-associated property. If I apply the stereotype to
> an property which is used in a class as an attribute everything is fine.
> Here is a code snippet from the exception throwing part:
>
>
>
> -- ...
> p1: UML!Property(
>
> upper <-a.associationEnds.first().conformance.upperBound,
> lower <- a.associationEnds.first().conformance.lowerBound,
> name <- a.associationEnds.first().name,
> type <- firstMemberType,
> opposite <- p2,
> isComposite <- true
> ),
>
> p2: UML!Property(
>
> upper <-a.associationEnds.last().conformance.upperBound,
> lower <- a.associationEnds.last().conformance.lowerBound,
> name <- a.associationEnds.last().name,
> type <- secondMemberType,
> opposite <- p1
> ),
>
> as:UML!Association(
> name <- a.name,
> ownedEnd <- Set{p2}
> navigableOwnedEnd <- Set{p1}
> )
> do {
> p1.applyStereotype(thisModule.getStereotype('xsdElement')); -- here an
> exception is thrown: see below
> }
>
>
> The following IllegalArgumentException is thrown.
>
>
>
> Here appear some other resulting stacktraces.
> ......
>
> Caused by: java.lang.IllegalArgumentException:
> org.eclipse.uml2.uml.internal.impl.StereotypeImpl@21ee05 (name:
> xsdElement, visibility: <unset>) (isLeaf: false, isAbstract: false)
> (isActive: false)
> at
> org.eclipse.uml2.uml.internal.operations.ElementOperations.applyStereotype(ElementOperations.java:1413)
> at
> org.eclipse.uml2.uml.internal.impl.ElementImpl.applyStereotype(ElementImpl.java:510)
> ... 18 more
>
>
> It seems like that p1 is not a property any longer. Anyone an idea?
> Would be great. thanks,
> Martin
>
> EDIT: I've missed to mention that I use
> UML=http://www.eclipse.org/uml2/3.0.0/UML.
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #896100 is a reply to message #896072] Tue, 17 July 2012 09:23 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro FaellaFriend
Messages: 31
Registered: June 2012
Member
I get the same exception, programmatically, when I call "applyStereotype" of org.eclipse.uml2.uml.NamedElement
I'm trying to use a custom profile (uml testing profile from omg website that I suppose to edit in right way).
I debugged it and the problem is born at:

myClass.applyStereotype(stereotype);

in particular the exception is thrown by org.eclipse.uml2.uml.internal.operations.ElementOperation at line 1413 because of this condition:

if (definition == null || getExtension(element, stereotype) == null || element.getStereotypeApplication(stereotype) != null)

where "getExtension(element, stereotype) == null" is true.
I think that it depends on the profile model...
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #896143 is a reply to message #896064] Tue, 17 July 2012 12:05 Go to previous messageGo to next message
Martin Benedict is currently offline Martin BenedictFriend
Messages: 22
Registered: June 2012
Junior Member
As suggested by Mauro I have searched for problems with my profile respectively OUT-model. I have checked out the ATL source code and done some debugging. I've analyzed the finalizeModel()-method and all called methods and the contents of the variables.

I have found that the problem was appearing because my associations were in the root package of my uml-out-model, but the profile application happend unintentionally on a subordinated package. So the stereotypes couldn't be applied to objects in the root package. I've applied the profile to the root package and everthing was working.

Thanks for any help.

Also asked and answered at: stackoverflow.com/questions/11518396/applying-stereotype-to-property-as-association-end-throws-illegalargumentexcepti/11522179#11522179

[Updated on: Tue, 17 July 2012 12:14]

Report message to a moderator

Re: Applying stereotype to property as association end throws IllegalArgumentException [message #896151 is a reply to message #896143] Tue, 17 July 2012 12:23 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro FaellaFriend
Messages: 31
Registered: June 2012
Member
Martin, please, can you tell me how did you define the profile? By Example EMF Model Creation Wizards? Have you done an ecore metamodel plugin first?
I'm doing this questions because I'm trying to use the UML Testing Profile provided by OMG, but I'm having some problems.
Thanks for the answers
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #896160 is a reply to message #896143] Tue, 17 July 2012 12:46 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It would appear that them UML routine declined to do what you wanted
becuase the invocation context was invalid.

It would therefore seem that either the UML routine was silent about the
problem, or ATL threw away an exception.

If your debugging enables you to tell where the missing diagnostic is,
perhaps you can report a bug so that the next user is less confused.

Regards

Ed Willink


On 17/07/2012 13:05, Martin Benedict wrote:
> As suggested by Mauro I have searched for problems with my profile
> respectively OUT-model. I have checked out the ATL source code and
> done some debugging. I've analyzed the finalizeModel()-method and all
> called methods and the contents of the variables.
> I have found that the problem was appearing because my associations
> were in the root package of my uml-out-model, but the profile
> application happend unintentionally on a subordinated package. So the
> stereotypes couldn't be applied to objects in the root package. I've
> applied the profile to the root package and everthing was working.
>
> Thanks for any help.
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #896350 is a reply to message #896160] Wed, 18 July 2012 07:09 Go to previous messageGo to next message
Martin Benedict is currently offline Martin BenedictFriend
Messages: 22
Registered: June 2012
Junior Member
Mauro, I use a given profile from a standard-defining organisation.
I have it exported from MagicDraw 17.0.1. The profile is based on EMF xmi v 3.x.
The MagicDraw export had generated some more profiles like "UML_Standard_Profile.*", but I think they are not very important.
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #896354 is a reply to message #896350] Wed, 18 July 2012 07:29 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro FaellaFriend
Messages: 31
Registered: June 2012
Member
ok, thanks.
Also I am trying to use a given profile from OMG but I'm having few problems. But it is another story Smile
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #897912 is a reply to message #896354] Wed, 25 July 2012 12:25 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro FaellaFriend
Messages: 31
Registered: June 2012
Member
I'm still having this issue programmatically.
I tried to apply a stereotype from UML Editor with my custom profile and it works well. Before, I need to load the "profile.uml" resourse and apply it to my 'model', after that I can simply apply a stereotype. All works well...
But programmatically when I call
myClass.applyStereotype(stereotype);

I get the same exception of Martin:
Exception in thread "main" java.lang.IllegalArgumentException: org.eclipse.uml2.uml.internal.impl.StereotypeImpl@90832e (name: TestComponent, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)
	at org.eclipse.uml2.uml.internal.operations.ElementOperations.applyStereotype(ElementOperations.java:1413)
	at org.eclipse.uml2.uml.internal.impl.ElementImpl.applyStereotype(ElementImpl.java:510)
	at test.main(test.java:65)

Before, I apply the profile to the Model and it works well:
testModel.applyProfile(profModel); //testModel is a org.eclipse.uml2.uml.Model
                                   //profModel is a org.eclipse.uml2.uml.Profile

I'm thinking that the problem could depend on ResourceSet initialization that I do with (API uml2 4.0.0):
UMLResourcesUtil.init(RESOURCE_SET);

Do I maybe add to the packageRegistry my custom profile? But I don't know how and what I must put in it.

Thanks in advance,
mf
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #899104 is a reply to message #897912] Mon, 30 July 2012 14:59 Go to previous messageGo to next message
Mauro Faella is currently offline Mauro FaellaFriend
Messages: 31
Registered: June 2012
Member
Hi all,
I'm trying and trying but the problem is still here.
I attach the java and uml files so you should test it about my issue. There are some jar to include into the build path and they can be found in plugins directory of eclipse (I'm using Juno edition).
The profile used in this test is given by Eclipse plugin, and it returns the same exception that I get with a custom profile.

Thanks in advance for every feedback
  • Attachment: Test.java
    (Size: 2.59KB, Downloaded 588 times)
  • Attachment: Test.uml
    (Size: 1.18KB, Downloaded 552 times)
  • Attachment: StandardProfileL2.xmi
    (Size: 75.83KB, Downloaded 707 times)
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #899761 is a reply to message #896350] Thu, 02 August 2012 09:11 Go to previous messageGo to next message
Dario Imparato is currently offline Dario ImparatoFriend
Messages: 20
Registered: August 2012
Junior Member
Hello,
I have the same identical problem.
The code shared by Mauro is very similar to mine, if anyone has any idea about the cause of the problem, please write it.

Here the code of Mauro (if someone has problem to download it):
import java.io.IOException;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;
import org.eclipse.uml2.uml.resource.XMI212UMLResource;
import org.eclipse.uml2.uml.resources.util.UMLResourcesUtil;

/**
 * @author Mauro Faella
 *
 */
public class Test {
	static private ResourceSet RESOURCE_SET = new ResourceSetImpl();
	
	public static void main(String[] args) {
		
		UMLResourcesUtil.init(RESOURCE_SET);
		URI uriModel = URI.createFileURI("Test").appendFileExtension(UMLResource.FILE_EXTENSION);
		URI uriProf = URI.createFileURI("StandardProfileL2").appendFileExtension(XMI212UMLResource.FILE_EXTENSION);
		Resource umlModel = RESOURCE_SET.getResource(uriModel, true);
		Resource umlProfile = RESOURCE_SET.getResource(uriProf, true);
		//To avoid reference problem in uml file 
		umlProfile.setURI(URI.createFileURI(uriProf.segmentsList().get(uriProf.segmentCount()-1)));
		Model testModel = (Model) EcoreUtil.getObjectByType(umlModel.getContents()
				, UMLPackage.Literals.MODEL);
		Profile profModel = (Profile) EcoreUtil.getObjectByType(umlProfile.getContents()
				, UMLPackage.Literals.PROFILE);
		if (profModel.isDefined()){
			System.out.println("is Defined");
		}else{
			EPackage profileModel = (EPackage) EcoreUtil.getObjectByType(umlProfile.getContents()
					, EcorePackage.Literals.EPACKAGE);
			System.out.println("is Not Defined");
			profModel.createMetamodelReference((Package) profileModel);
			profModel.define();
		}
		testModel.applyProfile(profModel);
		System.out.println("applied: "+testModel.isProfileApplied(profModel));
		org.eclipse.uml2.uml.Package myPkg = (org.eclipse.uml2.uml.Package) testModel.getPackagedElement("myPkg");
		Element myClass = myPkg.getPackagedElement("Class1");
		try {
			umlModel.save(null);
			System.out.println("Saved");
		} catch (IOException e) {
			e.printStackTrace();
		}
		Stereotype stereotype = profModel.getOwnedStereotype("Type");
		myClass.applyStereotype(stereotype);
		try {
			umlModel.save(null);
		} catch (IOException e) {
			e.printStackTrace();
		}
	} 
}
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #990670 is a reply to message #899761] Thu, 13 December 2012 17:02 Go to previous messageGo to next message
Federico Toledo is currently offline Federico ToledoFriend
Messages: 97
Registered: April 2012
Location: Ciudad Real, Spain
Member
does somebody solved that?
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #990711 is a reply to message #899104] Thu, 13 December 2012 18:23 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
On 12-07-30 10:59 AM, Mauro Faella wrote:
> Hi all,
> I'm trying and trying but the problem is still here.
> I attach the java and uml files so you should test it about my issue. There are some jar to include into the build path and they can be found in plugins directory of eclipse (I'm using Juno edition).
> The profile used in this test is given by Eclipse plugin, and it returns the same exception that I get with a custom profile.
>
> Thanks in advance for every feedback
>

Which versions of EMF and UML2 are you using? Note that there are bugs
in support for using legacy profiles standalone which are only fixed in
most recent Juno SR2 build (e.g., for EMF 2.8.2 and UML2 4.0.2)...

Kenn
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #990712 is a reply to message #990670] Thu, 13 December 2012 18:30 Go to previous messageGo to next message
Kenn Hussey is currently offline Kenn HusseyFriend
Messages: 1620
Registered: July 2009
Senior Member
On 12-12-13 12:02 PM, Federico Toledo wrote:
> does somebody solved that?

Hmm, if I had to guess, the problem stems from using relative file URIs.
Unless you use absolute URIs, EMF will probably have a hard time
resolving references to things like the UML metamodel, etc..

Kenn
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #991105 is a reply to message #990670] Mon, 17 December 2012 11:38 Go to previous messageGo to next message
Dario Imparato is currently offline Dario ImparatoFriend
Messages: 20
Registered: August 2012
Junior Member
Dear all,
to solve the problem you have to initialize resourseSet without calling UMLResourcesUtil.init but with this code:
String JAR_FILE_ECLIPSE_UML2_UML_RESOURCES = "jar:file:C:/org.eclipse.uml2.uml.resources_4.0.1.v20120913-1441.jar!/";
File test = new File(JAR_FILE_ECLIPSE_UML2_UML_RESOURCES.substring(9,JAR_FILE_ECLIPSE_UML2_UML_RESOURCES.length()-2)).getAbsoluteFile();
if (!test.exists()){
                throw new NullPointerException("JAR_FILE_ECLIPSE_UML2_UML_RESOURCES PATH ERROR, "+test.toString()+"not found!");
}
_resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
_resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION,UMLResource.Factory.INSTANCE);
Map<URI, URI> _resourceSetURIMap = _resourceSet.getURIConverter().getURIMap();
URI uri = URI.createURI(JAR_FILE_ECLIPSE_UML2_UML_RESOURCES);
_resourceSetURIMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
_resourceSetURIMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
_resourceSetURIMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));

Obviously you have to modify String "C:/org.eclipse.uml2.uml.resources_4.0.1.v20120913-1441.jar" with the path of your org.eclipse.uml2.uml.resources.*.jar file.

Federico solved in this way, let me know if anyone has problems.
Thanks also to Mauro Faella that found the solution.
Dario Imparato
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #991106 is a reply to message #991105] Mon, 17 December 2012 11:42 Go to previous messageGo to next message
Federico Toledo is currently offline Federico ToledoFriend
Messages: 97
Registered: April 2012
Location: Ciudad Real, Spain
Member
As Dario said, I've solved with the code that he provided me.
I though that the code was equivalent to call UMLResourcesUtil.init ... but using this method didnt work


thank you both
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #1150244 is a reply to message #991106] Tue, 22 October 2013 16:41 Go to previous messageGo to next message
Kostas Triantafyllidis is currently offline Kostas TriantafyllidisFriend
Messages: 15
Registered: November 2012
Junior Member
Hello,

I am facing a similar problem. I want to apply the MARTE profile into a model. In the beginning i was facing the error that you mention above. Ever since i have followed your advice for the mapping of the profiles, i do not receive any exceptions. Now the applyStereotype seems to be executed but when i check the produced model, the OwnedOperations that should be applied with the new stereotype are empty(after saving to a model).
When i test whether the new stereotype is applied (before the save) it seems that it is, but when i save it, the new model does not include the new stereotypes. I have to mention that the MARTE profile is loaded with no errors. The MARTE profile is visible from the model.uml file by using Papyrus modeling tool.

In brief what i am doing is that i create a model, then apply to this model the MARTE profile. I add a class called "Gmapping" and fir this class i create 5 ownedOperations which should be applied with the stereotype "SaStep" from MARTE.


I am attaching two files in order to check if i am doing something wrong.
The output if the execution is:
Stereotype 'MARTE::MARTE_AnalysisModel::SAM::SaStep' applied to element 'model::Gmapping::Initialization'.
Stereotype 'MARTE::MARTE_AnalysisModel::SAM::SaStep' applied to element 'model::Gmapping::AddScanProcess'.
Stereotype 'MARTE::MARTE_AnalysisModel::SAM::SaStep' applied to element 'model::Gmapping::Conversions'.
Stereotype 'MARTE::MARTE_AnalysisModel::SAM::SaStep' applied to element 'model::Gmapping::UpdateMap'.
Stereotype 'MARTE::MARTE_AnalysisModel::SAM::SaStep' applied to element 'model::Gmapping::publish_odom_frame'.
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #1150584 is a reply to message #1150244] Tue, 22 October 2013 21:51 Go to previous messageGo to next message
Kostas Triantafyllidis is currently offline Kostas TriantafyllidisFriend
Messages: 15
Registered: November 2012
Junior Member
I have finally found the answer to my problem here:
http://www.eclipse.org/forums/index.php/t/496135/

It seems that in order to save the stereotypes it is needed to parse the model element by element.
Re: Applying stereotype to property as association end throws IllegalArgumentException [message #1152075 is a reply to message #1150584] Wed, 23 October 2013 20:08 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The thread you refer to seemed to diagnose the problem as failure to use
a Resource properly.

Nothing to do with parsing element by element.

Regards

Ed Willink

On 22/10/2013 22:51, Kostas Triantafyllidis wrote:
> I have finally found the answer to my problem here:
> http://www.eclipse.org/forums/index.php/t/496135/
>
> It seems that in order to save the stereotypes it is needed to parse
> the model element by element.
Previous Topic:Re: Multiple Inheritance
Next Topic:connectors
Goto Forum:
  


Current Time: Tue Apr 16 22:34:38 GMT 2024

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

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

Back to the top