tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Quintin Beukes <quin...@skywalk.co.za>
Subject Re: suggestion for defining local ref name for session beans
Date Sun, 13 Sep 2009 12:22:49 GMT
Yes, you can create a mapped name when defining each EJB (part of the
@Stateless annotation), and then inside the facade session bean you
can lookup the others doing something like this:

InitialContext ctx = new InitialContext();
Object lookedUpEJB = ctx.lookup(otherEjbsMappedName);

Then lookedUpEJB will contain a reference to the EJB. you can wrap
this in a static method of either the facade bean or some other class.
When initializing an InitialContext without constructor arguments, it
is for the local server by default, and therefore you can lookup any
EJBs in the server.

Also, if you don't explicitly define a mapped name for the EJB, it
will default to ${beanImplementationClass}Local. So if you have the
following:

@Stateless
public class MyBean implements MyLocal {}
@Local
public class MyLocal {}

Then you can do the following to get a reference:
private Object lookup(String name) throws NamingException {
  return new InitialContext().lookup(name);
}

MyLocal bean = lookup("MyBeanLocal");

Hope this helps,
Q

On Sun, Sep 13, 2009 at 11:19 AM, John Ament <my.reprive@gmail.com> wrote:
> I'm not sure, could be that I'm missing the the subtlety of your request,
> but isn't this what the mappedName attribute is for on the
> Stateless/Stateful annotation?
>
> - John
>
> On Sun, Sep 13, 2009 at 4:20 AM, Mohammad Nour El-Din <
> nour.mohammad@gmail.com> wrote:
>
>> Hi Mohammad Nourouzi...
>>
>>  Seems that we almost have the same name ;). Well I think you are
>> missing things up here. The @EJB you are defining here are for
>> dependency injection (DI) so the container knows that you are
>> requiring this EJB to be injected into your class which
>> defined/declared this DI point. If using this way it not good for you
>> you still can lookup EJB explicitly using either:
>>
>> 1- The new lookup method in the EJB's context class.
>> 2- By initializing a naming context and using the lookup method.
>>
>> On Sun, Sep 13, 2009 at 6:01 AM, is_maximum <mnrz57@gmail.com> wrote:
>> >
>> > Hello
>> > I have a session bean which is an entry point for calling a number of
>> other
>> > session beans.
>> > Because this entry bean doesn't know which stateless should be called at
>> > runtime we need to lookup them. in order to lookup EJBs we must declare
>> @EJB
>> > on this entry session bean. that is, more than 20 @EJB should be declared
>> > for a class. This is not readable and also very bad-styled.
>> >
>> > Why not this local-ref name define in @Stateless annotation as an
>> attribute
>> > say "refName" so each session bean has declared its own local reference
>> name
>> > and we can lookup them any where in application locally
>> >
>> >
>> >
>> > -----
>> > --
>> > Regards
>> >
>> > Mohammad Norouzi
>> >
>> > Help each other to reach the future faster
>> >
>> > http://pixelshot.wordpress.com Pixelshot Photoblog
>> >
>> > http://brainable.blogspot.com Brainable Blog
>> >
>> >
>> > --
>> > View this message in context:
>> http://www.nabble.com/suggestion-for-defining-local-ref-name-for-session-beans-tp25420391p25420391.html
>> > Sent from the OpenEJB User mailing list archive at Nabble.com.
>> >
>> >
>>
>>
>>
>> --
>> Thanks
>> - Mohammad Nour
>> - LinkedIn: http://www.linkedin.com/in/mnour
>> ----
>> "Life is like riding a bicycle. To keep your balance you must keep moving"
>> - Albert Einstein
>>
>



-- 
Quintin Beukes

Mime
View raw message