[webbeans-dev] Fwd: Patterns of reuse

Gavin King gavin at hibernate.org
Tue Dec 2 15:29:26 EST 2008


FYI


---------- Forwarded message ----------
From: Gavin King <gavin at hibernate.org>
Date: Tue, Dec 2, 2008 at 2:26 PM
Subject: Re: Patterns of reuse
To: Java Community Process JSR #299 Expert List <JSR-299-EG at jcp.org>


So, after talking this over with Jason, we're inclined to think that
we should rely on the use of the @Inherited annotation in
java.lang.annotation to control inheritance of type-level metadata:

* scope
* deployment type
* binding types
* name
* stereotypes
* type-level interceptor bindings

For annotations defined by the spec, we would say that:

* all built-in scope types are declared @Inherited
* no built-in binding type is declared @Inherited
* @Name is not declared @Inherited
* no built-in stereotype is declared @Inherited

There are four scenarios of metadata inheritance in the spec today:

* implementation class inheritance
* XML configuration
* stereotype transitivity
* interceptor binding type transitivity

I think @Inherited is definitely a good way of controlling metadata
inheritance in the cases of implementation class inheritance and XML
configuration. For example, if we have the following types:

  @MyStereotype
  class Foo { ... }

  class Bar extends Foo { .... }

then it seems completely natural to me that we would decide whether
@MyStereotype is inherited by Bar on the basis of whether it is
declared @Inherited. Likewise, it seems natural in the case of XML
configuration:

  <myapp:Foo>
     ...
  </myapp:Foo>

The big question in my mind is whether it is also appropriate to use
this mechanism to control transitivity of metadata declared by
stereotypes, for example, suppose that @MyStereotype declares
@MyOtherStereotype:

  @MyOtherStereotype
  @Stereotype
  ...
  public @interface MyStereotype { ... }

And @MyOtherStereotype declares a deployment type:

  @Staging
  @Stereotype
  ...
  public @interface MyOtherStereotype { ... }

Should we look at the @Inherited annotation to decide if @Staging is
inherited by @MyStereotype? I'm thinking that the answer is "no", but
I'm not sure.

Of course, we still need to define "special" rules for the
member-level metadata:

* method-level interceptor bindings
* initializer methods + injected fields
* producer/disposal
* observer methods

Does all that make sense?

--
Gavin King
gavin.king at gmail.com
http://in.relation.to/Bloggers/Gavin
http://hibernate.org
http://seamframework.org



-- 
Gavin King
gavin.king at gmail.com
http://in.relation.to/Bloggers/Gavin
http://hibernate.org
http://seamframework.org



More information about the weld-dev mailing list