[jboss-cvs] JBossAS SVN: r81411 - in projects/jboss-reflect/trunk/src: test/java/org/jboss/test/beaninfo/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 21 04:56:16 EST 2008


Author: alesj
Date: 2008-11-21 04:56:15 -0500 (Fri, 21 Nov 2008)
New Revision: 81411

Added:
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java
Modified:
   projects/jboss-reflect/trunk/src/main/java/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoTestSuite.java
Log:
[JBREFLECT-41]; fix bean info caching.

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java	2008-11-21 08:29:06 UTC (rev 81410)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java	2008-11-21 09:56:15 UTC (rev 81411)
@@ -47,16 +47,16 @@
 
 /**
  * A bean info factory.
- * 
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ *
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision$
  */
 public class AbstractBeanInfoFactory implements BeanInfoFactory
 {
    /** The cache */
-   protected Map<ClassLoader, Map<String, Map<BeanAccessMode, BeanInfo>>> cache = new WeakHashMap<ClassLoader, Map<String, Map<BeanAccessMode, BeanInfo>>>();
-   
+   protected Map<ClassInfo, Map<BeanAccessMode, BeanInfo>> cache = new WeakHashMap<ClassInfo, Map<BeanAccessMode, BeanInfo>>();
+
    protected static boolean isGetter(MethodInfo minfo)
    {
       String name = minfo.getName();
@@ -72,7 +72,7 @@
       }
       return false;
    }
-   
+
    protected static boolean isSetter(MethodInfo minfo)
    {
       String name = minfo.getName();
@@ -85,16 +85,16 @@
       }
       return false;
    }
-   
+
    protected static String getUpperPropertyName(String name)
    {
       int start = 3;
       if (name.startsWith("is"))
          start = 2;
-      
+
       return name.substring(start);
    }
-   
+
    protected static String getLowerPropertyName(String name)
    {
       // If the second character is upper case then we don't make
@@ -133,20 +133,13 @@
 
       synchronized (cache)
       {
-         ClassLoader cl = classAdapter.getClassLoader();
          ClassInfo classInfo = classAdapter.getClassInfo();
-         String className = classInfo.getName();
-         Map<String, Map<BeanAccessMode, BeanInfo>> map = cache.get(cl);
-         Map<BeanAccessMode, BeanInfo> modeMap = null;
-         if (map != null)
+         Map<BeanAccessMode, BeanInfo> modeMap = cache.get(classInfo);
+         if (modeMap != null)
          {
-            modeMap = map.get(className);
-            if (modeMap != null)
-            {
-               BeanInfo info = modeMap.get(accessMode);
-               if (info != null)
-                  return info;
-            }
+            BeanInfo info = modeMap.get(accessMode);
+            if (info != null)
+               return info;
          }
 
          Set<ConstructorInfo> constructors = getConstructors(classInfo);
@@ -159,15 +152,10 @@
          Set<EventInfo> events = getEvents(classInfo);
 
          BeanInfo result = createBeanInfo(classAdapter, accessMode, properties, constructors, methods, events);
-         if (map == null)
-         {
-            map = new WeakValueHashMap<String, Map<BeanAccessMode, BeanInfo>>();
-            cache.put(cl, map);
-         }
          if (modeMap == null)
          {
             modeMap = new WeakValueHashMap<BeanAccessMode, BeanInfo>();
-            map.put(className, modeMap);
+            cache.put(classInfo, modeMap);
          }
          modeMap.put(accessMode, result);
          return result;
@@ -176,7 +164,7 @@
 
    /**
     * Create the bean info
-    * 
+    *
     * @param classAdapter the class adapter
     * @param accessMode the access mode
     * @param properties the properties
@@ -195,10 +183,10 @@
    {
       return accessMode.create(this, classAdapter, properties, constructors, methods, events);
    }
-   
+
    /**
     * Get the constructors
-    * 
+    *
     * @param classInfo the class info
     * @return the constructors
     */
@@ -216,17 +204,17 @@
       }
       return result;
    }
-   
+
    /**
     * Get the methods
-    * 
+    *
     * @param classInfo the class info
     * @return the methods
     */
    protected Set<MethodInfo> getMethods(ClassInfo classInfo)
    {
       HashSet<MethodInfo> result = new HashSet<MethodInfo>();
-      
+
       while (classInfo != null)
       {
          MethodInfo[] minfos = classInfo.getDeclaredMethods();
@@ -238,16 +226,16 @@
                   result.add(minfos[i]);
             }
          }
-         
+
          classInfo = classInfo.getSuperclass();
       }
-      
+
       return result;
    }
-   
+
    /**
     * Get the properties for a bean
-    * 
+    *
     * @param methods the methods
     * @return the properties
     */
@@ -303,7 +291,7 @@
                }
             }
             String lowerName = getLowerPropertyName(name);
-            
+
             // Merge the annotations between the getters and setters
             AnnotationValue[] annotations = getter.getAnnotations();
             AnnotationValue[] setterAnnotations = null;
