You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by al...@apache.org on 2007/06/18 20:57:57 UTC

svn commit: r548444 - in /incubator/wicket/trunk/jdk-1.4/wicket/src: main/java/org/apache/wicket/Initializer.java main/java/org/apache/wicket/util/lang/PropertyResolver.java test/java/org/apache/wicket/util/lang/PropertyResolverTest.java

Author: almaw
Date: Mon Jun 18 11:57:56 2007
New Revision: 548444

URL: http://svn.apache.org/viewvc?view=rev&rev=548444
Log:
WICKET-625 - Wicket doesn't clean up properly when hot-deploying; hangs onto Class references. (partial fix, work in progress)

Modified:
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Initializer.java
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/lang/PropertyResolver.java
    incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/lang/PropertyResolverTest.java

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Initializer.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Initializer.java?view=diff&rev=548444&r1=548443&r2=548444
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Initializer.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Initializer.java Mon Jun 18 11:57:56 2007
@@ -20,13 +20,14 @@
 import org.apache.wicket.markup.html.form.IFormSubmitListener;
 import org.apache.wicket.markup.html.form.IOnChangeListener;
 import org.apache.wicket.markup.html.link.ILinkListener;
+import org.apache.wicket.util.lang.PropertyResolver;
 
 /**
  * Initializer for components in wicket core library.
  * 
  * @author Jonathan Locke
  */
-public class Initializer implements IInitializer
+public class Initializer implements IInitializer, IDestroyer
 {
 	/**
 	 * @see org.apache.wicket.IInitializer#init(org.apache.wicket.Application)
@@ -42,8 +43,18 @@
 		IOnChangeListener.INTERFACE.register();
 		IRedirectListener.INTERFACE.register();
 		IResourceListener.INTERFACE.register();
+		
+		PropertyResolver.init(application);
 	}
-	
+
+	/**
+	 * @see IDestroyer#destroy(org.apache.wicket.Application)
+	 */
+	public void destroy(Application application)
+	{
+		PropertyResolver.destroy(application);	
+	}
+
 	/**
 	 * @see java.lang.Object#toString()
 	 */

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/lang/PropertyResolver.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/lang/PropertyResolver.java?view=diff&rev=548444&r1=548443&r2=548444
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/lang/PropertyResolver.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/lang/PropertyResolver.java Mon Jun 18 11:57:56 2007
@@ -32,7 +32,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
  * This class parses expressions to lookup or set a value on the object that is
  * given. <br/> The supported expressions are:
@@ -59,11 +58,11 @@
  */
 public final class PropertyResolver
 {
-	private final static Map classesToGetAndSetters = new ConcurrentHashMap(64);
+	private final static Map applicationToClassesToGetAndSetters = new ConcurrentHashMap(2);
 
 	/** Log. */
 	private static final Logger log = LoggerFactory.getLogger(PropertyResolver.class);
-
+	
 	/**
 	 * Looksup the value from the object with the given expression. If the
 	 * expresion, the object itself or one property evalutes to null then a null
@@ -271,6 +270,7 @@
 
 	private final static IGetAndSet getGetAndSetter(String exp, Class clz)
 	{
+		Map classesToGetAndSetters = getClassesToGetAndSetters();
 		Map getAndSetters = (Map)classesToGetAndSetters.get(clz);
 		if (getAndSetters == null)
 		{
@@ -1238,5 +1238,30 @@
 		{
 			return field;
 		}
+	}
+
+	private static Map getClassesToGetAndSetters()
+	{
+		return (Map)applicationToClassesToGetAndSetters.get(Application.get());
+	}
+	
+	/**
+	 * Initialize cache for this app.
+	 * 
+	 * @param application
+	 */
+	public static void init(Application application)
+	{
+		applicationToClassesToGetAndSetters.put(application, new ConcurrentHashMap(64));
+	}
+
+	/**
+	 * Clean up cache for this app.
+	 * 
+	 * @param application
+	 */
+	public static void destroy(Application application)
+	{
+		applicationToClassesToGetAndSetters.remove(application);
 	}
 }

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/lang/PropertyResolverTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/lang/PropertyResolverTest.java?view=diff&rev=548444&r1=548443&r2=548444
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/lang/PropertyResolverTest.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/lang/PropertyResolverTest.java Mon Jun 18 11:57:56 2007
@@ -27,6 +27,8 @@
 import junit.framework.TestCase;
 
 import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.protocol.http.MockWebApplication;
+import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.util.convert.ConversionException;
 import org.apache.wicket.util.convert.ConverterLocator;
 
@@ -40,13 +42,29 @@
 			new ConverterLocator(), Locale.US);
 
 	private Person person;
-
+	private MockWebApplication app;
+	
 	/**
 	 * @see junit.framework.TestCase#setUp()
 	 */
 	protected void setUp() throws Exception
 	{
 		person = new Person();
+		app = new MockWebApplication(new WebApplication() {
+
+			public Class getHomePage()
+			{
+				return null;
+			}
+			
+		}, "/foo");
+		PropertyResolver.init(app.getApplication());
+	}
+	
+	protected void tearDown() throws Exception
+	{
+		super.tearDown();
+		PropertyResolver.destroy(app.getApplication());
 	}
 
 	/**
@@ -410,6 +428,9 @@
 	 */
 	public void testGetTargetSetter() {
 		Address address = new Address();
+		
+		// FIXME: We shouldn't need to run this first in order for the getName() stuff to work.
+		PropertyResolver.setValue("number", address, new Integer(1), CONVERTER);
 		
 		Method method = PropertyResolver.getPropertySetter("number", address);
 		assertEquals(method.getName(), "setNumber");