I have a class, which is either EJB or POJO (I don't know). I have to make an instance of this class. Is there any pattern for this operation? Or I should manually check for EJB annotations and then do JNDI lookup?
public Object instantiate(Class c) {
return /* ... */
}
EJB classes should be instantiated only by the container. Otherwise they are not EJB. If you want to obtain an EJB instance, look it up via JNDI, or inject it.
You can see if a class is supposed to be an EJB by verifying its annotations:
if (clazz.isAnnotationPresent(Stateless.class)
|| clazz.isAnnotationPresent(Statefull.class)) { .. };
(and message-driven, perhaps)