Using getValue(Stereotype, String) with Collections [message #647310] |
Wed, 05 January 2011 16:13 |
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 |
|
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 #647444 is a reply to message #647334] |
Thu, 06 January 2011 12:24 |
|
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.03045 seconds