Bug fixes.
This commit is contained in:
parent
a2d68e4fc5
commit
3f6c5f7cb1
|
@ -94,7 +94,9 @@ public class IntrospectionManagerHibernate implements IntrospectionManager,
|
||||||
.keySet();
|
.keySet();
|
||||||
|
|
||||||
for (Iterator iter = mappedClasses.iterator(); iter.hasNext();) {
|
for (Iterator iter = mappedClasses.iterator(); iter.hasNext();) {
|
||||||
this.validationRegistryManager.findValidator((Class) iter.next());
|
String className = (String) iter.next();
|
||||||
|
this.validationRegistryManager.findValidator(Class.forName(
|
||||||
|
className));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,11 @@
|
||||||
|
|
||||||
package net.sf.acegisecurity.domain.validation;
|
package net.sf.acegisecurity.domain.validation;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
import org.springframework.beans.factory.BeanFactoryAware;
|
||||||
|
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
|
@ -56,18 +61,27 @@ import java.util.Map;
|
||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class ValidationRegistryManagerImpl implements ValidationRegistryManager {
|
public class ValidationRegistryManagerImpl implements ValidationRegistryManager,
|
||||||
|
BeanFactoryAware {
|
||||||
//~ Static fields/initializers =============================================
|
//~ Static fields/initializers =============================================
|
||||||
|
|
||||||
private static final String VALIDATOR_SUFFIX = "Validator";
|
private static final String VALIDATOR_SUFFIX = "Validator";
|
||||||
|
|
||||||
//~ Instance fields ========================================================
|
//~ Instance fields ========================================================
|
||||||
|
|
||||||
|
private AutowireCapableBeanFactory acbf;
|
||||||
private Map validatorMap = new HashMap();
|
private Map validatorMap = new HashMap();
|
||||||
private String[] validatorSearchPath;
|
private String[] validatorSearchPath;
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
|
public void setBeanFactory(BeanFactory beanFactory)
|
||||||
|
throws BeansException {
|
||||||
|
Assert.isInstanceOf(AutowireCapableBeanFactory.class, beanFactory,
|
||||||
|
"BeanFactory must be AutowireCapableBeanFactory");
|
||||||
|
this.acbf = (AutowireCapableBeanFactory) beanFactory;
|
||||||
|
}
|
||||||
|
|
||||||
public void setValidatorSearchPath(String[] validatorSearchPath) {
|
public void setValidatorSearchPath(String[] validatorSearchPath) {
|
||||||
this.validatorSearchPath = validatorSearchPath;
|
this.validatorSearchPath = validatorSearchPath;
|
||||||
}
|
}
|
||||||
|
@ -93,24 +107,26 @@ public class ValidationRegistryManagerImpl implements ValidationRegistryManager
|
||||||
String suffix = "." + ClassUtils.getShortName(domainClass)
|
String suffix = "." + ClassUtils.getShortName(domainClass)
|
||||||
+ VALIDATOR_SUFFIX;
|
+ VALIDATOR_SUFFIX;
|
||||||
|
|
||||||
for (int i = 0;
|
if (validatorSearchPath != null) {
|
||||||
(i < validatorSearchPath.length)
|
for (int i = 0;
|
||||||
&& (validatorClass == null); i++) {
|
(i < validatorSearchPath.length)
|
||||||
validatorClass = this.findValidatorClass(validatorSearchPath[i]
|
&& (validatorClass == null); i++) {
|
||||||
+ suffix);
|
validatorClass = this.findValidatorClass(validatorSearchPath[i]
|
||||||
|
+ suffix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// register the Validator in our Map, to speed up next retrieval
|
// if we found a Validator, register it so we speed up future retrieval
|
||||||
this.registerValidator(domainClass, validatorClass);
|
if (validatorClass != null) {
|
||||||
|
this.registerValidator(domainClass, validatorClass);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to create an instance of the Validator
|
// Attempt to create an instance of the Validator
|
||||||
try {
|
if (validatorClass != null) {
|
||||||
validator = (Validator) validatorClass.newInstance();
|
validator = obtainWiredValidator(validatorClass);
|
||||||
} catch (ClassCastException cce) {}
|
}
|
||||||
catch (InstantiationException ie) {}
|
|
||||||
catch (IllegalAccessException ile) {}
|
|
||||||
|
|
||||||
return validator;
|
return validator;
|
||||||
}
|
}
|
||||||
|
@ -123,6 +139,32 @@ public class ValidationRegistryManagerImpl implements ValidationRegistryManager
|
||||||
this.validatorMap.put(domainClass, validatorClass);
|
this.validatorMap.put(domainClass, validatorClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds a new instance of the <code>Validator</code>.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* By default, the <code>AutowireCapableBeanFactory</code> is used to build
|
||||||
|
* the instance, and autowire its bean properties. Specialised
|
||||||
|
* applications may wish to customise this behaviour, such as searching
|
||||||
|
* through the <code>ApplicationContext</code> for an existing singleton
|
||||||
|
* instance. This method is protected to enable such customisation.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param clazz the represents the <code>Validator</code> instance required
|
||||||
|
*
|
||||||
|
* @return the requested <code>Validator</code>, fully wired with all
|
||||||
|
* dependencies, or <code>null</code> if the
|
||||||
|
* <code>Validator</code> could not be found or created
|
||||||
|
*/
|
||||||
|
protected Validator obtainWiredValidator(Class clazz) {
|
||||||
|
try {
|
||||||
|
return (Validator) this.acbf.autowire(clazz,
|
||||||
|
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
|
||||||
|
} catch (BeansException autowireFailure) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Class findValidatorClass(String validatorClassName) {
|
private Class findValidatorClass(String validatorClassName) {
|
||||||
Class validatorClass = null;
|
Class validatorClass = null;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue