On Mon, May 02, 2005 at 04:23:05PM -0700, John MccLain wrote:
: Is it possible to add a datasource to JNDI AFTER the server has started?
If you create the DataSource yourself, yes, you can bind it.
I had to test the same thing tonight, so I'll share an excerpt of my
stub code. The short story is, get the InitialContext and call bind().
IIRC, java:comp/env isn't writable, but any other path should be...
public void contextInitialized(ServletContextEvent sce) {
try{
// "StoreMe" is a serializable class created just
// for this experiment...
final String bindPath = "/some/SomeObject" ;
final StoreMe original = new StoreMe() ;
original.setProperty1( "x" ) ;
original.setProperty1( "Z" ) ;
Context ctx = new InitialContext() ;
ctx.bind( "/some" , new InitialContext() ) ;
ctx.bind( bindPath , original ) ;
StoreMe fromJndi = (StoreMe) ctx.lookup( bindPath ) ;
log.info( "Do the objects match? " + original.equals( fromJndi ) ) ;
}catch( final Exception rethrow ){
log.error( rethrow ) ;
// yank the context if this fails...
throw( new RuntimeException( rethrow ) ) ;
}
} // contextInitialized()
-QM
--
software -- http://www.brandxdev.net/
tech news -- http://www.RoarNetworX.com/
code scan -- http://www.JxRef.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]