Author: jdonnerstag
Date: Sat Dec 11 17:22:32 2010
New Revision: 1044681

URL: http://svn.apache.org/viewvc?rev=1044681&view=rev
Log:
SpringBeanLocator getBeanNameOfClass move if-test outside of while-loop  
WICKET-3245

Modified:
    
wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java

Modified: 
wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java?rev=1044681&r1=1044680&r2=1044681&view=diff
==============================================================================
--- 
wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java
 (original)
+++ 
wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java
 Sat Dec 11 17:22:32 2010
@@ -48,7 +48,7 @@ public class SpringBeanLocator implement
        private static final long serialVersionUID = 1L;
 
        // Weak reference so we don't hold up WebApp classloader garbage 
collection.
-       private transient WeakReference<Class< ? >> beanTypeCache;
+       private transient WeakReference<Class<?>> beanTypeCache;
 
        private final String beanTypeName;
 
@@ -66,7 +66,7 @@ public class SpringBeanLocator implement
         * @param locator
         *            spring context locator
         */
-       public SpringBeanLocator(final Class< ? > beanType, final 
ISpringContextLocator locator)
+       public SpringBeanLocator(final Class<?> beanType, final 
ISpringContextLocator locator)
        {
                this(null, beanType, locator);
        }
@@ -81,8 +81,8 @@ public class SpringBeanLocator implement
         * @param locator
         *            spring context locator
         */
