{
String doing = null;
try
{
doing = "creating database context";
XNamingService dbContext = UnoRuntime.queryInterface( XNamingService.class,
m_orb.createInstance( "com.sun.star.sdb.DatabaseContext" ) );
if ( _revokeIfRegistered )
{
doing = "revoking previously registered data source";
try
{
dbContext.revokeObject( _registrationName );
}
catch( NoSuchElementException e )
{ /* allowed here */ }
}
// if the document associated with the database document has not yet been saved, then we need to do so
DatabaseDocument doc = getDatabaseDocument();
String docURL = doc.getURL();
if ( docURL.length() == 0 )
{
final java.io.File tempFile = java.io.File.createTempFile( _registrationName + "_", ".odb" );
if ( tempFile.exists() )
// we did not really want to create that file, we just wanted its local name, but
// createTempFile actually creates it => throw it away
// (This is necessary since some JVM/platform combinations seem to actually lock the file)
tempFile.delete();
String localPart = tempFile.toURI().toURL().toString();
localPart = localPart.substring( localPart.lastIndexOf( '/' ) + 1 );
docURL = util.utils.getOfficeTemp( m_orb ) + localPart;
doing = "storing database document to temporary location (" + docURL + ")";
doc.storeAsURL( docURL );
}
// register the data soource
doing = "registering the data source at the database context";
dbContext.registerObject( _registrationName, m_dataSource );
}
catch( final java.lang.Exception e )
{
throw new StatusException( "DataSource.registerAs: error during " + doing, e );
}