Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Using getValue(Stereotype, String) with Collections
Using getValue(Stereotype, String) with Collections [message #647310] Wed, 05 January 2011 16:13 Go to next message
Fred Sigems is currently offline Fred Sigems
Messages: 2
Registered: January 2011
Junior Member
Hi
I created a Java class with method :

public List<Object> getTaggedValue(Element element, String
stereotypeName, String property) {
Stereotype stereotype = getStereotype(element, stereotypeName);
System.out.println("stereotype : "+ stereotype.getName());
System.out.println("stereotype attribute : "+ property);
List<Object> result = new ArrayList<Object>();
Object value = element.getValue(stereotype, property);
if (value instanceof Collection)
result.addAll((Collection)value);
else
result.add(value);
return result;
}

I also created the follwing query

[query public getTaggedValue(element : Element, stereotype : String ,property :String ) : Sequence(OclAny) = invoke('fr.sigems.pim.uml2.gen.sigemsjavadao.services.Classe sService','getTaggedValue(org.eclipse.uml2.uml.Element, java.lang.String, java.lang.String)', Sequence{element,stereotype, property})/]

My template tries to get values of the collection

[for (c1: OclAnyc.getTaggedValue('entity','tables')->asSequence())]
[c1.oclAsType(Class).name/]
[/for]

Unfortunately, the following exception occurs when launching my code generation:

Invalid type for iteration at line 0 in Module generateCompositeDao for block for (getTaggedValue(c,'entity','tables')). org.eclipse.emf.ecore.impl.DynamicEObjectImpl was not an instanceof OclAny.

do you have a way to solve this problem?

Thanks in advance





Re: Using getValue(Stereotype, String) with Collections [message #647321 is a reply to message #647310] Wed, 05 January 2011 16:25 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,

This "org.eclipse.emf.ecore.impl.DynamicEObjectImpl" indicates that you have an invalid result somewhere it could be because the result of your query was null in Java. You can try to execute juste your query in a template to see if the result is still invalid or you can paste here the stack trace from your error log.

Stephane Begaudeau, Obeo



Re: Using getValue(Stereotype, String) with Collections [message #647334 is a reply to message #647321] Wed, 05 January 2011 16:49 Go to previous messageGo to next message
Fred Sigems is currently offline Fred Sigems
Messages: 2
Registered: January 2011
Junior Member
I just added a line in my java code to be sure that my UML model has a UML Class with 'table' stereotype.
This stereotype has a tagged value which refecences a collection of UML Classes


public List<Object> getTaggedValue(Element element, String
stereotypeName, String property) {
Stereotype stereotype = getStereotype(element, stereotypeName);
System.out.println("class : "+ ((NamedElement) element).getName());
System.out.println("stereotype : "+ stereotype.getName());
System.out.println("stereotype attribute : "+ property);

List<Object> result = new ArrayList<Object>();
Object value = element.getValue(stereotype, property);
if (value instanceof Collection){
System.out.println("value is instance of Collection");
result.addAll((Collection)value);
}
else
result.add(value);
return result;
}

please find here a track

stereotype : entity
stereotype attribute : tables
value is instance of Collection
org.eclipse.acceleo.engine.AcceleoEvaluationException: Invalid type for iteration at line 0 in Module generateCompositeDao for block for (getTaggedValue(c,'entity','tables')). org.eclipse.emf.ecore.impl.DynamicEObjectImpl was not an instanceof OclAny.
at generateCompositeDao.generateDao(Class)(generateCompositeDao .mtl:0)
at generateCompositeDao.generateDao(Class)(generateCompositeDao .mtl:0)
at generateCompositeDao.generateDao(Class)(generateCompositeDao .mtl:0)
at generate.generate(Class)(generate.mtl:0)
at generate.generate(Class)(generate.mtl:0)

It seems that the collection is not empty


Re: Using getValue(Stereotype, String) with Collections [message #647444 is a reply to message #647334] Thu, 06 January 2011 12:24 Go to previous message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
Hi fred,

The problem you encounter
org.eclipse.acceleo.engine.AcceleoEvaluationException: Invalid type for iteration at line 0 in Module generateCompositeDao for block for (getTaggedValue(c,'entity','tables')). org.eclipse.emf.ecore.impl.DynamicEObjectImpl was not an instanceof OclAny.

comes from the line :
[for (c1: OclAnyc.getTaggedValue('entity','tables')->asSequence())] 

Specifically, the Sequence your iterate on contains a value of type "DynamicEObjectImpl", which I assume to be the OCL "invalid" value. To put it another way, you have the same issue as what this would yield :
[for (o : OclAny | invalid->asSequence())]


Could you print the content of your Sequence from Acceleo to see which values it contains?
c.getTaggedValue('entity','tables')

should do the trick. (you can also try not to type your for loop :
[for (c.getTaggedValue('entity','tables'))]
[oclAsType(Class).name/]
[/for]


Laurent Goubet
Obeo
Previous Topic:[Acceleo 3] getting All classes from Papyrus Model
Next Topic:[MWE2,XPAND] Loading workflow in OSGi w/o workspace
Goto Forum:
  


Current Time: Sat Sep 20 01:56:13 GMT 2014

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

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