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/05 14:00:18 UTC

svn commit: r544458 - /incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ResourceReference.java

Author: almaw
Date: Tue Jun  5 05:00:17 2007
New Revision: 544458

URL: http://svn.apache.org/viewvc?view=rev&rev=544458
Log:
Weak references for scopes, so we can be garbage collected on redeploy.

Modified:
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ResourceReference.java

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ResourceReference.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ResourceReference.java?view=diff&rev=544458&r1=544457&r2=544458
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ResourceReference.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/ResourceReference.java Tue Jun  5 05:00:17 2007
@@ -16,6 +16,7 @@
  */
 package org.apache.wicket;
 
+import java.lang.ref.WeakReference;
 import java.util.Locale;
 
 import org.apache.wicket.markup.html.PackageResource;
@@ -66,7 +67,7 @@
 	private transient Resource resource;
 
 	/** The scope of the named resource */
-	private final Class scope;
+	private final WeakReference scope;
 
 	/** The style of the resource */
 	private String style;
@@ -105,7 +106,7 @@
 	 */
 	public ResourceReference(final Class scope, final String name, Locale locale, String style)
 	{
-		this.scope = scope;
+		this.scope = new WeakReference(scope);
 		this.name = name;
 		this.locale = locale;
 		this.style = style;
@@ -138,7 +139,7 @@
 		{
 			SharedResources sharedResources = application.getSharedResources();
 			// Try to get resource from Application repository
-			resource = sharedResources.get(scope, name, locale, style, true);
+			resource = sharedResources.get(getScope(), name, locale, style, true);
 
 			// Not available yet?
 			if (resource == null)
@@ -149,13 +150,13 @@
 				{
 					// If lazy-init did not create resource with correct locale
 					// and style then we should default the resource
-					resource = sharedResources.get(scope, name, locale, style, false);
+					resource = sharedResources.get(getScope(), name, locale, style, false);
 					if (resource == null)
 					{
 						// still null? try to see whether it is a package
 						// resource that should
 						// be lazily loaded
-						PackageResource packageResource = PackageResource.get(scope, name);
+						PackageResource packageResource = PackageResource.get(getScope(), name);
 						// will throw an exception if not found, so if we come
 						// here, it was found
 						sharedResources.add(name, packageResource);
@@ -163,7 +164,7 @@
 				}
 
 				// Share through application
-				sharedResources.add(scope, name, locale, style, resource);
+				sharedResources.add(getScope(), name, locale, style, resource);
 			}
 		}
 	}
@@ -176,7 +177,7 @@
 		if (obj instanceof ResourceReference)
 		{
 			ResourceReference that = (ResourceReference)obj;
-			return Objects.equal(this.scope.getName(), that.scope.getName()) && Objects.equal(this.name, that.name)
+			return Objects.equal(this.getScope().getName(), that.getScope().getName()) && Objects.equal(this.name, that.name)
 					&& Objects.equal(this.locale, that.locale)
 					&& Objects.equal(this.style, that.style);
 		}
@@ -217,7 +218,7 @@
 	 */
 	public final Class getScope()
 	{
-		return scope;
+		return (Class)scope.get();
 	}
 
 	/**
@@ -227,7 +228,7 @@
 	{
 		Application application = Application.get();
 		bind(application);
-		return application.getSharedResources().resourceKey(scope, name, locale, style);
+		return application.getSharedResources().resourceKey(getScope(), name, locale, style);
 	}
 
 	/**