@@ -375,7 +363,7 @@
 
    /**
     * Get the properties for an annotation
-    * 
+    *
     * @param methods the methods
     * @return the properties
     */
@@ -397,7 +385,7 @@
       }
       return properties;
    }
-   
+
    /**
     * Get the events
     *

Copied: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java (from rev 79796, projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoUtilTestCase.java)
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java	2008-11-21 09:56:15 UTC (rev 81411)
@@ -0,0 +1,158 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.beaninfo.test;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.Test;
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.test.beaninfo.support.BeanInfoAnnotation;
+import org.jboss.test.beaninfo.support.BeanInfoEmpty;
+import org.jboss.test.beaninfo.support.BeanInfoGenericInterface;
+
+/**
+ * BeanInfoCache Test Case.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BeanInfoCacheTestCase extends AbstractBeanInfoTest
+{
+   public static Test suite()
+   {
+      return suite(BeanInfoCacheTestCase.class);
+   }
+
+   public BeanInfoCacheTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testBeanInfoCaching() throws Exception
+   {
+      assertBeanInfoCaching("Integer", List.class);
+      assertBeanInfoCaching("String", List.class);
+      assertBeanInfoCaching("Integer", Set.class);
+      assertBeanInfoCaching("String", Set.class);
+      assertBeanInfoCaching("Integer", BeanInfoGenericInterface.class);
+      assertBeanInfoCaching("String", BeanInfoGenericInterface.class);
+      assertBeanInfoCaching("", String.class);
+      assertBeanInfoCaching("", BeanInfoAnnotation.class);
+      assertBeanInfoCaching("", BeanInfoEmpty.class);
+   }
+
+   private void assertBeanInfoCaching(String string, Class<?> clazz) throws Exception
+   {
+      Type type = getType(string, clazz);
+      assertBeanInfoCaching(type);
+   }
+
+   private void assertBeanInfoCaching(Type type) throws Exception
+   {
+      assertClassInfo(type);
+      TypeInfo typeInfo = getConfiguration().getTypeInfo(type);
+      ClassInfo classInfo = assertInstanceOf(typeInfo, ClassInfo.class);
+      assertClassInfo(classInfo);
+      if (type instanceof Class)
+      {
+         Class<?> clazz = Class.class.cast(type);
+         assertClassInfo(classInfo, clazz.getName(), clazz.getClassLoader());
+      }
+   }
+
+   private void assertClassInfo(Type type)
+   {
+      TypeInfo typeInfo = getConfiguration().getTypeInfo(type);
+      ClassInfo classInfo = assertInstanceOf(typeInfo, ClassInfo.class);
+      assertClassInfo(classInfo);
+   }
+
+   private void assertClassInfo(ClassInfo typeInfo)
+   {
+      BeanInfo beanInfo = getConfiguration().getBeanInfo(typeInfo);
+      ClassInfo typeInfo2 = beanInfo.getClassInfo();
+      assertSame(typeInfo, typeInfo2);
+   }
+
+   private void assertClassInfo(ClassInfo typeInfo, String className, ClassLoader cl) throws Exception
+   {
+      BeanInfo beanInfo = getConfiguration().getBeanInfo(className, cl);
+      ClassInfo typeInfo2 = beanInfo.getClassInfo();
+      assertSame(typeInfo, typeInfo2);
+   }
+
+   @SuppressWarnings("unchecked")
+   protected Type getType(String type, Class<?> clazz) throws Exception
+   {
+      Method method = getClass().getDeclaredMethod("get" + type + clazz.getSimpleName());
+      return method.getGenericReturnType();
+   }
+
+   public List<Integer> getIntegerList()
+   {
+      return null;
+   }
+
+   public Set<Integer> getIntegerSet()
+   {
+      return null;
+   }
+
+   public List<String> getStringList()
+   {
+      return null;
+   }
+
+   public Set<String> getStringSet()
+   {
+      return null;
+   }
+
+   public BeanInfoGenericInterface<Integer> getIntegerBeanInfoGenericInterface()
+   {
+      return null;
+   }
+
+   public BeanInfoGenericInterface<String> getStringBeanInfoGenericInterface()
+   {
+      return null;
+   }
+
+   public String getString()
+   {
+      return null;
+   }
+
+   public BeanInfoAnnotation getBeanInfoAnnotation()
+   {
+      return null;
+   }
+
+   public BeanInfoEmpty getBeanInfoEmpty()
+   {
+      return null;
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoTestSuite.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoTestSuite.java	2008-11-21 08:29:06 UTC (rev 81410)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoTestSuite.java	2008-11-21 09:56:15 UTC (rev 81411)
@@ -44,6 +44,7 @@
 
       suite.addTest(BeanInfoUnitTestCase.suite());
       suite.addTest(BeanInfoUtilTestCase.suite());
+      suite.addTest(BeanInfoCacheTestCase.suite());
       suite.addTest(FieldAccessRestrictionTestCase.suite());
       suite.addTest(MethodAccessRestrictionTestCase.suite());
 




More information about the jboss-cvs-commits mailing list