1 Reply Latest reply on Sep 28, 2009 6:30 AM by olegpv

    JNDI ObjectFactory - run-time registration

      Hello,

      Is there a possibility to register some new custom JNDI resources (via custom ObjectFactory implementations) at run-time?

      I mean the following:

      1) Here is an article about the standard approach for registering new JNDI resources for JBoss Web: http://www.jboss.org/file-access/default/members/jbossweb/freezone/docs/latest/jndi-resources-howto.html

      2) It says that all custom javax.naming.spi.ObjectFactory implementations should be configured in server.xml

      3) I need to register my custom ObjectFactory implementations at run-time, without any deploy-time modifications in server.xml

      Maybe there is a certain API for accessing JBoss Web configuration from Java code, which will allow such kind of registration?

      Regards,
      Oleg

        • 1. Re: JNDI ObjectFactory - run-time registration

          OK, everything turned out to be simple, as always...

          Method bind(String name, Object object) of javax.naming.Context can accept objects of type javax.naming.Reference as well, so this API enables the following code for binding ObjectFactory implementation to JNDI names:

          Reference ref = new Reference(myFactoryClassName, myFactoryClassName, null);
          
          Context context = new InitialContext();
          
          context.bind("services/serviceName1", ref);
          context.bind("services/serviceName2", ref);
          context.bind("services/serviceName3", ref);


          And every time the client code will lookup any of the above example JNDI names via context.lookup(...) our ObjectFactory will return the necessary proxy objects for accessing the target services.