* Creates an instance.
* @throws CreatePoolItemException if instance cannot be created.
* @return the created instance.
*/
public EasyBeansMDB createPoolItem() throws CreatePoolItemException {
EasyBeansMDB instance = null;
try {
instance = getBeanClass().newInstance();
} catch (InstantiationException e) {
throw new CreatePoolItemException(WAITING_TIME_BEFORE_CREATION, "Cannot create a new instance", e);
} catch (IllegalAccessException e) {
throw new CreatePoolItemException(WAITING_TIME_BEFORE_CREATION, "Cannot create a new instance", e);
} catch (Error e) {
logger.error("Unable to create a new instance of the class ''{0}''", getBeanClass().getName(), e);
// null as factory is broken
throw new CreatePoolItemException(null, "Cannot create a new instance", e);
}
// Set the factory
instance.setEasyBeansFactory(this);
instance.setEasyBeansInvocationContextFactory(getInvocationContextFactory());
// Init the MDB context
EasyBeansMDBContext mdbContext = new EasyBeansMDBContext(this);
instance.setEasyBeansContext(mdbContext);
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getContainer().getClassLoader());
try {
// Call injection
try {
injectResources(instance);
} catch (PoolException e) {
throw new CreatePoolItemException(WAITING_TIME_BEFORE_CREATION, "Cannot inject resource in the instance", e);
}
// post construct callback
instance.postConstructEasyBeansLifeCycle();
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
return instance;