package org.theonefx.wcframework.ioc.exception;
import org.theonefx.wcframework.core.exception.BeanCreationException;
import org.theonefx.wcframework.core.exception.BeansException;
import org.theonefx.wcframework.utils.ClassUtils;
/**
* Exception thrown when a bean depends on other beans or simple properties
* that were not specified in the bean factory definition, although
* dependency checking was enabled.
*/
public class UnsatisfiedDependencyException extends BeanCreationException {
private static final long serialVersionUID = -148071106905514992L;
/**
* Create a new UnsatisfiedDependencyException.
* @param resourceDescription description of the resource that the bean definition came from
* @param beanName the name of the bean requested
* @param propertyName the name of the bean property that couldn't be satisfied
* @param msg the detail message
*/
public UnsatisfiedDependencyException(String beanName, String propertyName, String msg) {
super(beanName, "Unsatisfied dependency expressed through bean property '" + propertyName + "'" +
(msg != null ? ": " + msg : ""));
}
/**
* Create a new UnsatisfiedDependencyException.
* @param resourceDescription description of the resource that the bean definition came from
* @param beanName the name of the bean requested
* @param propertyName the name of the bean property that couldn't be satisfied
* @param ex the bean creation exception that indicated the unsatisfied dependency
*/
public UnsatisfiedDependencyException(String beanName, String propertyName, BeansException ex) {
this(beanName, propertyName, (ex != null ? ": " + ex.getMessage() : ""));
initCause(ex);
}
/**
* Create a new UnsatisfiedDependencyException.
* @param resourceDescription description of the resource that the bean definition came from
* @param beanName the name of the bean requested
* @param ctorArgIndex the index of the constructor argument that couldn't be satisfied
* @param ctorArgType the type of the constructor argument that couldn't be satisfied
* @param msg the detail message
*/
public UnsatisfiedDependencyException(String beanName, int ctorArgIndex, Class<?> ctorArgType, String msg) {
super(beanName, "Unsatisfied dependency expressed through constructor argument with index " +
ctorArgIndex + " of type [" + ClassUtils.getQualifiedName(ctorArgType) + "]" +
(msg != null ? ": " + msg : ""));
}
/**
* Create a new UnsatisfiedDependencyException.
* @param resourceDescription description of the resource that the bean definition came from
* @param beanName the name of the bean requested
* @param ctorArgIndex the index of the constructor argument that couldn't be satisfied
* @param ctorArgType the type of the constructor argument that couldn't be satisfied
* @param ex the bean creation exception that indicated the unsatisfied dependency
*/
public UnsatisfiedDependencyException(String beanName, int ctorArgIndex, Class<?> ctorArgType, BeansException ex) {
this(beanName, ctorArgIndex, ctorArgType, (ex != null ? ": " + ex.getMessage() : ""));
initCause(ex);
}
}