users@glassfish.java.net

Re: appclient issue/misunderstanding

From: <glassfish_at_javadesktop.org>
Date: Mon, 05 Mar 2007 14:15:22 PST

Hi.

What you have noticed is intended.

This is from the spec: "Injection is also supported for the application client main class."

There are a few other threads in the forum on this, but it's pretty straightforward.

One main reason is for efficiency. If any arbitrary class could require injection then the app client container would have to scan all classes in the classpath looking for annotations that required injection. This could be very expensive, certainly.

The trade-off is to make only the main class subject to injection - and only static elements, by the way.

I don't agree that this restriction makes annotation virtually useless in all but the simplest clients.

Collect the injectable resources on the main class. Write a helper class (ResourceHelper or something like that) which the main class initializes with the injected resources. ResourceHelper would provide public get methods. Then any code elsewhere in the client that needs to use an injected resource XXX can simply use ResourceHelper.getXXX().

Perhaps not quite as convenient as having injection work on any possible class, but this seems like a relatively simple approach to working within the restriction while being much more efficient than requiring a scan of every possible class.

Is there something you're trying to do for which this approach would not work?

- Tim
[Message sent by forum member 'tjquinn' (tjquinn)]

http://forums.java.net/jive/thread.jspa?messageID=206321