2.12.5. InitialContextInitializer API

InitialContextInitalizer also provides feature of references binding in runtime. References have bind in runtime will be persisted and automatically rebinded on a next system start.

Service provides methods for binding reference.



     public void bind(String bindName, 
                      String className, 
                      String factory, 
                      String factoryLocation, 
                      Map<String, String> refAddr) 
                 throws NamingException, FileNotFoundException, XMLStreamException;

Example of usage:



      // obtain InitialContextInitializer instance from ExoContainer (e.g. PortalContainer)
      InitialContextInitializer initContext = (InitialContextInitializer)container.getComponentInstanceOfType(InitialContextInitializer.class);
  
      Map<String, String> refAddr = new HashMap<String, String>();
      refAddr.put("driverClassName", "oracle.jdbc.OracleDriver");
      refAddr.put("url", "jdbc:oracle:thin:@oraclehost:1521:orcl");
      refAddr.put("username", "exouser");
      refAddr.put("password", "exopassword");
      initContext.bind("jdbcexco", "javax.sql.DataSource", "org.apache.commons.dbcp.BasicDataSourceFactory", null, refAddr);
      // try to get just bound DataSource
      DataSource ds = (DataSource)new InitialContext().lookup("jdbcexo");
Copyright ©2012. All rights reserved. eXo Platform SAS