1 Reply Latest reply on Apr 11, 2002 8:53 AM by Andreas Schouten

    Introspecting ejb interfaces

    Puneet Narang Newbie

      Is it possible to introspect the home interface returned by jndi lookup to call the "create" method and then introspect the remote interface returned by create to invoke a method of remote interface.

      In a way i want to get rid of the castings of objects returned by jndi lookup and create method into home and remote interfaces respectively.

        • 1. Re: Introspecting ejb interfaces
          Andreas Schouten Newbie

          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) {
          throw new RuntimeException(fex.getMessage());