Retour / Return

This forum is now read-only. If you have any questions about Acceleo, please refer now to: http://wiki.eclipse.org/Acceleo/Forums

For the French Acceleo community, a forum is available on the Obeo Network


Problems / Bugs :  Acceleo Forum
Bugs reports 
Goto Thread: PreviousNext
Goto:  Forum ListMessage ListSearch
Calling Scripts
Posted by: Stefan.Haack (IP Logged)
Date: July 23, 2007 09:24PM

Hello Acceleo Team !

I have a Problem what confuses me a bit. I don`t know if i choose the wrong
approach to solve this problem or there is a simple solution and i don't see
it. For each class with the Stereotype "FORM" i have a Activity Diagram. For
each State/"CallOperation" in the Activity Diagram i would like to generate a
Method in the Output File. Fore each State/"CallOperation" i need also to know the next
State/"CallOperation". But inside the Iteration of the States i can not call
the script "getControlflowTargetName". How to solve this ?

Ideas or Hints are welcome,

Thank you

Stefan H.


<%
metamodel [www.eclipse.org]
import org.acceleo.modules.uml2.services.Uml2Services
import org.acceleo.modules.uml2.services.StringServices
%>
<%script type="Class" name="fullFilePath"%>
<%if (hasStereotype("FORM")){%>
<%name.toU1Case()%>Control.php
<%}%>
<%script type="Class" name="genControl" file="<%fullFilePath%>"%>

class <%name.toU1Case()%>Control

Name of the Activity : "<%getDefaultActivityName(name)%>
Default, First Activity : "<%getActivityName(name)%>",
array (
<%genActions(name)%>
)
<%--

get the model root container, get all CallOperations from the
activity Diagram which belongs to the Form args(0)
Todo :
- set automaticly the next activity by "Control Flow" Element
--%>
<%script type="Class" name="genActions"%>
<%for (getRootContainer()
.eAllContents("CallOperationAction")
.select("context.name", args(0))){%>
Name : <%name%>
Name of Outgoing Workflow :<%outgoing.name%>
<%--

PROBLEM:
Why i cant call it here ?

Next Activity : <%getControlflowTargetName(outgoing.name)%>
--%>
<%}%>
<%--
return : returns the "name" of the activity diagram from the form/class "args(0)"
--%>
<%script type="Class" name="getActivityName"%>
<%for (getRootContainer().eAllContents("uml.Activity").select("context.name", args(0))) {%>
<%name%><%}%>
<%--
return : return the name of the controlflow element where the initial nodes points
--%>
<%script type="Class" name="getDefaultActivityName" post="trim()"%>
<%getControlflowTargetName(getInitialNode( getActivityName( args(0) ) ) )%>
<%--
returns : returns from the "initialnode" element with "owner.name" == "args(0)" the
"outgoing.name"
--%>
<%script type="Class" name="getInitialNode"%>
<%for (getRootContainer().eAllContents("InitialNode").select("owner.name", args(0))) {%>
<%outgoing.name%><%}%>
<%--
returns : returns from the "controlflow" element with name == args(0) the "target.name"
--%>
<%script type="Class" name="getControlflowTargetName"%>
<%for (getRootContainer().eAllContents("ControlFlow").select("name", args(0))) {%>
<%target.name%><%}%>

Re: Calling Scripts
Posted by: pweber (IP Logged)
Date: July 24, 2007 08:50AM

Hi,

the explication to your problem is that you are in a for.
So in this for, Acceleo search for a getControlflowTargetName script that apply to a CallOperationAction and can't find it.

To call the script on the class, you have to launch it on the class.
Try something like <%current(1).getControlflowTargetName%>

Or define your getControlflowTargetName on a more generic type like Element

Good luck

Re: Calling Scripts
Posted by: Stefan.Haack (IP Logged)
Date: July 25, 2007 12:12AM

Hello pweber,

Thank you, current(1). works ! I can not decide when to write a Service or when to user Scripts...

Stefan H.

Re: Calling Scripts
Posted by: slacrampe (IP Logged)
Date: July 25, 2007 06:52AM

Hi,

I understand that the choice may not be always simple, but I think that I can say that the rule is quite simple : write as few services as possible !
Basically, Acceleo has been designed to keep templates as simple as possible to read, understand and maintain. Services are there to do things that you can't do within scripts using the basic Acceleo syntax (model navigation, if, for...). So if you can't do something using scripts, then you might need a service, other wise just make a script.
Another thing is that when you do a script and use scripts, you get completion, error detection, etc... whereas this is not the case with services.
For example, you do not get completion after your <%current(1)%>... because Acceleo can't guess the type of the object returned by <%current(1)%>. BTW, there is a workaround in this specific case, if you know the type of the object you want to get to, you can pass this parameter to the current service, something like <%current("Class")%> in your case will work the same way as the current("1") but you will still get error detection and completion after the current.

Please refer to the reference manual for a complete list of available services with Acceleo.

Stephane



Edited 1 time(s). Last edit at 07/25/2007 06:53AM by slacrampe.



This forum is read only now. You can post your acceleo questions on Eclipse Acceleo forum : http://wiki.eclipse.org/Acceleo/Forums
Webdesign : www.katrinet.com - Realisation : Obeo