This content has been marked as final.
Show 1 reply
-
1. Re: Introspecting ejb interfaces
andreas Apr 11, 2002 8:53 AM (in response to puneet)It's not allowed to create instances of ejb in any way the container stack is obviated.
But I don't see any reason, why a bean interface method, shouldn't invoked with reflection on a object returned by a legal lookup.
I. e. I use this method to find all my beans by primary key:
public static Object findByPrimaryKey(String entity, String id) throws RuntimeException {
try {
Context initial = getContext();
Object home = initial.lookup("java:comp/env/" + entity);
Class c = home.getClass();
Class[] argTypes = {String.class};
Object[] arguments = {id};
Method method = c.getMethod("findByPrimaryKey", argTypes);
return method.invoke(home, arguments);
} catch (Exception fex) {
fex.printStackTrace();
throw new RuntimeException(fex.getMessage());
}
}