[jboss-user] [EJB 3.0] - Re: locate services with service locator?
luckybird
do-not-reply at jboss.com
Wed Dec 17 04:23:20 EST 2008
I found my own solution:
| @SuppressWarnings("unchecked")
| public <T> T lookup(Class<T> clazz, final String pJndiName) {
| T cs = null;
| String jndiName = (pJndiName == null)
| ? jndiPrefix + clazz.getSimpleName() + "Bean/remote"
| : pJndiName;
|
| LOG.debug("Looking for "+jndiName);
| try {
| Object o = context.lookup(jndiName);
| if (o == null) {
| System.err.println("unable to find " + jndiName);
| } else {
| System.out.println("retrieved instance of "
| + o.getClass().getName());
| }
| cs = (T) PortableRemoteObject.narrow(o, clazz);
|
| } catch (NamingException e) {
| e.printStackTrace();
| }
| return cs;
| }
|
Errorhandling has to be improved, but this version works for me.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4197051#4197051
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4197051
More information about the jboss-user
mailing list