Hi, again, Witold.
Witold Szczerba wrote:
> 2006/12/6, vince kraemer <Vince.Kraemer_at_sun.com>:
>> This is a limitation outlined in the spec...
>>
>> I wish it was different. It isn't.
>>
> Hoooooooooly .... :) I have never got to that point in any
> documentation. Thanks a lot for clarification.
>
>> I have to trust that the folks that wrote the spec put the limitation in
>> there for a reason that I haven't come to understand yet...
>
> Well, interesting thing with that limitation in deed. Maybe they
> wanted to avoid uncaught/unexpected problems during loading of
> classes, as class loader would have introspect every single new class
> and hold loading for the time needed by injection (injection of remote
> resources is dangerous by itself).
> In other words there would be no clear point for defining catches for
> Naming/Network exceptions. That is what I think about that limitation
> after thinking about it for a while...
>
> So it looks like I should reserve a place in my Main class for every
> possible bean injection and reference that beans as in my second
> example, like:
> Main.xyzSessionBean.doSomething()
> in entire application. Actually id doesn't sound so bad... Don't you
> think?
Yes, this or something functionally equivalent should work fine for you.
You may want to consider something like this. Create private static
variables on the Main class for injection and provide getter methods for
each of them. Then use the getters from the rest of the logic.
You could even create a helper class (named, perhaps, something like
BeanManager) with its own static methods that use the getters that you
wrote on the Main class to return the bean references to the caller.
Then the rest of your client logic can use the BeanManager methods to
retrieve the appropriate bean and operate on it. Although adding the
BeanManager into the picture may seem overly complicated, it helps to
isolate the rest of your client logic that much more from that
particular Main class so you can more easily reuse that other client
logic in another app client you might write. To do so you'd just have
to implement the BeanManager methods differently to refer to the new
client's Main class and its static getter methods.
Using the helper class is pretty much a matter of personal preference.
In any case, your general approach is on-target.
- Tim