You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2012/01/21 16:43:26 UTC

svn commit: r1234350 - in /commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2: AccessibleObjectsRegistry.java MethodsRegistry.java

Author: simonetripodi
Date: Sat Jan 21 15:43:26 2012
New Revision: 1234350

URL: http://svn.apache.org/viewvc?rev=1234350&view=rev
Log:
replacing the methods registry with a more general AccessibleObjects registry, to cache Constructors as well

Added:
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/AccessibleObjectsRegistry.java
      - copied, changed from r1233590, commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/MethodsRegistry.java
Removed:
    commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/MethodsRegistry.java

Copied: commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/AccessibleObjectsRegistry.java (from r1233590, commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/MethodsRegistry.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/AccessibleObjectsRegistry.java?p2=commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/AccessibleObjectsRegistry.java&p1=commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/MethodsRegistry.java&r1=1233590&r2=1234350&rev=1234350&view=diff
==============================================================================
--- commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/MethodsRegistry.java (original)
+++ commons/sandbox/beanutils2/trunk/src/main/java/org/apache/commons/beanutils2/AccessibleObjectsRegistry.java Sat Jan 21 15:43:26 2012
@@ -21,37 +21,48 @@ import static java.util.Collections.sync
 
 import java.lang.ref.Reference;
 import java.lang.ref.WeakReference;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.Map;
 import java.util.WeakHashMap;
 
-final class MethodsRegistry
+final class AccessibleObjectsRegistry<AO extends AccessibleObject>
 {
 
-    private static final MethodsRegistry INSTANCE = new MethodsRegistry();
+    private static final AccessibleObjectsRegistry<Constructor<?>> CONSTRUCTORS_REGISTRY =
+                    new AccessibleObjectsRegistry<Constructor<?>>();
 
-    public static MethodsRegistry getInstance()
+    private static final AccessibleObjectsRegistry<Method> METHODS_REGISTRY = new AccessibleObjectsRegistry<Method>();
+
+    public static AccessibleObjectsRegistry<Constructor<?>> getConstructorsRegistry()
+    {
+        return CONSTRUCTORS_REGISTRY;
+    }
+
+    public static AccessibleObjectsRegistry<Method> getMethodsRegistry()
     {
-        return INSTANCE;
+        return METHODS_REGISTRY;
     }
 
-    private final Map<MethodDescriptor, WeakReference<Method>> cache =
-                    synchronizedMap( new WeakHashMap<MethodDescriptor, WeakReference<Method>>() );
+    private final Map<MethodDescriptor, WeakReference<AO>> cache =
+                    synchronizedMap( new WeakHashMap<MethodDescriptor, WeakReference<AO>>() );
 
-    private MethodsRegistry()
+    private AccessibleObjectsRegistry()
     {
         // this class cannot be instantiated
     }
 
-    public void putMethod( Method method, boolean exact, Class<?> cls, String methodName, Class<?>... paramTypes )
+    public void put( AO accessibleObject, boolean exact, Class<?> cls, String methodName, Class<?>... paramTypes )
     {
-        cache.put( new MethodDescriptor( exact, cls, methodName, paramTypes ), new WeakReference<Method>( method ) );
+        cache.put( new MethodDescriptor( exact, cls, methodName, paramTypes ),
+                   new WeakReference<AO>( accessibleObject ) );
     }
 
-    public Method getMethod( boolean exact, Class<?> cls, String methodName, Class<?>... paramTypes )
+    public AO get( boolean exact, Class<?> cls, String methodName, Class<?>... paramTypes )
     {
-        Reference<Method> methodReference = cache.get( new MethodDescriptor( exact, cls, methodName, paramTypes ) );
+        Reference<AO> methodReference = cache.get( new MethodDescriptor( exact, cls, methodName, paramTypes ) );
         if ( methodReference != null )
         {
             return methodReference.get();