Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [JET2] Iterating through the elements of an EList in an EMF model
[JET2] Iterating through the elements of an EList in an EMF model [message #56561] Thu, 29 January 2009 11:14 Go to next message
Youmm P. is currently offline Youmm P.Friend
Messages: 140
Registered: July 2009
Senior Member
Hello,


I've got an EClass with a method "EList<State> getValidStates()".
State is defined as "public enum State implements Enumerator".

I would like to iterate on the State contained in the EList in the JET
templates.

I tried this:

<c:iterate select="$element/validStates" var="validState">
<c:get select="$validState" />
</c:iterate>

but it doesn't work.

Is it possible to do what I'm trying to do?

Thanks in advance.
Re: [JET2] Iterating through the elements of an EList in an EMF model [message #56669 is a reply to message #56561] Thu, 29 January 2009 14:56 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Youmm:

JET's XPath engine uses EMFs reflective APIs. It only sees
EStructuralFeature implementations (EReferences and EAttributes). I
currently does not do reflection on the actual Java class for methods that
are not declared in the ECore model.

Is there an EReference or an EAttribute declaration of validSates ?

Paul

"Youmm P." <kototamo@gmail.com> wrote in message
news:gls2rt$mua$1@build.eclipse.org...
> Hello,
>
>
> I've got an EClass with a method "EList<State> getValidStates()".
> State is defined as "public enum State implements Enumerator".
>
> I would like to iterate on the State contained in the EList in the JET
> templates.
>
> I tried this:
>
> <c:iterate select="$element/validStates" var="validState">
> <c:get select="$validState" />
> </c:iterate>
>
> but it doesn't work.
>
> Is it possible to do what I'm trying to do?
>
> Thanks in advance.
Re: [JET2] Iterating through the elements of an EList in an EMF model [message #56696 is a reply to message #56669] Thu, 29 January 2009 15:28 Go to previous messageGo to next message
Youmm P. is currently offline Youmm P.Friend
Messages: 140
Registered: July 2009
Senior Member
> Is there an EReference or an EAttribute declaration of validSates ?
No, the EList values are dynamically created by the getValidStates function.
Re: [JET2] Iterating through the elements of an EList in an EMF model [message #56722 is a reply to message #56696] Fri, 30 January 2009 14:16 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Youmm:

I think your best choice is to drop into Java code...

a) Make sure your JET project has a dependency on the plug-in defining the
Ecore model. (Open plugin.xml or META-INF/MANIFEST.MF, and go to the
Dependencies tab)

b) Add imports for the classes your template was to access

<%-- import the classes you'll need --%>
<%@jet import="a.b.c.YourElement a.b.c.State" %>
<%@jet import="org.eclipse.jet.XPathContextExtender" %>

c) get the JET variable as a Java variable. Assuming $element is the JET
variable containing EObject:

<%
YourElement element =
(YourElement)XPathContext.getInstance(context).resolveAsObje ct(null, "$element");
%>

d) Write the Java scriptlet

<% for(State state : element.getValidStates() ) { %>
.... template content <%= state.toString %>
<% } %>

Paul

"Youmm P." <kototamo@gmail.com> wrote in message
news:glshpg$vqi$1@build.eclipse.org...
>> Is there an EReference or an EAttribute declaration of validSates ?
> No, the EList values are dynamically created by the getValidStates
> function.
Previous Topic:Re: JET1 Editor for EMF Codegen template extensions
Next Topic:JET2 merging of model data with existing Java code
Goto Forum:
  


Current Time: Fri Sep 20 02:24:03 GMT 2024

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

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

Back to the top