Applying Stereotypes programatically returns IllegalArgumentException [message #505852] |
Tue, 05 January 2010 11:17 |
Stefan Messages: 13 Registered: October 2009 |
Junior Member |
|
|
Hi,
i am trying to apply a stereotype to a model element programatically, every time i do this an IllegalArgumentException is thrown by ElementOperations.applyStereotypes. My project setup is done according to the tutorial for standalone Projects mentioned here several times.
Here the Profile is loaded and the new model is created.
URI annotationProfileFile = URI.createURI("file:/Users/schegi/Documents/Diplomarbeit/Eclipse/sandbox/UML-Test/MetaModels/Anntation.profile.uml");
UMLResource annotationProfileResource = (UMLResource)resourceSet.getResource(annotationProfileFile, true);
URI ontologyAPIModelFile = URI.createURI("file:/Users/schegi/Documents/Diplomarbeit/Eclipse/sandbox/UML-Test/Models/Ontology-API.uml");
UMLResource ontologyAPIModelResource = (UMLResource)resourceSet.createResource(ontologyAPIModelFile);
I can apply the Profile to the model itself and newly created Packages in the model. And if i performe getAppliedProfiles i can see that the Profile is applied correctly.
If i performe a element.getApplicableStereotypes the returned list is empty, every time.
Setting breakpoints in the ElementOperations.applyStereotypes point me to ElementOperations.getExtension.
I can enter the if (type instanceof org.eclipse.uml2.uml.Class)
It seems that the eClassifier is null. What does that mean? I will check this.
Ok here some additional Information:
The base_Class Property of the Profile is of type uml::Class, but it seams that in the UMLUtil.getEClassifier(Type type) the line
org.eclipse.uml2.uml.Package package_ = type.getNearestPackage(); package_ is null. and so the eClassifier is null and so the Extension is null and so the Exception is thrown.
Ok now i know why, but why is the NearestPackage of uml::Class null?
Now I think it must have something to do with the Standalone setup, because in the Pluginenvironment (UMLEditor) it seams to work.
The other strange think is that if i outcomment the stereotype application and save the model. I am able to apply stereotypes by hand if i open the model in an uml view. As long as i can say it has nothing to do with the Profile.
Thx for help
Stefan
[Updated on: Tue, 05 January 2010 13:28] Report message to a moderator
|
|
|
|
Re: Applying Stereotypes programatically returns IllegalArgumentException [message #505945 is a reply to message #505852] |
Tue, 05 January 2010 15:40 |
Stefan Messages: 13 Registered: October 2009 |
Junior Member |
|
|
Hi,
I am working on an standalone application, in an plugin environment all works well. For Example when i skip the programatical Stereotype application and open the generated Model in the Eclipse UML Model Editor i can apply the stereotype without any additional work.
Here is my standalone setup:
final String UML2_200_NS_URI = "http://www.eclipse.org/uml2/2.0.0/UML";
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
resourceSet.getPackageRegistry().put(UMLPackage.eCONTENT_TYPE, UMLPackage.eINSTANCE);
resourceSet.getPackageRegistry().put(UMLPackage.eNAME, UMLPackage.eINSTANCE);
resourceSet.getPackageRegistry().put(UMLPackage.eNS_PREFIX, UMLPackage.eINSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
EPackage.Registry.INSTANCE.put(UML2_200_NS_URI,EPackage.Registry.INSTANCE.get(UMLPackage.eINSTANCE.getNsURI()));
Ecore2XMLPackage.eINSTANCE.getEClassifiers();
Map uriMap = resourceSet.getURIConverter().getURIMap();
URI uri = URI.createURI("jar:file:/C:/eclipse/plugins/org.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar!/");
uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));
And here is the Profile:
<?xml version="1.0" encoding="UTF-8"?>
<uml:Profile xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmi:id="_sgoFIPRsEd6r3-nGxzDfug" name="Annotation" metaclassReference="_DGU0wPRvEd6-do6LdBmvGQ _DGU0wfRvEd6-do6LdBmvGQ _DGU0wvRvEd6-do6LdBmvGQ">
<eAnnotations xmi:id="_mtIVIPRvEd6-do6LdBmvGQ" source="http://www.eclipse.org/uml2/2.0.0/UML">
<contents xmi:type="ecore:EPackage" xmi:id="_mtI8MPRvEd6-do6LdBmvGQ" name="Annotation" nsURI="http:///schemas/Annotation/_mtEqwPRvEd6-do6LdBmvGQ/0" nsPrefix="Annotation">
<eClassifiers xmi:type="ecore:EClass" xmi:id="_mtI8MfRvEd6-do6LdBmvGQ" name="_winter">
<eAnnotations xmi:id="_mtI8MvRvEd6-do6LdBmvGQ" source="http://www.eclipse.org/uml2/2.0.0/UML" references="_M1n2gPRtEd6-do6LdBmvGQ"/>
<eStructuralFeatures xmi:type="ecore:EAttribute" xmi:id="_mtI8M_RvEd6-do6LdBmvGQ" name="query" ordered="false" lowerBound="1">
<eType xmi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eStructuralFeatures>
<eStructuralFeatures xmi:type="ecore:EAttribute" xmi:id="_mtI8NfRvEd6-do6LdBmvGQ" name="var" ordered="false" lowerBound="1">
<eType xmi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eStructuralFeatures>
<eStructuralFeatures xmi:type="ecore:EAttribute" xmi:id="_mtI8N_RvEd6-do6LdBmvGQ" name="src" ordered="false" upperBound="-1">
<eType xmi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eStructuralFeatures>
<eStructuralFeatures xmi:type="ecore:EAttribute" xmi:id="_mtI8OfRvEd6-do6LdBmvGQ" name="dst" ordered="false" upperBound="-1">
<eType xmi:type="ecore:EDataType" href="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eStructuralFeatures>
<eStructuralFeatures xmi:type="ecore:EAttribute" xmi:id="_mtI8O_RvEd6-do6LdBmvGQ" name="type" ordered="false" lowerBound="1" eType="_mtI8Q_RvEd6-do6LdBmvGQ"/>
<eStructuralFeatures xmi:type="ecore:EReference" xmi:id="_mtI8PfRvEd6-do6LdBmvGQ" name="base_Class" ordered="false" lowerBound="1">
<eType xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/3.0.0/UML#//Class"/>
</eStructuralFeatures>
<eStructuralFeatures xmi:type="ecore:EReference" xmi:id="_mtI8P_RvEd6-do6LdBmvGQ" name="base_Interface" ordered="false" lowerBound="1">
<eType xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/3.0.0/UML#//Interface"/>
</eStructuralFeatures>
<eStructuralFeatures xmi:type="ecore:EReference" xmi:id="_mtI8QfRvEd6-do6LdBmvGQ" name="base_Property" ordered="false" lowerBound="1">
<eType xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/3.0.0/UML#//Property"/>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xmi:type="ecore:EEnum" xmi:id="_mtI8Q_RvEd6-do6LdBmvGQ" name="Type">
<eAnnotations xmi:id="_mtI8RPRvEd6-do6LdBmvGQ" source="http://www.eclipse.org/uml2/2.0.0/UML" references="_RR70UPRuEd6-do6LdBmvGQ"/>
<eLiterals xmi:id="_mtI8RfRvEd6-do6LdBmvGQ" name="PATTERN"/>
<eLiterals xmi:id="_mtI8RvRvEd6-do6LdBmvGQ" name="MAPPING" value="1"/>
<eLiterals xmi:id="_mtI8R_RvEd6-do6LdBmvGQ" name="EXTERNALOBJECT" value="2"/>
<eLiterals xmi:id="_mtI8SPRvEd6-do6LdBmvGQ" name="INTERNALOBJECT" value="3"/>
<eLiterals xmi:id="_mtI8SfRvEd6-do6LdBmvGQ" name="LITERAL" value="4"/>
</eClassifiers>
</contents>
</eAnnotations>
<elementImport xmi:id="_DGU0wPRvEd6-do6LdBmvGQ">
<importedElement xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Class"/>
</elementImport>
<elementImport xmi:id="_DGU0wfRvEd6-do6LdBmvGQ">
<importedElement xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Interface"/>
</elementImport>
<elementImport xmi:id="_DGU0wvRvEd6-do6LdBmvGQ">
<importedElement xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Property"/>
</elementImport>
<packagedElement xmi:type="uml:Stereotype" xmi:id="_M1n2gPRtEd6-do6LdBmvGQ" name="@winter">
<ownedAttribute xmi:id="_Q2qqEPRtEd6-do6LdBmvGQ" name="query">
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
</ownedAttribute>
<ownedAttribute xmi:id="_SoU08PRtEd6-do6LdBmvGQ" name="var">
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
</ownedAttribute>
<ownedAttribute xmi:id="_TnM4APRtEd6-do6LdBmvGQ" name="src">
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_p3r3gPRtEd6-do6LdBmvGQ" value="*"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_pJps0PRtEd6-do6LdBmvGQ"/>
</ownedAttribute>
<ownedAttribute xmi:id="_UkXq4PRtEd6-do6LdBmvGQ" name="dst">
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_sUFogPRtEd6-do6LdBmvGQ" value="*"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_rhj_YPRtEd6-do6LdBmvGQ"/>
</ownedAttribute>
<ownedAttribute xmi:id="_Vd568PRtEd6-do6LdBmvGQ" name="type" type="_RR70UPRuEd6-do6LdBmvGQ"/>
<ownedAttribute xmi:id="_RmSeQfRvEd6-do6LdBmvGQ" name="base_Class" association="_RmR3MPRvEd6-do6LdBmvGQ">
<type xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Class"/>
</ownedAttribute>
<ownedAttribute xmi:id="_RmSeRPRvEd6-do6LdBmvGQ" name="base_Interface" association="_RmSeQvRvEd6-do6LdBmvGQ">
<type xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Interface"/>
</ownedAttribute>
<ownedAttribute xmi:id="_RmTFUfRvEd6-do6LdBmvGQ" name="base_Property" association="_RmSeRfRvEd6-do6LdBmvGQ">
<type xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Property"/>
</ownedAttribute>
</packagedElement>
<packagedElement xmi:type="uml:Enumeration" xmi:id="_RR70UPRuEd6-do6LdBmvGQ" name="Type">
<ownedLiteral xmi:id="_TXRJIPRuEd6-do6LdBmvGQ" name="PATTERN"/>
<ownedLiteral xmi:id="_US8HMPRuEd6-do6LdBmvGQ" name="MAPPING"/>
<ownedLiteral xmi:id="_U_jVkPRuEd6-do6LdBmvGQ" name="EXTERNALOBJECT"/>
<ownedLiteral xmi:id="_VwXugPRuEd6-do6LdBmvGQ" name="INTERNALOBJECT"/>
<ownedLiteral xmi:id="_WY8xcPRuEd6-do6LdBmvGQ" name="LITERAL"/>
</packagedElement>
<packagedElement xmi:type="uml:Extension" xmi:id="_RmR3MPRvEd6-do6LdBmvGQ" name="Class_@winter" memberEnd="_RmSeQPRvEd6-do6LdBmvGQ _RmSeQfRvEd6-do6LdBmvGQ">
<ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="_RmSeQPRvEd6-do6LdBmvGQ" name="extension_@winter" type="_M1n2gPRtEd6-do6LdBmvGQ" aggregation="composite" association="_RmR3MPRvEd6-do6LdBmvGQ"/>
</packagedElement>
<packagedElement xmi:type="uml:Extension" xmi:id="_RmSeQvRvEd6-do6LdBmvGQ" name="Interface_@winter" memberEnd="_RmSeQ_RvEd6-do6LdBmvGQ _RmSeRPRvEd6-do6LdBmvGQ">
<ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="_RmSeQ_RvEd6-do6LdBmvGQ" name="extension_@winter" type="_M1n2gPRtEd6-do6LdBmvGQ" aggregation="composite" association="_RmSeQvRvEd6-do6LdBmvGQ"/>
</packagedElement>
<packagedElement xmi:type="uml:Extension" xmi:id="_RmSeRfRvEd6-do6LdBmvGQ" name="Property_@winter" memberEnd="_RmTFUPRvEd6-do6LdBmvGQ _RmTFUfRvEd6-do6LdBmvGQ">
<ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="_RmTFUPRvEd6-do6LdBmvGQ" name="extension_@winter" type="_M1n2gPRtEd6-do6LdBmvGQ" aggregation="composite" association="_RmSeRfRvEd6-do6LdBmvGQ"/>
</packagedElement>
</uml:Profile>
Sry the Profile was a little bit long, it happens that performing define() on an already defined Profile duplicates the ecore expressions in the .profile.uml file.
Thx for your work, hope you could help.
Stefan
[Updated on: Wed, 06 January 2010 15:52] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03265 seconds