Using getValue(Stereotype, String) with Collections [message #647310] |
Wed, 05 January 2011 16: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 #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 #647334 is a reply to message #647321] |
Wed, 05 January 2011 16:49   |
Eclipse User |
|
|
|
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  |
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.02726 seconds