[webbeans-dev] Java EE resource injection
by Gavin King
Folks, it's time to address the problem of generalized Java EE
resource injection.
Web Beans needs to support injection of the following kinds of things:
* EE resources (e.g. JDBC datasources, etc)
* remote EJB references
* web service references
I believe we can treat all three as essentially the same kind of thing
in the spec. Let's call it a "EE resource reference", or whatever.
It's a new "kind" of Web Bean in Chapter 3. This functionality should
not impact any other part of the specification.
(An additional complication is that we need to unify the current
notion of a "JMS endpoint" with this functionality. I don't believe
that this is a difficult problem, we just need to make it a special
case of a "EE resource reference", that supports additional
semantics.)
I see two possible paths we could go down here:
Option 1:
=======
The spec could simply say that for every "EE resource reference"
defined in web.xml or ejb-jar.xml, that a Web Bean exists with
deployment type @Production and no name. The scope and binding types
of this Web Bean have the usual defaults (@Depenent, @Current), but
these may be specified explicitly in web.xml or ejb-jar.xml:
<ejb-ref>
<ejb-ref-name>foo</ejb-ref-name>
<remote>org.myapp.FooRemote</remote>
<binding>org.myapp.Bar</binding>
<scope>javax.webbeans.Conversation</scope>
</ejb-ref>
<resource-ref>
<res-ref-name>jdbc/DefaultDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<binding>org.myapp.Default</binding>
</resource-ref>
<service-ref>
<service-ref-name>service/FooService</service-ref-name>
<service-interface>org.myapp.Foo</service-interface>
<wsdl-file>META-INF/wsdl/FooService.wsdl</wsdl-file>
<jaxrpc-mapping-file>META-INF/foo-mapping.xml</jaxrpc-mapping-file>
<binding>org.myapp.Bar</binding>
<scope>javax.webbeans.Request</scope>
</service-ref>
The lifecycle of this Web Bean would be super-simple:
* Bean.create() would be equivalent to a JNDI lookup for the resource
* Bean.destroy() would simply discard the reference
There is just one problem with this approach: EE resource references
are by nature scoped to a particular EE module, whereas this is not
naturally the case for Web Beans (which are naturally EAR scoped). I
don't believe this is a really big problem but we would need to
institute an additional layer of validation to ensure that injection
points that refer to an EE resource are in the same module as the
resource ref declaration. This would be a new section in the spec, but
I don't believe it is difficult to write.
Option 2:
=======
The second option would be to require explicit declaration of the
resource in web-beans.xml, thus making them an EAR-global declaration.
<ResourceRef jndiName=".....">
<myapp:Foo>
<myapp:Bar/>
</myapp:Foo>
<ResquestScoped/>
</ResourceRef>
There are a couple of major problems with this:
* resources must be declared twice, in different places
* the two declarations are correlated via a global JNDI name, which:
- is still not really a well-defined construct in the EE spec
- cannot be properly validated at development time
Therefore I strongly prefer Option 1.
WDYT?
--
Gavin King
gavin.king(a)gmail.com
http://in.relation.to/Bloggers/Gavin
http://hibernate.org
http://seamframework.org
16 years
[webbeans-dev] Question about parsing Date fields in XML based metadata
by Mark Struberg
Hi!
It's a bit late so please excuse me if my thoughts/sentences are a bit weird.
The web_beans-1.0-pr-spec has the following definition in section 9.2.5:
> The initial value of a field of type java.util.Date or
> java.util.Calendar is specified using a format that can be
> parsed by java.text.DateFormat.getDateTimeInstance().parse().
Now my question: DateFormat.getDateTimeInstance() is Locale aware. This may not always be positive.
I'm working on international projects, and if I build a WAR in vienna (Locale de_AT), and my colleagues in mountain view (Locale US) and Bangalore (maybe Locale hi_IN) like to deploy it, then it's very likely that they get parsing exceptions for e.g. default values provided via web-beans XML definition, isn't it?
Shouldn't we better use e.g. the xs:dateTime format like in SOAP?
http://www.w3.org/TR/xmlschema-2/#dateTime
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
Another question:
Let's say I have a Calendar field in MyWebBean.java. Which kind of Calendar should it actually inject? GregorianCalendar? Or should it throw a DefinitionException? (Generall question about handling of abstract members)
txs in advance and LieGrue,
strub
----------------------------------------------------------------
“Multiple exclamation marks are a sure sign of a diseased mind!”
(Sir Terry Pratchett)
16 years
[webbeans-dev] XML Date Type Field Value
by Gurkan Erdogdu
Hi;
In Spec says that
"Date values are parsed by the DateFormat.getDateTimeInstance().parse()."
But it does not specifies any default locale specific information. So one format/Locale defined in the XML does not work for other Locales than its defined locale. So is there any default formatting/Locale ? (For example : SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ") as a default).
Thanks;
Gurkan
16 years
[webbeans-dev] Bean.getInjectionPoints()
by Gavin King
The spec requires that injection points be validated at init time for
any Bean (for XxxxxDependencyException).
Nick from the RI team has noticed that for this to be implementable,
we need to add metadata about the injection points of a bean to the
Bean interface.
I propose:
public abstract class Bean<X> {
...
Set<InjectionPoint> getInjectionPoints();
}
Since we already have the following interface that describes injection points:
public interface InjectionPoint {
public Type getType();
public Set<Annotation> getBindingTypes();
public Object getInstance();
public Bean<?> getBean();
public Member getMember();
public <T extends Annotation> T getAnnotation(Class<T> annotationType);
public Annotation[] getAnnotations();
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType);
}
I will make this change to the spec, unless anyone speaks up with any objection.
--
Gavin King
gavin.king(a)gmail.com
http://in.relation.to/Bloggers/Gavin
http://hibernate.org
http://seamframework.org
16 years
[webbeans-dev] Re: producer methods and injection
by Benjamin Graf
I played a bit around this code fragment and everything works as
expected for me.
@Nik: Do you have a complete example and a bit more information to
verify your problem?
> No, @Dependent is the default.
>
> On Fri, Jan 2, 2009 at 12:22 AM, Benjamin Graf <Benjamin.Graf at gmx.net <https://lists.jboss.org/mailman/listinfo/webbeans-dev>> wrote:
> >/ I'm not sure but doesn't it need a @Dependent scope to work?
> />/
> />/ Gavin King wrote:
> />>/ That code should work. If it doesn't it would be a bug.
> />>/
> />>/ On Wed, Dec 31, 2008 at 9:38 PM, Nicklas Karlsson <nickarls at gmail.com <https://lists.jboss.org/mailman/listinfo/webbeans-dev>> wrote:
> />>/
> />>>/ Hi,
> />>>/
> />>>/ Is there something I don't understand about producers methods and
> />>>/ injection with parameterized types when I have
> />>>/
> />>>/ public class A
> />>>/ {
> />>>/ @Produces @Users
> />>>/ public List<User> getUsers() {
> />>>/ List<User> users = new ArrayList<User>();
> />>>/ users.add(new User("1", "1", "1"));
> />>>/ return users;
> />>>/ }
> />>>/ }
> />>>/
> />>>/ and
> />>>/
> />>>/ @SessionScoped
> />>>/ public class B
> />>>/ {
> />>>/ @Users
> />>>/ private List<User> users;
> />>>/
> />>>/ public int count() {
> />>>/ return users.size();
> />>>/ }
> />>>/ }
> />>>/
> />>>/ When B is created and injection is done, it goes looking for
> />>>/ java.util.List and fails.
> />>>/
> />>>/ ---
> />>>/ Nik
> />>>/
> />>>/
> />>/
> />>/
> />>/
> />>/
> />/
> />/ _______________________________________________
> />/ webbeans-dev mailing list
> />/ webbeans-dev at lists.jboss.org <https://lists.jboss.org/mailman/listinfo/webbeans-dev>
> />/ https://lists.jboss.org/mailman/listinfo/webbeans-dev
> />/
> /
>
>
> --
> Gavin King
> gavin.king at gmail.com <https://lists.jboss.org/mailman/listinfo/webbeans-dev>
> http://in.relation.to/Bloggers/Gavin
> http://hibernate.org
> http://seamframework.org
>
16 years
[webbeans-dev] Re: producer methods and injection
by Gavin King
That code should work. If it doesn't it would be a bug.
On Wed, Dec 31, 2008 at 9:38 PM, Nicklas Karlsson <nickarls(a)gmail.com> wrote:
> Hi,
>
> Is there something I don't understand about producers methods and
> injection with parameterized types when I have
>
> public class A
> {
> @Produces @Users
> public List<User> getUsers() {
> List<User> users = new ArrayList<User>();
> users.add(new User("1", "1", "1"));
> return users;
> }
> }
>
> and
>
> @SessionScoped
> public class B
> {
> @Users
> private List<User> users;
>
> public int count() {
> return users.size();
> }
> }
>
> When B is created and injection is done, it goes looking for
> java.util.List and fails.
>
> ---
> Nik
>
--
Gavin King
gavin.king(a)gmail.com
http://in.relation.to/Bloggers/Gavin
http://hibernate.org
http://seamframework.org
16 years