* Uses the KeyAllocator session bean to allocate a necessary key.
*/
protected Integer allocateKey() throws RemoteException
{
IKeyAllocator allocator;
if (_keyAllocatorHome == null)
{
try
{
Context initial = new InitialContext();
Context environment = (Context) initial.lookup("java:comp/env");
Object raw = environment.lookup("ejb/KeyAllocator");
_keyAllocatorHome = (IKeyAllocatorHome) PortableRemoteObject.narrow(
raw,
IKeyAllocatorHome.class);
}
catch (NamingException ex)
{
throw new XEJBException("Unable to locate IKeyAllocatorHome.", ex);
}
}
// Get a reference to *some* KeyAllocator bean ... it may be fresh,
// or one reused from a pool.
try
{
allocator = _keyAllocatorHome.create();
}
catch (CreateException ex)
{
throw new RemoteException("Unable to create a KeyAllocator from " + _keyAllocatorHome
+ ".", ex);
}
// Finally, invoke the method that gets a key.
return allocator.allocateKey();
}