1 Reply Latest reply on Mar 7, 2003 2:22 AM by Ecka Kjellberg

    JNDI-EJB

    acron Newbie

      How can I extract all ejb-beans deployed into JNDI if I don't know their JNDI-names and then put them into some structure(a tree for example)?

        • 1. 3839699
          Ecka Kjellberg Newbie

          ...
          public void testInitialContext() throws Exception
          {
          log.info(listContext(""));
          }
          public void testInitialContextJavaComp() throws Exception
          {
          log.info(listContext("java:comp"));
          }
          private String listContext(String name) throws Exception
          {
          StringBuffer sb = new StringBuffer(name + "\n");
          sb.append(listContext(ic.listBindings(name), " "));
          return sb.toString();
          }
          private String listContext(NamingEnumeration blist, String tab) throws Exception
          {
          StringBuffer sb = new StringBuffer("");
          sb.append(tab + "{\n");
          while (blist.hasMore())
          {
          javax.naming.Binding bd = (javax.naming.Binding)
          blist.next();
          String objstr = bd.getObject().toString();
          objstr = objstr.replace('\n', '|');
          objstr = objstr.replace('\r', '|');
          sb.append(tab + " " + bd.getName() + "=" +
          objstr + ",\n");
          Object o = bd.getObject();
          if (o instanceof javax.naming.Context)
          {
          javax.naming.Context nc =
          (javax.naming.Context)o;
          sb.append(listContext(nc.listBindings(""),
          tab + " "));
          }
          }
          sb.append(tab + "}\n");
          return sb.toString();
          }
          ...