try {
try {
instance = getBeanClass().newInstance();
} catch (InstantiationException e) {
logger.error("Unable to create a new instance of the class ''{0}''", getBeanClass().getName(), e);
throw new CreatePoolItemException(WAITING_TIME_BEFORE_CREATION, "Cannot create a new instance", e);
} catch (IllegalAccessException e) {
logger.error("Unable to create a new instance of the class ''{0}''", getBeanClass().getName(), e);
throw new CreatePoolItemException(WAITING_TIME_BEFORE_CREATION, "Cannot create a new instance", e);
} catch (RuntimeException e) {
logger.error("Unable to create a new instance of the class ''{0}''", getBeanClass().getName(), e);
throw new CreatePoolItemException(WAITING_TIME_BEFORE_CREATION, "Cannot create a new instance", e);
} catch (Exception e) {
logger.error("Unable to create a new instance of the class ''{0}''", getBeanClass().getName(), 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(WAITING_TIME_BEFORE_CREATION, "Cannot create a new instance", e);
}
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
// Set the factory
instance.setEasyBeansFactory(this);
instance.setEasyBeansInvocationContextFactory(getInvocationContextFactory());
// Init the session Context
EZBSessionContext<SessionFactory<?>> sessionContext = new EasyBeansSessionContext<SessionFactory<?>>(this);
instance.setEasyBeansContext(sessionContext);
oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getContainer().getClassLoader());
try {
// Call injection
try {
injectResources(instance);
} catch (PoolException e) {
logger.error("Unable to perform injection of resources in the instance of the class ''{0}''", getBeanClass()
.getName(), e);
throw new CreatePoolItemException(WAITING_TIME_BEFORE_CREATION,
"Cannot perform injection of resources in the instance of the class '" + getBeanClass().getName()
+ "'.", e);
} catch (RuntimeException e) {
logger.error("Unable to perform injection of resources in the instance of the class ''{0}''", getBeanClass()
.getName(), e);
throw new CreatePoolItemException(WAITING_TIME_BEFORE_CREATION,
"Cannot perform injection of resources in the instance of the class '" + getBeanClass().getName()
+ "'.", e);
} catch (Exception e) {
logger.error("Unable to perform injection of resources in the instance of the class ''{0}''", getBeanClass()
.getName(), e);
throw new CreatePoolItemException(WAITING_TIME_BEFORE_CREATION,
"Cannot perform injection of resources in the instance of the class '" + getBeanClass().getName()
+ "'.", e);
} catch (Error e) {
logger.error("Unable to perform injection of resources in the instance of the class ''{0}''", getBeanClass()
.getName(), e);
throw new CreatePoolItemException(WAITING_TIME_BEFORE_CREATION,
"Cannot perform injection of resources in the instance of the class '" + getBeanClass().getName()
+ "'.", e);
}
// post construct callback
postConstruct(instance);
} catch (RuntimeException e) {
logger.error("Unable to perform postconstruct on a new instance of the class ''{0}''", getBeanClass().getName(), e);
throw new CreatePoolItemException(WAITING_TIME_BEFORE_CREATION, "Cannot perform postConstruct on the new instance",
e);
} catch (Exception e) {
logger.error("Unable to perform postconstruct on a new instance of the class ''{0}''", getBeanClass().getName(), e);
throw new CreatePoolItemException(WAITING_TIME_BEFORE_CREATION, "Cannot perform postConstruct on the new instance",
e);
} catch (Error e) {
logger.error("Unable to perform postconstruct on a new instance of the class ''{0}''", getBeanClass().getName(), e);
throw new CreatePoolItemException(WAITING_TIME_BEFORE_CREATION, "Cannot perform postConstruct on the new instance",
e);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}