Using getValue(Stereotype, String) with Collections [message #647310] |
Wed, 05 January 2011 11:13  |
Eclipse User |
|
|
|
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 #647444 is a reply to message #647334] |
Thu, 06 January 2011 07:24  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03898 seconds