@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2010 the original author or authors .
* Copyright 2002 - 2011 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -42,6 +42,7 @@ import org.springframework.beans.PropertyEditorRegistry;
@@ -42,6 +42,7 @@ import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.PropertyEditorRegistrySupport ;
import org.springframework.beans.SimpleTypeConverter ;
import org.springframework.beans.TypeConverter ;
import org.springframework.beans.TypeMismatchException ;
import org.springframework.beans.factory.BeanCreationException ;
import org.springframework.beans.factory.BeanCurrentlyInCreationException ;
import org.springframework.beans.factory.BeanDefinitionStoreException ;
@ -166,6 +167,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
@@ -166,6 +167,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
private final ThreadLocal < Object > prototypesCurrentlyInCreation =
new NamedThreadLocal < Object > ( "Prototype beans currently in creation" ) ;
/ * *
* Create a new AbstractBeanFactory .
* /
@ -189,7 +191,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
@@ -189,7 +191,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
public Object getBean ( String name ) throws BeansException {
return doGetBean ( name , null , null , false ) ;
}
public < T > T getBean ( String name , Class < T > requiredType ) throws BeansException {
return doGetBean ( name , requiredType , null , false ) ;
}
@ -346,7 +348,16 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
@@ -346,7 +348,16 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
// Check if required type matches the type of the actual bean instance.
if ( requiredType ! = null & & bean ! = null & & ! requiredType . isAssignableFrom ( bean . getClass ( ) ) ) {
throw new BeanNotOfRequiredTypeException ( name , requiredType , bean . getClass ( ) ) ;
try {
return getTypeConverter ( ) . convertIfNecessary ( bean , requiredType ) ;
}
catch ( TypeMismatchException ex ) {
if ( logger . isDebugEnabled ( ) ) {
logger . debug ( "Failed to convert bean '" + name + "' to required type [" +
ClassUtils . getQualifiedName ( requiredType ) + "]" , ex ) ;
}
throw new BeanNotOfRequiredTypeException ( name , requiredType , bean . getClass ( ) ) ;
}
}
return ( T ) bean ;
}
@ -682,7 +693,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
@@ -682,7 +693,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
return this . propertyEditorRegistrars ;
}
public void registerCustomEditor ( Class requiredType , Class < ? extends PropertyEditor > propertyEditorClass ) {
public void registerCustomEditor ( Class < ? > requiredType , Class < ? extends PropertyEditor > propertyEditorClass ) {
Assert . notNull ( requiredType , "Required type must not be null" ) ;
Assert . isAssignable ( PropertyEditor . class , propertyEditorClass ) ;
this . customEditors . put ( requiredType , propertyEditorClass ) ;
@ -1253,7 +1264,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
@@ -1253,7 +1264,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
throw new CannotLoadBeanClassException ( mbd . getResourceDescription ( ) , beanName , mbd . getBeanClassName ( ) , err ) ;
}
}
private Class doResolveBeanClass ( RootBeanDefinition mbd , Class . . . typesToMatch ) throws ClassNotFoundException {
if ( ! ObjectUtils . isEmpty ( typesToMatch ) ) {
ClassLoader tempClassLoader = getTempClassLoader ( ) ;