From 325d8834e35cf1458b290746fb95db6a97d9cf19 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 14 May 2013 21:20:24 +0200 Subject: [PATCH] Polishing --- .../aspectj/AspectJWeaverMessageHandler.java | 26 +++++++++---------- .../AbstractAutowireCapableBeanFactory.java | 25 +++++++----------- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJWeaverMessageHandler.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJWeaverMessageHandler.java index 678c87baebf..018c2dc1c7f 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJWeaverMessageHandler.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJWeaverMessageHandler.java @@ -45,43 +45,41 @@ public class AspectJWeaverMessageHandler implements IMessageHandler { private static final String AJ_ID = "[AspectJ] "; - private static final Log LOGGER = LogFactory.getLog("AspectJ Weaver"); + private static final Log logger = LogFactory.getLog("AspectJ Weaver"); public boolean handleMessage(IMessage message) throws AbortException { Kind messageKind = message.getKind(); - if (messageKind == IMessage.DEBUG) { - if (LOGGER.isDebugEnabled() || LOGGER.isTraceEnabled()) { - LOGGER.debug(makeMessageFor(message)); + if (logger.isDebugEnabled()) { + logger.debug(makeMessageFor(message)); return true; } } - else if ((messageKind == IMessage.INFO) || (messageKind == IMessage.WEAVEINFO)) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info(makeMessageFor(message)); + else if (messageKind == IMessage.INFO || messageKind == IMessage.WEAVEINFO) { + if (logger.isInfoEnabled()) { + logger.info(makeMessageFor(message)); return true; } } else if (messageKind == IMessage.WARNING) { - if (LOGGER.isWarnEnabled()) { - LOGGER.warn(makeMessageFor(message)); + if (logger.isWarnEnabled()) { + logger.warn(makeMessageFor(message)); return true; } } else if (messageKind == IMessage.ERROR) { - if (LOGGER.isErrorEnabled()) { - LOGGER.error(makeMessageFor(message)); + if (logger.isErrorEnabled()) { + logger.error(makeMessageFor(message)); return true; } } else if (messageKind == IMessage.ABORT) { - if (LOGGER.isFatalEnabled()) { - LOGGER.fatal(makeMessageFor(message)); + if (logger.isFatalEnabled()) { + logger.fatal(makeMessageFor(message)); return true; } } - return false; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java index 16c9e5be741..f4a1a498f3b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java @@ -171,6 +171,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac setParentBeanFactory(parentBeanFactory); } + /** * Set the instantiation strategy to use for creating bean instances. * Default is CglibSubclassingInstantiationStrategy. @@ -261,7 +262,6 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac this.ignoredDependencyInterfaces.add(ifc); } - @Override public void copyConfigurationFrom(ConfigurableBeanFactory otherFactory) { super.copyConfigurationFrom(otherFactory); @@ -346,7 +346,6 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac else { Object bean; final BeanFactory parent = this; - if (System.getSecurityManager() != null) { bean = AccessController.doPrivileged(new PrivilegedAction() { public Object run() { @@ -357,7 +356,6 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac else { bean = getInstantiationStrategy().instantiate(bd, null, parent); } - populateBean(beanClass.getName(), bd, new BeanWrapperImpl(bean)); return bean; } @@ -687,22 +685,19 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac // Try to obtain the FactoryBean's object type without instantiating it at all. BeanDefinition fbDef = getBeanDefinition(factoryBeanName); if (fbDef instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) fbDef).hasBeanClass()) { - Class fbClass = ((AbstractBeanDefinition) fbDef).getBeanClass(); - if (ClassUtils.isCglibProxyClass(fbClass)) { - // CGLIB subclass methods hide generic parameters. look at the superclass. - fbClass = fbClass.getSuperclass(); - } + // CGLIB subclass methods hide generic parameters; look at the original user class. + Class fbClass = ClassUtils.getUserClass(((AbstractBeanDefinition) fbDef).getBeanClass()); // Find the given factory method, taking into account that in the case of // @Bean methods, there may be parameters present. ReflectionUtils.doWithMethods(fbClass, - new ReflectionUtils.MethodCallback() { - public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { - if (method.getName().equals(factoryMethodName) && - FactoryBean.class.isAssignableFrom(method.getReturnType())) { - objectType.value = GenericTypeResolver.resolveReturnTypeArgument(method, FactoryBean.class); + new ReflectionUtils.MethodCallback() { + public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { + if (method.getName().equals(factoryMethodName) && + FactoryBean.class.isAssignableFrom(method.getReturnType())) { + objectType.value = GenericTypeResolver.resolveReturnTypeArgument(method, FactoryBean.class); + } } - } - }); + }); if (objectType.value != null) { return objectType.value; }