You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jc...@apache.org on 2008/12/21 21:30:14 UTC
svn commit: r728490 -
/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/lang/PropertyResolver.java
Author: jcompagner
Date: Sun Dec 21 12:30:13 2008
New Revision: 728490
URL: http://svn.apache.org/viewvc?rev=728490&view=rev
Log:
fix for WICKET-1959
people can set there own IClassCache on the PropertyResolver if they want a special strategy like LRU cache on it
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/lang/PropertyResolver.java
Modified: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/lang/PropertyResolver.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/lang/PropertyResolver.java?rev=728490&r1=728489&r2=728490&view=diff
==============================================================================
--- wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/lang/PropertyResolver.java (original)
+++ wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/lang/PropertyResolver.java Sun Dec 21 12:30:13 2008
@@ -308,7 +308,7 @@
private final static IGetAndSet getGetAndSetter(String exp, Class clz)
{
- Map classesToGetAndSetters = getClassesToGetAndSetters();
+ IClassCache classesToGetAndSetters = getClassesToGetAndSetters();
Map getAndSetters = (Map)classesToGetAndSetters.get(clz);
if (getAndSetters == null)
{
@@ -1302,7 +1302,7 @@
}
}
- private static Map getClassesToGetAndSetters()
+ private static IClassCache getClassesToGetAndSetters()
{
Object key = null;
if (Application.exists())
@@ -1313,13 +1313,10 @@
{
key = PropertyResolver.class;
}
- Map result = (Map)applicationToClassesToGetAndSetters.get(key);
+ IClassCache result = (IClassCache)applicationToClassesToGetAndSetters.get(key);
if (result == null)
{
- // Don't synchronize this - Doesn't matter if we create two of them,
- // as it's only a cache and the first will go out of scope and get
- // GC'ed.
- applicationToClassesToGetAndSetters.put(key, result = new ConcurrentHashMap(64));
+ applicationToClassesToGetAndSetters.put(key, result = new DefaultClassCache());
}
return result;
}
@@ -1333,4 +1330,76 @@
{
applicationToClassesToGetAndSetters.remove(application);
}
+
+
+ /**
+ * Sets the {@link IClassCache} for the given application.
+ *
+ * If the Application is null then it will be the default if no application is found. So if you
+ * want to be sure that your {@link IClassCache} is handled in all situations then call this
+ * method twice with your implementations. One time for the application and the second time with
+ * null.
+ *
+ * @param application
+ * to use or null if the default must be set.
+ * @param classCache
+ */
+ public static void setClassCache(Application application, IClassCache classCache)
+ {
+ if (application != null)
+ {
+ applicationToClassesToGetAndSetters.put(application, classCache);
+ }
+ else
+ {
+ applicationToClassesToGetAndSetters.put(PropertyResolver.class, classCache);
+ }
+ }
+
+
+ /**
+ * An implementation of the class can be set on the
+ * {@link PropertyResolver#setClassCacheCreator(Application, IClassCache)} method for a specific
+ * application. This class cache can then be a special map with an eviction policy or do nothing
+ * if nothing should be cached for the given class.
+ *
+ * For example if you have proxy classes that are constantly created you could opt for not
+ * caching those at all or have a special Map implementation that will evict that class at a
+ * certain point.
+ *
+ * @author jcompagner
+ */
+ public static interface IClassCache
+ {
+ /**
+ * Put the class into the cache, or if that class shouldn't be cached do nothing.
+ *
+ * @param clz
+ * @param values
+ */
+ void put(Class clz, Map values);
+
+ /**
+ * Returns the class map from the cache.
+ *
+ * @param clz
+ * @return the map of the given class
+ */
+ Object get(Class clz);
+ }
+
+ private static class DefaultClassCache implements IClassCache
+ {
+ private final ConcurrentHashMap map = new ConcurrentHashMap(16);
+
+ public Object get(Class clz)
+ {
+ return map.get(clz);
+ }
+
+ public void put(Class clz, Map values)
+ {
+ map.put(clz, values);
+ }
+ }
}