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;
bindName: name of binding.
className: the fully-qualified name of the class
of the object to which this Reference refers.
factory: the name of the factory class for
creating an instance of the object to which this Reference
refers.
factoryLocation: the location of the factory
class.
refAddr: object's properties map.
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");