-       public SpringBeanLocator(final String beanName, final Class< ? > 
beanType,
-                       final ISpringContextLocator locator)
+       public SpringBeanLocator(final String beanName, final Class<?> beanType,
+               final ISpringContextLocator locator)
        {
                if (locator == null)
                {
@@ -93,7 +93,7 @@ public class SpringBeanLocator implement
                        throw new IllegalArgumentException("[beanType] argument 
cannot be null");
                }
 
-               beanTypeCache = new WeakReference<Class< ? >>(beanType);
+               beanTypeCache = new WeakReference<Class<?>>(beanType);
                beanTypeName = beanType.getName();
                springContextLocator = locator;
                this.beanName = beanName;
@@ -111,23 +111,23 @@ public class SpringBeanLocator implement
         * @throws IllegalStateException
         * @return spring name of the bean
         */
-       private final String getBeanNameOfClass(final ApplicationContext ctx, 
final Class< ? > clazz)
+       private final String getBeanNameOfClass(final ApplicationContext ctx, 
final Class<?> clazz)
        {
                // get the list of all possible matching beans
-               List<String> names = new 
ArrayList<String>(Arrays.asList(BeanFactoryUtils
-                               .beanNamesForTypeIncludingAncestors(ctx, 
clazz)));
-               Iterator<String> it = names.iterator();
+               List<String> names = new ArrayList<String>(
+                       
Arrays.asList(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(ctx, clazz)));
 
                // filter out beans that are not candidates for autowiring
-               while (it.hasNext())
+               if (ctx instanceof AbstractApplicationContext)
                {
-                       final String possibility = it.next();
-                       if (ctx instanceof AbstractApplicationContext)
+                       Iterator<String> it = names.iterator();
+                       while (it.hasNext())
                        {
-                               BeanDefinition beanDef = 
getBeanDefinition(((AbstractApplicationContext)ctx)
-                                               .getBeanFactory(), possibility);
+                               String possibility = it.next();
+                               BeanDefinition beanDef = getBeanDefinition(
+                                       
((AbstractApplicationContext)ctx).getBeanFactory(), possibility);
                                if 
(BeanFactoryUtils.isFactoryDereference(possibility) ||
-                                               
possibility.startsWith("scopedTarget.") || !beanDef.isAutowireCandidate())
+                                       possibility.startsWith("scopedTarget.") 
|| !beanDef.isAutowireCandidate())
                                {
                                        it.remove();
                                }
@@ -145,8 +145,8 @@ public class SpringBeanLocator implement
                                List<String> primaries = new 
ArrayList<String>();
                                for (String name : names)
                                {
-                                       BeanDefinition beanDef = 
getBeanDefinition(((AbstractApplicationContext)ctx)
-                                                       .getBeanFactory(), 
name);
+                                       BeanDefinition beanDef = 
getBeanDefinition(
+                                               
((AbstractApplicationContext)ctx).getBeanFactory(), name);
                                        if (beanDef instanceof 
AbstractBeanDefinition)
                                        {
                                                if 
(((AbstractBeanDefinition)beanDef).isPrimary())
@@ -176,8 +176,14 @@ public class SpringBeanLocator implement
                }
        }
 
+       /**
+        * 
+        * @param beanFactory
+        * @param name
+        * @return BeanDefinition
+        */
        private BeanDefinition 
getBeanDefinition(ConfigurableListableBeanFactory beanFactory,
-                       String name)
+               String name)
        {
                if (beanFactory.containsBeanDefinition(name))
                {
@@ -214,18 +220,18 @@ public class SpringBeanLocator implement
        /**
         * @return bean class this locator is configured with
         */
-       public Class< ? > getBeanType()
+       public Class<?> getBeanType()
        {
-               Class< ? > clazz = beanTypeCache == null ? null : 
beanTypeCache.get();
+               Class<?> clazz = beanTypeCache == null ? null : 
beanTypeCache.get();
                if (clazz == null)
                {
-                       beanTypeCache = new WeakReference<Class< ? >>(clazz = 
WicketObjects
-                                       .resolveClass(beanTypeName));
+                       beanTypeCache = new WeakReference<Class<?>>(
+                               clazz = 
WicketObjects.resolveClass(beanTypeName));
                        if (clazz == null)
                        {
                                throw new RuntimeException("SpringBeanLocator 
could not find class [" +
-                                               beanTypeName + "] needed to 
locate the [" +
-                                               ((beanName != null) ? 
(beanName) : ("bean name not specified")) + "] bean");
+                                       beanTypeName + "] needed to locate the 
[" +
+                                       ((beanName != null) ? (beanName) : 
("bean name not specified")) + "] bean");
                        }
                }
                return clazz;
@@ -248,6 +254,10 @@ public class SpringBeanLocator implement
                }
        }
 
+       /**
+        * 
+        * @return ApplicationContext
+        */
        private ApplicationContext getSpringContext()
        {
                final ApplicationContext context = 
springContextLocator.getSpringContext();
@@ -291,7 +301,7 @@ public class SpringBeanLocator implement
         * @throws IllegalStateException
         * @return found bean
         */
-       private final Object lookupSpringBean(ApplicationContext ctx, Class< ? 
> clazz)
+       private final Object lookupSpringBean(ApplicationContext ctx, Class<?> 
clazz)
        {
                return lookupSpringBean(ctx, getBeanNameOfClass(ctx, clazz), 
clazz);
        }
@@ -309,7 +319,7 @@ public class SpringBeanLocator implement
         * @throws IllegalStateException
         * @return found bean
         */
-       private static Object lookupSpringBean(ApplicationContext ctx, String 
name, Class< ? > clazz)
+       private static Object lookupSpringBean(ApplicationContext ctx, String 
name, Class<?> clazz)
        {
                try
                {
@@ -318,7 +328,7 @@ public class SpringBeanLocator implement
                catch (NoSuchBeanDefinitionException e)
                {
                        throw new IllegalStateException("bean with name [" + 
name + "] and class [" +
-                                       clazz.getName() + "] not found");
+                               clazz.getName() + "] not found");
                }
        }
 
@@ -332,7 +342,7 @@ public class SpringBeanLocator implement
                {
                        SpringBeanLocator other = (SpringBeanLocator)obj;
                        return beanTypeName.equals(other.beanTypeName) &&
-                                       Objects.equal(beanName, other.beanName);
+                               Objects.equal(beanName, other.beanName);
                }
                return false;
        }


Reply via email to