You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Christian Beikov <c....@curecomp.com> on 2012/04/02 18:46:50 UTC
OWB Decorators
Hello there!
I have just found out something that really scared me!
I am using for this example 2 Decorators for one Interface and a simple
implementation, like this:
interface Service extends Serializable{
public Object getSomething(int value);
public boolean test(String text);
}
-----------------
public class MyService implements Service {
/* Used somewhere else to be able to use decorators and interceptors */
@Inject
private Service delegate;
public boolean test(String text){
return false;
}
}
-----------------
@Decorator
public abstract class ServiceDecoratorA implements Service {
@Delegate
@Inject
private Service delegate;
public boolean test(String text){
Object o = delegate.getSomething();
if(/*condition*/){
return true;
} else {
return delegate.test(text);
}
}
}
----------------
@Decorator
public abstract class ServiceDecoratorB implements Service {
@Delegate
@Inject
private Service delegate;
public boolean test(String text){
Object o = delegate.getSomething();
if(/*condition*/){
return true;
} else {
return delegate.test(text);
}
}
}
Invocation(Through EL): #{myService.test('aString')}
Expected Invocation-Chain:
OWB-Proxy.test(String)->...->ServiceDecoratorA.test(String)->ServiceDecoratorB.test(String)->MyService.test(String)
Actual Invocation-Chain:
OWB-Proxy.test(String)->...->ServiceDecoratorA.test(String)->MyService.test(String)
When I call the method test(String) decorator A is accessed when the
condition evaluates to false I would expect the next decorator to be
called, instead MyService.test(String) is called. If I put the
expression delegate.test(String) to the first line in the decorator
method, temporary put the result in a local var and return the local
vars content, everything works as expected.
I think that the invocation of the delegate mixes up a state of the OWB
proxy or so. I have no idea about what happens here but it sucks and I
think that this behavior is wrong.
I fixed this problem right now with temporary saving the delegates
return into a local var and the do other invocations on the delegate.
Is this a bug or is it not allowed to call other methods than the
decorated one in the decorator method?
Regards,
Christian
Re: OWB Decorators
Posted by Eric Covener <co...@gmail.com>.
>> Is this a bug or is it not allowed to call other methods than the decorated one
>> in the decorator method?
I think the behavior he expects is the correct behavior, having not
looked at the code, as the stack unwinds we need to back up the
decorator we're looking at as "next".
Re: OWB Decorators
Posted by Mark Struberg <st...@yahoo.de>.
Hi Christian!
It is better we move this one over to the openwebbeans-dev list.
LieGrue,
strub
----- Original Message -----
> From: Christian Beikov <c....@curecomp.com>
> To: MyFaces Discussion <us...@myfaces.apache.org>
> Cc:
> Sent: Monday, April 2, 2012 6:46 PM
> Subject: OWB Decorators
>
> Hello there!
>
> I have just found out something that really scared me!
> I am using for this example 2 Decorators for one Interface and a simple
> implementation, like this:
>
> interface Service extends Serializable{
> public Object getSomething(int value);
> public boolean test(String text);
> }
>
> -----------------
> public class MyService implements Service {
>
> /* Used somewhere else to be able to use decorators and interceptors */
> @Inject
> private Service delegate;
>
> public boolean test(String text){
> return false;
> }
> }
>
> -----------------
> @Decorator
> public abstract class ServiceDecoratorA implements Service {
> @Delegate
> @Inject
> private Service delegate;
>
> public boolean test(String text){
> Object o = delegate.getSomething();
>
> if(/*condition*/){
> return true;
> } else {
> return delegate.test(text);
> }
> }
> }
>
> ----------------
> @Decorator
> public abstract class ServiceDecoratorB implements Service {
> @Delegate
> @Inject
> private Service delegate;
>
> public boolean test(String text){
> Object o = delegate.getSomething();
>
> if(/*condition*/){
> return true;
> } else {
> return delegate.test(text);
> }
> }
> }
>
> Invocation(Through EL): #{myService.test('aString')}
> Expected Invocation-Chain:
> OWB-Proxy.test(String)->...->ServiceDecoratorA.test(String)->ServiceDecoratorB.test(String)->MyService.test(String)
> Actual Invocation-Chain:
> OWB-Proxy.test(String)->...->ServiceDecoratorA.test(String)->MyService.test(String)
>
> When I call the method test(String) decorator A is accessed when the condition
> evaluates to false I would expect the next decorator to be called, instead
> MyService.test(String) is called. If I put the expression delegate.test(String)
> to the first line in the decorator method, temporary put the result in a local
> var and return the local vars content, everything works as expected.
>
> I think that the invocation of the delegate mixes up a state of the OWB proxy or
> so. I have no idea about what happens here but it sucks and I think that this
> behavior is wrong.
> I fixed this problem right now with temporary saving the delegates return into a
> local var and the do other invocations on the delegate.
>
> Is this a bug or is it not allowed to call other methods than the decorated one
> in the decorator method?
>
> Regards,
>
> Christian
>
Re: OWB Decorators
Posted by Mark Struberg <st...@yahoo.de>.
Hi Christian!
It is better we move this one over to the openwebbeans-dev list.
LieGrue,
strub
----- Original Message -----
> From: Christian Beikov <c....@curecomp.com>
> To: MyFaces Discussion <us...@myfaces.apache.org>
> Cc:
> Sent: Monday, April 2, 2012 6:46 PM
> Subject: OWB Decorators
>
> Hello there!
>
> I have just found out something that really scared me!
> I am using for this example 2 Decorators for one Interface and a simple
> implementation, like this:
>
> interface Service extends Serializable{
> public Object getSomething(int value);
> public boolean test(String text);
> }
>
> -----------------
> public class MyService implements Service {
>
> /* Used somewhere else to be able to use decorators and interceptors */
> @Inject
> private Service delegate;
>
> public boolean test(String text){
> return false;
> }
> }
>
> -----------------
> @Decorator
> public abstract class ServiceDecoratorA implements Service {
> @Delegate
> @Inject
> private Service delegate;
>
> public boolean test(String text){
> Object o = delegate.getSomething();
>
> if(/*condition*/){
> return true;
> } else {
> return delegate.test(text);
> }
> }
> }
>
> ----------------
> @Decorator
> public abstract class ServiceDecoratorB implements Service {
> @Delegate
> @Inject
> private Service delegate;
>
> public boolean test(String text){
> Object o = delegate.getSomething();
>
> if(/*condition*/){
> return true;
> } else {
> return delegate.test(text);
> }
> }
> }
>
> Invocation(Through EL): #{myService.test('aString')}
> Expected Invocation-Chain:
> OWB-Proxy.test(String)->...->ServiceDecoratorA.test(String)->ServiceDecoratorB.test(String)->MyService.test(String)
> Actual Invocation-Chain:
> OWB-Proxy.test(String)->...->ServiceDecoratorA.test(String)->MyService.test(String)
>
> When I call the method test(String) decorator A is accessed when the condition
> evaluates to false I would expect the next decorator to be called, instead
> MyService.test(String) is called. If I put the expression delegate.test(String)
> to the first line in the decorator method, temporary put the result in a local
> var and return the local vars content, everything works as expected.
>
> I think that the invocation of the delegate mixes up a state of the OWB proxy or
> so. I have no idea about what happens here but it sucks and I think that this
> behavior is wrong.
> I fixed this problem right now with temporary saving the delegates return into a
> local var and the do other invocations on the delegate.
>
> Is this a bug or is it not allowed to call other methods than the decorated one
> in the decorator method?
>
> Regards,
>
> Christian
>