Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo 3] ServiceWrapper Problem during generation
[Acceleo 3] ServiceWrapper Problem during generation [message #653196] Tue, 08 February 2011 20:15 Go to next message
dieppi is currently offline dieppiFriend
Messages: 27
Registered: November 2010
Junior Member
Hi,

i use acceleo 3.0.1. There is a strange behavoir during the generation process.

Considering the following scenario:

I created a java service wrapper with a method that fills a list. The list as an attribute of the service wrapper class. In the constructor i create an instance of these list.

Example:
--------------

private Set<Element> systemStates = null;

public ListServices() {
if(this.systemStates == null) {
this.systemStates = new LinkedHashSet<Element>();
}
}

So now i create a method that put state elements in this list. In my template i call the method for state elements. But if i call these template in two times in my generation process only one instance from my serviceclass exists and the list is filled with all values from the first call. I would expect that for every call of my template a new instance of the servicewrapper class will be created.

Best regards
Maik



[Updated on: Tue, 08 February 2011 20:34]

Report message to a moderator

Re: [Acceleo] [message #653280 is a reply to message #653196] Wed, 09 February 2011 08:03 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010204080600030400070602
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Maik,

The service classes are only instantiated when we need to (thus not for
static method calls or when we are passed an instance of the class to
call the method on), and only once if we ever do.

If you do want the "systemStates" Set to be cleared, you'll have to do
it before calling methods on this service wrapper.

Laurent Goubet
Obeo

On 08/02/2011 21:16, Maik wrote:
> Hi,
>
> i use acceleo 3.0.1. There is a strange behavoir during the generation
> process.
>
> Considering the following scenario:
>
> I created a java service wrapper with a method that fills a list. The
> list as an attribute of the service wrapper class. In the constructor i
> create an instance of these list.
>
> Example:
> --------------
>
> private Set<Element> systemStates = null;
>
> public ListServices() {
> if(this.systemStates == null) {
> this.systemStates = new LinkedHashSet<Element>();
> }
> }
>
> So now i create a method that put state elements in this list. In my
> template i call the method for state elements. But if i call these
> template in two times in my generation process only one instance from my
> serviceclass exists and the list is filled with all values from the
> first call. I would expect that for every call of my template a new
> instance of the servicewrapper class will be created.
> Best regards
> Maik
>
>
>


--------------010204080600030400070602
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------010204080600030400070602--
Re: [Acceleo] [message #653559 is a reply to message #653280] Thu, 10 February 2011 09:26 Go to previous messageGo to next message
dieppi is currently offline dieppiFriend
Messages: 27
Registered: November 2010
Junior Member
Hi Laurent,

thanks for your answer. Could you give me the class name from accleo who handle this service wrapper generation? I would look into the source code.

Is this java file

org.eclipse.acceleo.common/src/org/eclipse/acceleo/common/Ac celeoServicesRegistry.java??

Best regards
Maik

[Updated on: Thu, 10 February 2011 10:26]

Report message to a moderator

Re: [Acceleo] [message #653609 is a reply to message #653559] Thu, 10 February 2011 11:56 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020100050909070709020106
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Maik,

The services in Acceleo 3 are stateful : their variables won't be reset
between two invocations. This behavior is a design choice we made, thus
we won't change it even if someone were to provide us with a patch.

If you truly wish to do with a forked version of Acceleo, you can take a
look at the implementations of
AcceleoServicesRegisty#getServiceInstance (in charge of instantiating
services in standalone)
and
AcceleoWorkspaceUtil#getServiceInstance (in charge of instantiating
services when within Eclipse)

Laurent Goubet
Obeo

On 10/02/2011 10:26, Maik wrote:
> Hi Laurent,
>
> thanks for your answer. Could you give me the class name from accleo who
> handle this service wrapper generation? I would look into the source code.
>
> Best regards
> Maik


--------------020100050909070709020106
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------020100050909070709020106--
Re: [Acceleo] [message #656995 is a reply to message #653609] Tue, 01 March 2011 10:11 Go to previous messageGo to next message
dieppi is currently offline dieppiFriend
Messages: 27
Registered: November 2010
Junior Member
Hi Laurent,

thanks for your answers. I'am a big fan of the whole acceleo project. Maybe we can find a solution for both of us and the community.
Would it be possible from your side to implement a property (true|false or new kind of generation in doGenerate() methode) where the user can decide in the generation class, if a service will be use as singleton or not?

Best regards
Maik

[Updated on: Tue, 01 March 2011 10:17]

Report message to a moderator

Re: [Acceleo] [message #657006 is a reply to message #656995] Tue, 01 March 2011 10:42 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------060909050806000201060203
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Maik,

This might sound more like a workaround but... can't you reinitialize
your variable when you call your service a second time? It sounds like
you're trying to use the service sometimes as a singleton (otherwise,
why initialize your list only once?) and sometimes as a regular Object
(thus your need to reinitialize it).

Laurent Goubet
Obeo

On 01/03/2011 11:11, Maik wrote:
> Hi Laurent,
>
> thanks for your answers. I'am a big fan of the whole acceleo project.
> Maybe we can find a solution for both of us and the community. Would it
> be possible from your side to implement a property (true|false) where
> the user can decied in the generation class, if a service will be use as
> singleton or not?
>
> Best regards
> Maik


--------------060909050806000201060203
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------060909050806000201060203--
Re: [Acceleo] [message #657286 is a reply to message #657006] Wed, 02 March 2011 10:45 Go to previous messageGo to next message
dieppi is currently offline dieppiFriend
Messages: 27
Registered: November 2010
Junior Member
Hi Laurent,

at the moment i clear the list in the template, via a method resetList(). The method is implemented as a service too.

We have here to following scenarion:

The templates runs through every state. If a state has a defined stereotype (defined by us) then a method (as service) will be called who checks the outgoings from the current state and the next states from the outgoing and so on until the next state with this defined stereotype. All states between these both state with defined stereotype will be stored in a list.

The method call is recursiv. We need to delete (reset) the list for every call of the template because there is only one instance. Sad

private Set<Element> systemStates = null;

public SystemStateServices() {
if(this.systemStates == null) {
this.systemStates = new LinkedHashSet<Element>();
}
}

The method has the follwoing signature

public Set<Element> getSystemStatesUntilViewState(Transition t)

and the reset method

public void resetList(Set<Element> list){
list.clear();
}

and the template who use the service
[template public systemClassTemplate(state : uml::State)]

[let liste : Set(Element) = transition.getSystemStatesUntilViewState()]
[for (element : Element | liste)]
[if (element.oclIsTypeOf(State))]
[helperClassSystemStates(element.oclAsType(State))/]
[/if]
[/for]

reset the list
[/comment]
[resetList(liste)/]
[/let]

......

The problem ist that we need to reset the list in a template. Sad It should be fine if we can decide with a property during the generation -> use services as singleton or not. Wink

Best regards
Maik

[Updated on: Wed, 02 March 2011 10:56]

Report message to a moderator

Re: [Acceleo] [message #657545 is a reply to message #657286] Thu, 03 March 2011 08:58 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000601060600010405030701
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Maik,

Why do you have the "systemStates" collection as a field is what I do
not get. It does not seem to me as the implementation you want for this
service.

public class SystemStateService {
public Set<Element> getSystemStatesUntilViewState(Transition t) {
Set<Element> systemStates = new LinkedHashSet<Element>();
// Do stuff
return systemStates;
}
}

seem more like the solution you seek. Why did you make that set a class
member? Why do you instantiate it as a singleton?

Laurent Goubet
Obeo

On 02/03/2011 11:45, Maik wrote:
> Hi Laurent,
>
> at the moment i clear the list in the template, via a method
> resetList(). The method is implemented as a service too. But i think is
> only a workaround to delete the list in a template.
> We have here to following scenarion:
>
> The templates runs through every state. If a state has a defined
> stereotype (defined by us) then a method (as service) will be called who
> checks the outgoings from the current state and the next states from the
> outgoing and so on until the next state with this defined stereotype.
> All states between these both state with defined stereotype will be
> stored in a list.
> The method call is recursiv. We need to delete (reset) the list for
> every call of the template because there is only one instance. :(
>
> private Set<Element> systemStates = null;
>
> public SystemStateServices() {
> if(this.systemStates == null) {
> this.systemStates = new LinkedHashSet<Element>();
> }
> }
>
> The method has the follwoing signature
>
> public Set<Element> getSystemStatesUntilViewState(Transition t)
>
> and the reset method
>
> public void resetList(Set<Element> list){
> list.clear();
> }
>
> and the template who use the service
> [template public systemClassTemplate(state : uml::State)]
>
> [let liste : Set(Element) = transition.getSystemStatesUntilViewState()]
> [for (element : Element | liste)]
> [if (element.oclIsTypeOf(State))]
> [helperClassSystemStates(element.oclAsType(State))/]
> [/if]
> [/for]
> reset the list
> [/comment]
> [resetList(liste)/]
> [/let]
>
> .....
>
> The problem ist that we need to reset the list in a template. :(
>
> Best regards
> Maik
>


--------------000601060600010405030701
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------000601060600010405030701--
Re: [Acceleo] [message #657661 is a reply to message #657545] Thu, 03 March 2011 15:38 Go to previous messageGo to next message
dieppi is currently offline dieppiFriend
Messages: 27
Registered: November 2010
Junior Member
Hi Laurent,

i can't create the list in the method because there is a recursivly call.

public class ServiceHelper {

private Set<Element> systemStates = null;

public ServiceHelper () {
if(this.systemStates == null) {
this.systemStates = new LinkedHashSet<Element>();
}
}

public Set<Element> getSystemStatesUntilViewState(Transition t) {

if (!(t.getTarget() instanceof FinalState)) {
if (t.getTarget() instanceof State) {
if (!hasViewStateStereotype((State) t.getTarget())) {
systemStates.add((State) t.getTarget());

return getSystemStatesUntilViewState(((Transition) t
.getTarget().getOutgoings().get(0)));
}
}
}
return systemStates;
}


Best regards
Maik
Re: [Acceleo] [message #657822 is a reply to message #657661] Fri, 04 March 2011 08:40 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010700080004070403050702
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

This could be changed to :

public class ServiceHelper {

public Set<Element> getSystemStatesUntilViewState(Transition t) {
Set<Element> systemStates = new LinkedHashSet<Element>();

if (!(t.getTarget() instanceof FinalState)) {
if (t.getTarget() instanceof State) {
if (!hasViewStateStereotype((State) t.getTarget())) {
systemStates.add((State) t.getTarget());

return
systemStates.addAll(getSystemStatesUntilViewState(((Transiti on) t
.getTarget().getOutgoings().get(0))));
}
}
}
return systemStates;
}

}

I usually favor short-lived objects to long-lived ones, especially when
it impacts readability (Who changes my set? From where? In which cases?
Why reset it?).

I do aggree that this might seem to you as a workaround for the fact
Acceleo does not reinstantiates its services... but what you see as a
bug (my "set" field is not emptied") was asked for as a feature in the
previous Acceleo, and we do think this is the best handling for services.

Laurent Goubet
Obeo


On 03/03/2011 16:38, Maik wrote:
> Hi Laurent,
>
> i can't create the list in the method because there is a recursivly call.
>
> public class ServiceHelper {
>
> private Set<Element> systemStates = null;
>
> public ServiceHelper () {
> if(this.systemStates == null) {
> this.systemStates = new LinkedHashSet<Element>();
> }
> }
>
> public Set<Element> getSystemStatesUntilViewState(Transition t) {
>
> if (!(t.getTarget() instanceof FinalState)) {
> if (t.getTarget() instanceof State) {
> if (!hasViewStateStereotype((State) t.getTarget())) {
> systemStates.add((State) t.getTarget());
>
> return getSystemStatesUntilViewState(((Transition) t
> .getTarget().getOutgoings().get(0)));
> }
> }
> }
> return systemStates;
> }
>
>
> Best regards Maik


--------------010700080004070403050702
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------010700080004070403050702--
Previous Topic:[Acceleo] eliminate white lines generated by template
Next Topic:[Acceleo 3] Update site problem
Goto Forum:
  


Current Time: Mon Oct 14 21:21:54 GMT 2024

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

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

Back to the top