[jboss-cvs] JBossAS SVN: r81413 - in projects/jboss-reflect/branches/Branch_2_0/src: main/java/org/jboss/joinpoint/plugins and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 21 05:06:56 EST 2008


Author: alesj
Date: 2008-11-21 05:06:56 -0500 (Fri, 21 Nov 2008)
New Revision: 81413

Added:
   projects/jboss-reflect/branches/Branch_2_0/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java
Modified:
   projects/jboss-reflect/branches/Branch_2_0/src/main/java/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java
   projects/jboss-reflect/branches/Branch_2_0/src/main/java/org/jboss/joinpoint/plugins/Config.java
   projects/jboss-reflect/branches/Branch_2_0/src/test/java/org/jboss/test/beaninfo/test/BeanInfoTestSuite.java
Log:
Port JBREFLECT-41 to branch.

Modified: projects/jboss-reflect/branches/Branch_2_0/src/main/java/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java
===================================================================
--- projects/jboss-reflect/branches/Branch_2_0/src/main/java/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java	2008-11-21 10:06:41 UTC (rev 81412)
+++ projects/jboss-reflect/branches/Branch_2_0/src/main/java/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java	2008-11-21 10:06:56 UTC (rev 81413)
@@ -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
     *

Modified: projects/jboss-reflect/branches/Branch_2_0/src/main/java/org/jboss/joinpoint/plugins/Config.java
===================================================================
--- projects/jboss-reflect/branches/Branch_2_0/src/main/java/org/jboss/joinpoint/plugins/Config.java	2008-11-21 10:06:41 UTC (rev 81412)
+++ projects/jboss-reflect/branches/Branch_2_0/src/main/java/org/jboss/joinpoint/plugins/Config.java	2008-11-21 10:06:56 UTC (rev 81413)
@@ -40,6 +40,7 @@
  * Config utilities.
  *
  * @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 Config
@@ -266,10 +267,10 @@
       ConstructorInfo[] constructors = classInfo.getDeclaredConstructors();
       if (constructors != null)
       {
-         for (int i = 0; i < constructors.length; ++i)
+         for (ConstructorInfo constructor : constructors)
          {
-            if (equals(paramTypes, constructors[i].getParameterTypes()))
-               return constructors[i];
+            if (equals(paramTypes, constructor.getParameterTypes()))
+               return constructor;
          }
          throw new JoinpointException("Constructor not found " + classInfo.getName() + Arrays.asList(paramTypes) + " in " + Arrays.asList(constructors));
       }
@@ -311,10 +312,10 @@
       FieldInfo[] fields = classInfo.getDeclaredFields();
       if (fields != null)
       {
-         for (int i = 0; i < fields.length; ++i)
+         for (FieldInfo field : fields)
          {
-            if (name.equals(fields[i].getName()))
-               return fields[i];
+            if (name.equals(field.getName()))
+               return field;
          }
       }
       return null;
@@ -415,12 +416,12 @@
       MethodInfo[] methods = classInfo.getDeclaredMethods();
       if (methods != null)
       {
-         for (int i = 0; i < methods.length; ++i)
+         for (MethodInfo method : methods)
          {
-            if (name.equals(methods[i].getName()) &&
-                equals(paramTypes, methods[i].getParameterTypes()) &&
-                (strict == false || (methods[i].isStatic() == isStatic && methods[i].isPublic() == isPublic)))
-               return methods[i];
+            if (name.equals(method.getName()) &&
+                  equals(paramTypes, method.getParameterTypes()) &&
+                  (strict == false || (method.isStatic() == isStatic && method.isPublic() == isPublic)))
+               return method;
          }
       }
       return null;
@@ -449,17 +450,12 @@
    /**
     * A simple null and length check.
     *
-    * @param typeNames
-    * @param typeInfos
+    * @param typeNames the type names
+    * @param typeInfos the type infos
     * @return false if either argument is null or lengths differ, else true
     */
    protected static boolean simpleCheck(String[] typeNames, TypeInfo[] typeInfos)
    {
-      if (typeNames == null || typeInfos == null)
-      {
-         return false;
-      }
-      return typeNames.length == typeInfos.length;
+      return typeNames != null && typeInfos != null && typeNames.length == typeInfos.length;
    }
-
 }

Copied: projects/jboss-reflect/branches/Branch_2_0/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java (from rev 81411, projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java)
===================================================================
--- projects/jboss-reflect/branches/Branch_2_0/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java	                        (rev 0)
+++ projects/jboss-reflect/branches/Branch_2_0/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java	2008-11-21 10:06:56 UTC (rev 81413)
@@ -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

Modified: projects/jboss-reflect/branches/Branch_2_0/src/test/java/org/jboss/test/beaninfo/test/BeanInfoTestSuite.java
===================================================================
--- projects/jboss-reflect/branches/Branch_2_0/src/test/java/org/jboss/test/beaninfo/test/BeanInfoTestSuite.java	2008-11-21 10:06:41 UTC (rev 81412)
+++ projects/jboss-reflect/branches/Branch_2_0/src/test/java/org/jboss/test/beaninfo/test/BeanInfoTestSuite.java	2008-11-21 10:06:56 UTC (rev 81413)
@@ -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