Author: jcompagner
Date: Fri Mar 7 15:28:32 2008
New Revision: 634862
URL: http://svn.apache.org/viewvc?rev=634862&view=rev
Log:
WICKET-1370
Modified:
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/MarkupCache.java
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/MarkupResourceStream.java
Modified:
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/MarkupCache.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/MarkupCache.java?rev=634862&r1=634861&r2=634862&view=diff
==============================================================================
---
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/MarkupCache.java
(original)
+++
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/MarkupCache.java
Fri Mar 7 15:28:32 2008
@@ -56,7 +56,10 @@
private static final Logger log =
LoggerFactory.getLogger(MarkupCache.class);
/** Map of markup tags by class (exactly what is in the file). */
- private final ICache markupCache;
+ private final ICache /* <String(LocationString),Markup> */markupCache;
+
+ /** Map of markup tags by class (exactly what is in the file). */
+ private final ICache /* <String(CacheKey),String(LocationString)>
*/markupKeyCache;
/** The markup cache key provider used by MarkupCache */
private IMarkupCacheKeyProvider markupCacheKeyProvider;
@@ -80,6 +83,7 @@
this.application = application;
markupCache = newCacheImplementation();
+ markupKeyCache = newCacheImplementation();
if (markupCache == null)
{
throw new WicketRuntimeException("The map used to cache
markup must not be null");
@@ -92,6 +96,7 @@
public final void clear()
{
markupCache.clear();
+ markupKeyCache.clear();
}
/**
@@ -101,6 +106,7 @@
public void shutdown()
{
markupCache.shutdown();
+ markupKeyCache.shutdown();
}
/**
@@ -120,10 +126,11 @@
// Remove the markup and any other markup which depends on it
// (inheritance)
- Markup markup = (Markup)markupCache.get(cacheKey);
+ String locationString = (String)markupKeyCache.get(cacheKey);
+ Markup markup = (Markup)markupCache.get(locationString);
if (markup != null)
{
- markupCache.remove(cacheKey);
+ markupCache.remove(locationString);
// In practice markup inheritance has probably not more
than 3 or 4
// levels. And since markup reloading is only enabled
in development
@@ -145,7 +152,9 @@
if (resourceData != null)
{
String baseCacheKey =
resourceData.getResource().getCacheKey();
- if
(markupCache.get(baseCacheKey) == null)
+ String baseLocationString =
(String)markupKeyCache.get(baseCacheKey);
+ if (baseLocationString != null
&&
+
markupCache.get(baseLocationString) == null)
{
if
(log.isDebugEnabled())
{
@@ -177,7 +186,9 @@
{
MarkupResourceStream
resourceStream = (MarkupResourceStream)modifiable;
String resourceCacheKey =
resourceStream.getCacheKey();
- if
(markupCache.containsKey(resourceCacheKey) == false)
+ String resouceLocationString =
(String)markupKeyCache.get(resourceCacheKey);
+ if (resouceLocationString !=
null &&
+
markupCache.containsKey(resouceLocationString) == false)
{
iter.remove();
}
@@ -342,19 +353,19 @@
* Put the markup into the cache if cacheKey is not null and the cache
does not yet contain the
* cacheKey. Return the markup stored in the cache if cacheKey is
present already.
*
- * @param cacheKey
+ * @param locationString
* If null, than ignore the cache
* @param markup
* @return markup The markup provided, except if the cacheKey already
existed in the cache, than
* the markup from the cache is provided.
*/
- protected Markup putIntoCache(final String cacheKey, Markup markup)
+ protected Markup putIntoCache(final String locationString, Markup
markup)
{
- if (cacheKey != null)
+ if (locationString != null)
{
- if (markupCache.containsKey(cacheKey) == false)
+ if (markupCache.containsKey(locationString) == false)
{
- markupCache.put(cacheKey, markup);
+ markupCache.put(locationString, markup);
}
else
{
@@ -365,7 +376,7 @@
// loading in avg takes less than 100ms, it is
not really an
// issue. For consistency reasons however, we
should always use
// the markup loaded first which is why it gets
returned.
- markup = (Markup)markupCache.get(cacheKey);
+ markup =
(Markup)markupCache.get(locationString);
}
}
return markup;
@@ -385,7 +396,11 @@
{
if (cacheKey != null)
{
- return (Markup)markupCache.get(cacheKey);
+ String locationString =
(String)markupKeyCache.get(cacheKey);
+ if (locationString != null)
+ {
+ return (Markup)markupCache.get(locationString);
+ }
}
return null;
}
@@ -406,13 +421,21 @@
final MarkupResourceStream markupResourceStream, final boolean
enforceReload)
{
String cacheKey = markupResourceStream.getCacheKey();
+ String locationString = markupResourceStream.locationAsString();
+ if (locationString == null)
+ {
+ // set the cache key as location string, because
location string
+ // couldn't be resolved.
+ locationString = cacheKey;
+ }
try
{
Markup markup = getMarkupLoader().loadMarkup(container,
markupResourceStream, null,
enforceReload);
// add the markup to the cache.
- return putIntoCache(cacheKey, markup);
+ markupKeyCache.put(cacheKey, locationString);
+ return putIntoCache(locationString, markup);
}
catch (ResourceStreamNotFoundException e)
{
@@ -450,6 +473,20 @@
final MarkupResourceStream markupResourceStream, final boolean
enforceReload)
{
final String cacheKey = markupResourceStream.getCacheKey();
+ // get the location String
+ String locationString = markupResourceStream.locationAsString();
+ if (locationString == null)
+ {
+ // set the cache key as location string, because
location string
+ // couldn't be resolved.
+ locationString = cacheKey;
+ }
+ Markup markup = (Markup)markupCache.get(locationString);
+ if (markup != null)
+ {
+ markupKeyCache.put(cacheKey, locationString);
+ return markup;
+ }
if (cacheKey != null)
{
// Watch file in the future
Modified:
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/MarkupResourceStream.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/MarkupResourceStream.java?rev=634862&r1=634861&r2=634862&view=diff
==============================================================================
---
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/MarkupResourceStream.java
(original)
+++
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/MarkupResourceStream.java
Fri Mar 7 15:28:32 2008
@@ -21,6 +21,7 @@
import java.util.Locale;
import org.apache.wicket.util.lang.Classes;
+import org.apache.wicket.util.resource.IFixedLocationResourceStream;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
import org.apache.wicket.util.time.Time;
@@ -31,7 +32,7 @@
*
* @author Juergen Donnerstag
*/
-public class MarkupResourceStream implements IResourceStream
+public class MarkupResourceStream implements IResourceStream,
IFixedLocationResourceStream
{
private static final long serialVersionUID = 1846489965076612828L;
@@ -77,7 +78,7 @@
* @param markupClass
*/
public MarkupResourceStream(final IResourceStream resourceStream,
- final ContainerInfo containerInfo, final Class
markupClass)
+ final ContainerInfo containerInfo, final Class markupClass)
{
this.resourceStream = resourceStream;
this.containerInfo = containerInfo;
@@ -87,6 +88,15 @@
{
throw new IllegalArgumentException("Parameter
'resourceStream' must not be null");
}
+ }
+
+ public String locationAsString()
+ {
+ if (resourceStream instanceof IFixedLocationResourceStream)
+ {
+ return
((IFixedLocationResourceStream)resourceStream).locationAsString();
+ }
+ return null;
}
/**