Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [ACCELEO 3] Retrieving the class from a stereotype
[ACCELEO 3] Retrieving the class from a stereotype [message #725736] Thu, 15 September 2011 16:12 Go to next message
bkhamphousone is currently offline bkhamphousone
Messages: 4
Registered: September 2011
Junior Member
Hi everybody.

I'm facing a problem and I can't find the solution.

Actually, we've got a UML2 Model as source of the generation. Everything works fine until I've to generate something awkward but very useful in my opinion.

There's a Stereotype (IHMMethod) which contains a property name bean. This property has to be a type of another Stereotype which name is DTO.

The stereotype DTO is applied to some classes and the stereotype IHMMethod is applied to Operation type. So we've got this :

Operation <<IHMMethod>> <-- bean <<DTO>> <-- every class stereotyped with DTO

When I access to an Operation type and when this last one got the stereotype IHMMethod, I retrieve the bean property. Unfortunately, it is an eClass and not an Element. So I'm not able to get the class contains in the bean property.

This works fine in Acceleo 2 but not in 3. Maybe it's a bug or maybe the way to get it changed.

Does someone got an idea of how to retrieve it?

Thank you very much.

Edit :

Here is the code to retrieve the object. Furthermore I've made a mistake : it's a DynamicEObjectImpl instead of EClass. I can retrieve the eClass with obj.eClass() but I don't know how to get the class set in the stereotype value.

public class testServices {
public String getBeanIHMMethodService(Operation anOperation) {
String result = null;
if (anOperation != null) {
try {
Stereotype st = anOperation
.getAppliedStereotype("myprofile::IHM Method");
if (st == null) {
result = "st null";
} else {
DynamicEObjectImpl obj = (DynamicEObjectImpl) anOperation.getValue(st, "bean");
if(obj != null){
result = obj.toString();

}else{
result = "nulllqsdaaa";
}
}
} catch (Exception e) {
result = e.toString();
}
} else {
result = "nullaaa";
}
return result;
}
}

I think it's uml2's bug but I'm not sure of it.

[Updated on: Fri, 16 September 2011 07:19]

Report message to a moderator

Re: [ACCELEO 3] Retrieving the class from a stereotype [message #726786 is a reply to message #725736] Mon, 19 September 2011 14:57 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane Begaudeau
Messages: 406
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

If you have a "DynamicEObjectImpl", you should have a closer look at its name because 99.99999999% of the time it is an OCL_Invalid which is "null" for OCL. I am not familiar with your profile but this "anOperation.getValue(st, "bean")" returns null in your case.

You could place a breakpoint in the "initialize" method of the entry point of the generator and launch your generation to see the content of the model loaded and see if your profile is correctly taken into account.

Regards,

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau
Google+: stephane.begaudeau
Blog: http://stephanebegaudeau.tumblr.com
Acceleo Documentation: http://docs.obeonetwork.com/acceleo



Re: [ACCELEO 3] Retrieving the class from a stereotype [message #728080 is a reply to message #726786] Thu, 22 September 2011 13:58 Go to previous messageGo to next message
bkhamphousone is currently offline bkhamphousone
Messages: 4
Registered: September 2011
Junior Member
Hi,

First of all, thanks for replying.

Unfortunately, what you said is wrong. If I change the bean's type to Class, it would works fine. We had typed it to DTO because it limit the choice more than Class.

I guess it's an issue from EMF or UML2 but I'm not sure of it.

Any other idea will be welcomed Smile

Thank you.
Re: [ACCELEO 3] Retrieving the class from a stereotype [message #728116 is a reply to message #726786] Thu, 22 September 2011 14:54 Go to previous messageGo to next message
bkhamphousone is currently offline bkhamphousone
Messages: 4
Registered: September 2011
Junior Member
Here is what I've got :

MTL file :
[**
 * Return TRUE if an element has the stereotype aQualifiedStereotypeName. FALSE otherwise.
 * @param anElement
 * @param aQualifiedStereotypeName
 */]
[query public hasStereotype(anElement : Element, aQualifiedStereotypeName : String) : Boolean =
	not anElement.getAppliedStereotype(aQualifiedStereotypeName).oclIsUndefined()
/]

[**
 * Return the value of a stereotype.
 * @param anElement
 * @param aQualifiedStereotypeName
 * @param anAttributeName 
 */]
[query public getStereotypeValue(anElement : Element, aQualifiedStereotypeName : String, anAttributeName : String) : OclAny =
	anElement.getValue(anElement.getAppliedStereotype(aQualifiedStereotypeName), anAttributeName)
/]

[template public test(aClass : Class)]
[comment @main/]
[if (aClass.hasStereotype('myProfile::stereotypePere'))]
[file (aClass.name, false, 'UTF-8')]
[aClass.getStereotypeValue('myProfile::stereotypePere', 'fils')/]
[/file]
[/if]
[/template]


With the uml2 export withoutStereotype, I've got as result :
org.eclipse.uml2.uml.internal.impl.ClassImpl@1ebb51b (name: uneClasse, visibility: <unset>) (isLeaf: false, isAbstract: false) (isActive: false)

With the uml2 export withStereotype, I've got as result :
org.eclipse.emf.ecore.impl.DynamicEObjectImpl@49a1c5 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@1fe3aa4 (name: stereotypeFils) (instanceClassName: null) (abstract: false, interface: false))

The only difference between those two is the type of stereotypePere's attribute fils.

withoutStereotype and withStereotype are attached to the post.

The difference is this :
<eStructuralFeatures xmi:type="ecore:EReference" xmi:id="_hzut2eUpEeCCEKmxfMl80Q" name="fils" ordered="false" lowerBound="1">
          <eType xmi:type="ecore:EClass" href="h t t p://www.eclipse.org/uml2/3.0.0/UML#//Class"/>
        </eStructuralFeatures>



<eStructuralFeatures xmi:type="ecore:EReference" xmi:id="_dOK3-eUpEeCCEKmxfMl80Q" name="fils" ordered="false" lowerBound="1" eType="_dOK3--UpEeCCEKmxfMl80Q"/>



As we can see, the eStructuralFeatures know that the object is a Class but how can I get the eStructuralFeatures as a Class instead of DynamicObject?

[Updated on: Thu, 22 September 2011 15:29]

Report message to a moderator

Re: [ACCELEO 3] Retrieving the class from a stereotype [message #728145 is a reply to message #728116] Thu, 22 September 2011 15:46 Go to previous messageGo to next message
bkhamphousone is currently offline bkhamphousone
Messages: 4
Registered: September 2011
Junior Member
I've found the way to get the object. We've got to get call the eCrossReferences to get it.

Thanks Smile
Re: [ACCELEO 3] Retrieving the class from a stereotype [message #729439 is a reply to message #728145] Mon, 26 September 2011 08:02 Go to previous message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1627
Registered: July 2009
Senior Member
Glad you've found a working solution.

The problem here seems to be that your "stereotypeFils" is defined in a model which metamodel is located somewhere in the workspace. "DynamicEObject" are things we usually see when using "create dynamic instance" from an ecore editor. The "Element.getValue()" method is the only way I know of retrieving a stereotype value, and I have no idea as to how to call that method on a dynamic EObject.

Laurent Goubet
Obeo
Previous Topic:[acceleo] how to return a List (or array or whatever) from an query
Next Topic:[acceleo 3.1] editor doesn't see inheritance
Goto Forum:
  


Current Time: Tue Sep 30 11:55:01 GMT 2014

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

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