[weld-dev] Stereotype inheritance

Pete Muir pmuir at redhat.com
Mon Jan 18 10:43:53 EST 2010


On 18 Jan 2010, at 07:52, Stuart Douglas wrote:

> Does the spec define what happens in the following situation?
> 
> @RequestScoped @Stereotype @Target(TYPE) @Retention(RUNTIME) public @interface Action {}
> 
> @ApplicationScoped @Action @Stereotype @Target(TYPE) @Retention(RUNTIME) public @interface Home {}
> 
> @Home
> public class MyBean{}

2.7.1.5 "Stereotype declarations are transitive—a stereotype declared by a second stereotype is inherited by all beans and other ste- reotypes that declare the second stereotype." means that the way the stereotypes of MyBean are computed as the transitive closure of the stereotype graph. Which means MyBean has two stereotypes, @Home and and @Action.

And the scopes is covered in 2.4.4, "If there are two different stereotypes declared by the bean that declare different default scopes, then there is no default scope and the bean must explicitly declare a scope. If it does not explicitly declare a scope, the container automatically detects the problem and treats it as a definition error." (it's an error).

BTW we don't check stereotypes which aren't used.

> 
> 
> As far as I could see the spec does not define what to do when stereotypes declare stereotypes that have conflicting scopes.  In this situation it would make sense to have Home's scope override Actions, but we can also get situations like this:
> 
> 
> @RequestScoped @Stereotype @Target(TYPE) @Retention(RUNTIME) public @interface Action {}
> 
> @ApplicationScoped @Stereotype @Target(TYPE) @Retention(RUNTIME) public @interface Home {}
> 
> @Stereotype @Home @Action @Target(TYPE) @Retention(RUNTIME) public @interface HomeAction {}
> 
> @Home
> public class MyBean{}
> 
> I think this should be an error.  

Likewise :-)


More information about the weld-dev mailing list