polishing

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3245 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller 2010-04-14 12:18:05 +00:00
parent 0f49919d33
commit 3cd57a0148
2 changed files with 25 additions and 30 deletions

View File

@ -1,12 +1,12 @@
/* /*
* Copyright 2002-2005 the original author or authors. * Copyright 2002-2010 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -32,7 +32,7 @@ import org.springframework.beans.factory.BeanFactory;
* @since 1.1 * @since 1.1
*/ */
public interface InstantiationStrategy { public interface InstantiationStrategy {
/** /**
* Return an instance of the bean with the given name in this factory. * Return an instance of the bean with the given name in this factory.
* @param beanDefinition the bean definition * @param beanDefinition the bean definition
@ -43,9 +43,9 @@ public interface InstantiationStrategy {
* @return a bean instance for this bean definition * @return a bean instance for this bean definition
* @throws BeansException if the instantiation failed * @throws BeansException if the instantiation failed
*/ */
Object instantiate( Object instantiate(RootBeanDefinition beanDefinition, String beanName, BeanFactory owner)
RootBeanDefinition beanDefinition, String beanName, BeanFactory owner) throws BeansException; throws BeansException;
/** /**
* Return an instance of the bean with the given name in this factory, * Return an instance of the bean with the given name in this factory,
* creating it via the given constructor. * creating it via the given constructor.
@ -59,10 +59,9 @@ public interface InstantiationStrategy {
* @return a bean instance for this bean definition * @return a bean instance for this bean definition
* @throws BeansException if the instantiation failed * @throws BeansException if the instantiation failed
*/ */
Object instantiate( Object instantiate(RootBeanDefinition beanDefinition, String beanName, BeanFactory owner,
RootBeanDefinition beanDefinition, String beanName, BeanFactory owner, Constructor<?> ctor, Object[] args) throws BeansException;
Constructor ctor, Object[] args) throws BeansException;
/** /**
* Return an instance of the bean with the given name in this factory, * Return an instance of the bean with the given name in this factory,
* creating it via the given factory method. * creating it via the given factory method.
@ -78,8 +77,7 @@ public interface InstantiationStrategy {
* @return a bean instance for this bean definition * @return a bean instance for this bean definition
* @throws BeansException if the instantiation failed * @throws BeansException if the instantiation failed
*/ */
Object instantiate( Object instantiate(RootBeanDefinition beanDefinition, String beanName, BeanFactory owner,
RootBeanDefinition beanDefinition, String beanName, BeanFactory owner,
Object factoryBean, Method factoryMethod, Object[] args) throws BeansException; Object factoryBean, Method factoryMethod, Object[] args) throws BeansException;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009 the original author or authors. * Copyright 2002-2010 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,12 +42,10 @@ import org.springframework.util.StringUtils;
*/ */
public class SimpleInstantiationStrategy implements InstantiationStrategy { public class SimpleInstantiationStrategy implements InstantiationStrategy {
public Object instantiate( public Object instantiate(RootBeanDefinition beanDefinition, String beanName, BeanFactory owner) {
RootBeanDefinition beanDefinition, String beanName, BeanFactory owner) {
// Don't override the class with CGLIB if no overrides. // Don't override the class with CGLIB if no overrides.
if (beanDefinition.getMethodOverrides().isEmpty()) { if (beanDefinition.getMethodOverrides().isEmpty()) {
Constructor constructorToUse = (Constructor) beanDefinition.resolvedConstructorOrFactoryMethod; Constructor<?> constructorToUse = (Constructor<?>) beanDefinition.resolvedConstructorOrFactoryMethod;
if (constructorToUse == null) { if (constructorToUse == null) {
final Class clazz = beanDefinition.getBeanClass(); final Class clazz = beanDefinition.getBeanClass();
if (clazz.isInterface()) { if (clazz.isInterface()) {
@ -60,7 +58,8 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy {
return clazz.getDeclaredConstructor((Class[]) null); return clazz.getDeclaredConstructor((Class[]) null);
} }
}); });
} else { }
else {
constructorToUse = clazz.getDeclaredConstructor((Class[]) null); constructorToUse = clazz.getDeclaredConstructor((Class[]) null);
} }
beanDefinition.resolvedConstructorOrFactoryMethod = constructorToUse; beanDefinition.resolvedConstructorOrFactoryMethod = constructorToUse;
@ -90,9 +89,8 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy {
"Method Injection not supported in SimpleInstantiationStrategy"); "Method Injection not supported in SimpleInstantiationStrategy");
} }
public Object instantiate( public Object instantiate(RootBeanDefinition beanDefinition, String beanName, BeanFactory owner,
RootBeanDefinition beanDefinition, String beanName, BeanFactory owner, final Constructor<?> ctor, Object[] args) {
final Constructor ctor, Object[] args) {
if (beanDefinition.getMethodOverrides().isEmpty()) { if (beanDefinition.getMethodOverrides().isEmpty()) {
if (System.getSecurityManager() != null) { if (System.getSecurityManager() != null) {
@ -117,16 +115,14 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy {
* the Method Injection specified in the given RootBeanDefinition. * the Method Injection specified in the given RootBeanDefinition.
* Instantiation should use the given constructor and parameters. * Instantiation should use the given constructor and parameters.
*/ */
protected Object instantiateWithMethodInjection( protected Object instantiateWithMethodInjection(RootBeanDefinition beanDefinition,
RootBeanDefinition beanDefinition, String beanName, BeanFactory owner, String beanName, BeanFactory owner, Constructor ctor, Object[] args) {
Constructor ctor, Object[] args) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Method Injection not supported in SimpleInstantiationStrategy"); "Method Injection not supported in SimpleInstantiationStrategy");
} }
public Object instantiate( public Object instantiate(RootBeanDefinition beanDefinition, String beanName, BeanFactory owner,
RootBeanDefinition beanDefinition, String beanName, BeanFactory owner,
Object factoryBean, final Method factoryMethod, Object[] args) { Object factoryBean, final Method factoryMethod, Object[] args) {
try { try {
@ -159,4 +155,5 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy {
"Factory method [" + factoryMethod + "] threw exception", ex.getTargetException()); "Factory method [" + factoryMethod + "] threw exception", ex.getTargetException());
} }
} }
}
}