You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openwebbeans.apache.org by "Eric Covener (JIRA)" <ji...@apache.org> on 2010/08/11 23:01:17 UTC

[jira] Commented: (OWB-435) What is the expected result for following 2 decorators?

    [ https://issues.apache.org/jira/browse/OWB-435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12897453#action_12897453 ] 

Eric Covener commented on OWB-435:
----------------------------------

I think the result you saw is correct.  UserDecorator1 must run first due to the spec, and can do whatever it wants in getName(), even not calling its delegate at all (this is why it is higher priority -- it can disregard any potential result from other decorators or bean class)

Since it chooses to call the delegate, it invokes the next decorator, who invokes the decorated bean.    Each of the decorators appends text, so the first decorator is the leftmost in the output.


> What is the expected result for following 2 decorators?
> -------------------------------------------------------
>
>                 Key: OWB-435
>                 URL: https://issues.apache.org/jira/browse/OWB-435
>             Project: OpenWebBeans
>          Issue Type: Question
>          Components: Interceptor and Decorators
>            Reporter: YING WANG
>            Assignee: Gurkan Erdogdu
>            Priority: Minor
>
> While I am testing 2 decorators decorate the same getName() method of UserBean, I found the result is:
> 1. "UserDecorator1(UserDecorator2(MYNAME)) "   <==  Did call UserDecorator1.getName() first, but before it finishes, it recursively invokes the UserDecorator2.getName() on the calling stack.
> 2. or  should the result be:
> "UserDecorator2(MYNAME)"      <==== should decorator2's result overwrite decorator1's?
> 3. or should the result be:
> "UserDecorator2(UserDecorator1(MYNAME)) "    <==== should decorator1's result to the one used for decorator2?
> I prefer 3, but I am not sure which result is the correct one....
> ===================Userbean ========================
> public class UserBean implements UserInterface, Serializable 
> {
>     public String getName()
>     {
>     	return "MYNAME";
>     }
> }
> ===================UserDecorator1 ========================
> @Decorator
> public abstract class UserDecorator1 implements UserInterface, Serializable 
> {
> 	@Inject @Delegate @Any UserInterface ui;
> 	
> 	public String getName() {
> 		return "UserDecorator1(" + ui.getName() + ")";
> 	}
> }
> ===================UserDecorator2 ========================
> @Decorator
> public abstract class UserDecorator2 implements UserInterface, Serializable 
> {
> 	@Inject @Delegate @Any UserInterface ui;
> 	
> 	public String getName() {
> 		return "UserDecorator2(" + ui.getName() + ")";
> 	}
> }
> ========================================================
>         <decorators>
>                 <class>com.jcdi.test.UserDecorator1</class>
>                 <class>com.jcdi.test.UserDecorator2</class>
>         </decorators>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.