You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by eh...@apache.org on 2007/06/03 04:13:54 UTC

svn commit: r543829 - in /incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket: resource/ resource/loader/ util/resource/locator/

Author: ehillenius
Date: Sat Jun  2 19:13:53 2007
New Revision: 543829

URL: http://svn.apache.org/viewvc?view=rev&rev=543829
Log:
doc fixes and got rid of the static get() methods

Modified:
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/IPropertiesFactory.java
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/PropertiesFactory.java
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/loader/ComponentStringResourceLoader.java
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/locator/ResourceStreamLocator.java

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/IPropertiesFactory.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/IPropertiesFactory.java?view=diff&rev=543829&r1=543828&r2=543829
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/IPropertiesFactory.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/IPropertiesFactory.java Sat Jun  2 19:13:53 2007
@@ -16,14 +16,22 @@
  */
 package org.apache.wicket.resource;
 
+import org.apache.wicket.util.value.ValueMap;
+
 
 /**
- * IPropertyiesFactory is not a 100% replacement for java.util.Properties as it
- * does not provide the same interface. But it serves kind of the same purpose
- * with Wicket specific features. E.g. besides Locale it take 'styles' and
- * 'variations' into account as well, it allows to register listeners which get
- * called when a property resource has changed and it allows to clear the
- * locally cached properties.
+ * Implementations are responsible for {@link #load(Class, String) locating}
+ * {@link Properties} objects, which are a thin wrapper around {@link ValueMap}
+ * and is used to locate localized messages.
+ * <p>
+ * The {@link #clearCache()} method should remove any cached references to
+ * properties objects used by an implementation, so that
+ * {@link #load(Class, String)} gets the freshest instance possible.
+ * </p>
+ * <p>
+ * {@link IPropertiesChangeListener Listeners} are related to cached properties
+ * and should be used to inform observers when sets of properties are reloaded.
+ * </p>
  * 
  * @see org.apache.wicket.resource.Properties
  * 
@@ -40,6 +48,11 @@
 	void addListener(final IPropertiesChangeListener listener);
 
 	/**
+	 * Remove all cached properties.
+	 */
+	abstract void clearCache();
+
+	/**
 	 * Load the properties associated with the path
 	 * 
 	 * @param clazz
@@ -49,9 +62,4 @@
 	 * @return The properties
 	 */
 	Properties load(final Class clazz, final String path);
-
-	/**
-	 * Remove all cached properties
-	 */
-	abstract void clearCache();
 }

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/PropertiesFactory.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/PropertiesFactory.java?view=diff&rev=543829&r1=543828&r2=543829
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/PropertiesFactory.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/PropertiesFactory.java Sat Jun  2 19:13:53 2007
@@ -32,7 +32,7 @@
 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.resource.locator.ResourceStreamLocator;
+import org.apache.wicket.util.resource.locator.IResourceStreamLocator;
 import org.apache.wicket.util.string.Strings;
 import org.apache.wicket.util.value.ValueMap;
 import org.apache.wicket.util.watch.ModificationWatcher;
@@ -41,13 +41,11 @@
 
 
 /**
- * Reloadable properties. It is not a 100% replacement for java.util.Properties
- * as it does not provide the same interface. But is serves kind of the same
- * purpose with Wicket specific features as it take Locale, style and variations
- * into account. PropertiesFactory loads and reloads the Properties and
- * maintaines a cache. Hence property files are loaded just once, but are
- * reloaded if a change to a property file has been detected (actually the cache
- * gets cleared which forces a reload on demand).
+ * Default implementation of {@link IPropertiesFactory} which uses the
+ * {@link IResourceStreamLocator} as defined by
+ * {@link IResourceSettings#getResourceStreamLocator()} to load the
+ * {@link Properties} objects. Depending on the settings, it will assign
+ * {@link ModificationWatcher}s to the loaded resources to support reloading.
  * 
  * @see org.apache.wicket.settings.IResourceSettings#getPropertiesFactory()
  * 
@@ -58,15 +56,15 @@
 	/** Log. */
 	private static final Logger log = LoggerFactory.getLogger(PropertiesFactory.class);
 
-	/** Cache for all property files loaded */
-	private final Map propertiesCache = new ConcurrentHashMap();
-
 	/**
 	 * Listeners will be invoked after changes to property file have been
 	 * detected
 	 */
 	private final List afterReloadListeners = new ArrayList();
 
+	/** Cache for all property files loaded */
+	private final Map propertiesCache = new ConcurrentHashMap();
+
 	/** Resource Settings */
 	private final IResourceSettings resourceSettings;
 
@@ -79,16 +77,6 @@
 	}
 
 	/**
-	 * Little helper
-	 * 
-	 * @return The properties factory registered with the application
-	 */
-	public static IPropertiesFactory get()
-	{
-		return Application.get().getResourceSettings().getPropertiesFactory();
-	}
-
-	/**
 	 * @see org.apache.wicket.resource.IPropertiesFactory#addListener(org.apache.wicket.resource.IPropertiesChangeListener)
 	 */
 	public void addListener(final IPropertiesChangeListener listener)
@@ -101,6 +89,14 @@
 	}
 
 	/**
+	 * @see org.apache.wicket.resource.IPropertiesFactory#clearCache()
+	 */
+	public final void clearCache()
+	{
+		propertiesCache.clear();
+	}
+
+	/**
 	 * 
 	 * @see org.apache.wicket.resource.IPropertiesFactory#load(java.lang.Class,
 	 *      java.lang.String)
@@ -120,7 +116,8 @@
 		}
 
 		// If not in the cache than try to load the resource stream
-		IResourceStream stream = ResourceStreamLocator.get().locate(clazz, path);
+		IResourceStream stream = Application.get().getResourceSettings().getResourceStreamLocator()
+				.locate(clazz, path);
 		if (stream != null)
 		{
 			// Load the properties from the stream
@@ -138,24 +135,6 @@
 	}
 
 	/**
-	 * For subclasses to get access to the cache
-	 * 
-	 * @return Map
-	 */
-	protected final Map getCache()
-	{
-		return this.propertiesCache;
-	}
-
-	/**
-	 * @see org.apache.wicket.resource.IPropertiesFactory#clearCache()
-	 */
-	public final void clearCache()
-	{
-		propertiesCache.clear();
-	}
-
-	/**
 	 * Helper method to do the actual loading of resources if required.
 	 * 
 	 * @param key
@@ -299,5 +278,15 @@
 
 		log.info("Loading properties files from " + resourceStream);
 		return loadPropertiesFile(key, resourceStream);
+	}
+
+	/**
+	 * For subclasses to get access to the cache
+	 * 
+	 * @return Map
+	 */
+	protected final Map getCache()
+	{
+		return this.propertiesCache;
 	}
 }

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/loader/ComponentStringResourceLoader.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/loader/ComponentStringResourceLoader.java?view=diff&rev=543829&r1=543828&r2=543829
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/loader/ComponentStringResourceLoader.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/loader/ComponentStringResourceLoader.java Sat Jun  2 19:13:53 2007
@@ -27,8 +27,8 @@
 import org.apache.wicket.markup.html.WebComponent;
 import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.resource.IPropertiesFactory;
 import org.apache.wicket.resource.Properties;
-import org.apache.wicket.resource.PropertiesFactory;
 import org.apache.wicket.util.resource.locator.ResourceNameIterator;
 import org.apache.wicket.util.string.Strings;
 import org.slf4j.Logger;
@@ -67,8 +67,8 @@
  * In addition to the above search order, each key will be pre-pended with the
  * relative path of the current component related to the component that is being
  * searched. E.g. assume a component hierarchy like page1.form1.input1 and your
- * are requesting a key named 'Required'. Wicket will search the
- * property in the following order:
+ * are requesting a key named 'Required'. Wicket will search the property in the
+ * following order:
  * 
  * <pre>
  *        page1.properties =&gt; form1.input1.Required
@@ -141,6 +141,10 @@
 			return null;
 		}
 
+		// Load the properties associated with the path
+		IPropertiesFactory propertiesFactory = Application.get().getResourceSettings()
+				.getPropertiesFactory();
+
 		while (true)
 		{
 			// Create the base path
@@ -151,10 +155,9 @@
 					"properties,xml");
 			while (iter.hasNext())
 			{
-				String newPath = (String) iter.next();
+				String newPath = (String)iter.next();
 
-				// Load the properties associated with the path
-				final Properties props = PropertiesFactory.get().load(clazz, newPath);
+				final Properties props = propertiesFactory.load(clazz, newPath);
 				if (props != null)
 				{
 					// Lookup the value
@@ -186,33 +189,6 @@
 	}
 
 	/**
-	 * Check the supplied class to see if it is one that we shouldn't bother
-	 * further searches up the class hierarchy for properties.
-	 * 
-	 * @param clazz
-	 *            The class to check
-	 * @return Whether to stop the search
-	 */
-	protected boolean isStopResourceSearch(final Class clazz)
-	{
-		if (clazz == null || clazz.equals(Object.class) || clazz.equals(Application.class))
-		{
-			return true;
-		}
-
-		// Stop at all html markup base classes
-		if (clazz.equals(WebPage.class) || clazz.equals(WebMarkupContainer.class)
-				|| clazz.equals(WebComponent.class))
-		{
-			return true;
-		}
-
-		// Stop at all wicket base classes
-		return clazz.equals(Page.class) || clazz.equals(MarkupContainer.class)
-				|| clazz.equals(Component.class);
-	}
-
-	/**
 	 * 
 	 * @see org.apache.wicket.resource.loader.IStringResourceLoader#loadStringResource(org.apache.wicket.Component,
 	 *      java.lang.String)
@@ -294,5 +270,32 @@
 			}
 		}
 		return searchStack;
+	}
+
+	/**
+	 * Check the supplied class to see if it is one that we shouldn't bother
+	 * further searches up the class hierarchy for properties.
+	 * 
+	 * @param clazz
+	 *            The class to check
+	 * @return Whether to stop the search
+	 */
+	protected boolean isStopResourceSearch(final Class clazz)
+	{
+		if (clazz == null || clazz.equals(Object.class) || clazz.equals(Application.class))
+		{
+			return true;
+		}
+
+		// Stop at all html markup base classes
+		if (clazz.equals(WebPage.class) || clazz.equals(WebMarkupContainer.class)
+				|| clazz.equals(WebComponent.class))
+		{
+			return true;
+		}
+
+		// Stop at all wicket base classes
+		return clazz.equals(Page.class) || clazz.equals(MarkupContainer.class)
+				|| clazz.equals(Component.class);
 	}
 }

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/locator/ResourceStreamLocator.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/locator/ResourceStreamLocator.java?view=diff&rev=543829&r1=543828&r2=543829
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/locator/ResourceStreamLocator.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/locator/ResourceStreamLocator.java Sat Jun  2 19:13:53 2007
@@ -31,8 +31,8 @@
  * Locate Wicket resource.
  * <p>
  * Contains the logic to locate a resource based on a path, a style (see
- * {@link org.apache.wicket.Session}), a locale and an extension string. The full filename
- * will be built like:
+ * {@link org.apache.wicket.Session}), a locale and an extension string. The
+ * full filename will be built like:
  * &lt;path&gt;_&lt;style&gt;_&lt;locale&gt;.&lt;extension&gt;.
  * <p>
  * Resource matches will be attempted in the following order:
@@ -61,18 +61,19 @@
 
 	/** If null, the application registered finder will be used */
 	private IResourceFinder finder;
-	
+
 	/**
 	 * Constructor
 	 */
 	public ResourceStreamLocator()
 	{
 	}
-	
+
 	/**
 	 * Constructor
 	 * 
-	 * @param finder resource finder
+	 * @param finder
+	 *            resource finder
 	 */
 	public ResourceStreamLocator(final IResourceFinder finder)
 	{
@@ -80,18 +81,35 @@
 	}
 
 	/**
-	 * Helper to get the Application registered resource stream locator
 	 * 
-	 * @return resource stream locator
+	 * @see org.apache.wicket.util.resource.locator.IResourceStreamLocator#locate(java.lang.Class,
+	 *      java.lang.String)
 	 */
-	public static IResourceStreamLocator get()
+	public IResourceStream locate(final Class clazz, final String path)
 	{
-		return Application.get().getResourceSettings().getResourceStreamLocator();
+		// First try with the resource finder registered with the application
+		// (allows for markup reloading)
+		IResourceStream stream = locateByResourceFinder(clazz, path);
+		if (stream != null)
+		{
+			return stream;
+		}
+
+		// Then search the resource on the classpath
+		stream = locateByClassLoader(clazz, path);
+		if (stream != null)
+		{
+			return stream;
+		}
+
+		return null;
 	}
 
 	/**
 	 * 
-	 * @see org.apache.wicket.util.resource.locator.IResourceStreamLocator#locate(java.lang.Class, java.lang.String, java.lang.String, java.util.Locale, java.lang.String)
+	 * @see org.apache.wicket.util.resource.locator.IResourceStreamLocator#locate(java.lang.Class,
+	 *      java.lang.String, java.lang.String, java.util.Locale,
+	 *      java.lang.String)
 	 */
 	public IResourceStream locate(final Class clazz, String path, final String style,
 			final Locale locale, final String extension)
@@ -101,37 +119,14 @@
 		ResourceNameIterator iter = new ResourceNameIterator(path, style, locale, extension);
 		while (iter.hasNext())
 		{
-			String newPath = (String) iter.next();
-			
+			String newPath = (String)iter.next();
+
 			IResourceStream stream = locate(clazz, newPath);
 			if (stream != null)
 			{
 				stream.setLocale(iter.getLocale());
 				return stream;
 			}
-		}
-
-		return null;
-	}
-
-	/**
-	 * 
-	 * @see org.apache.wicket.util.resource.locator.IResourceStreamLocator#locate(java.lang.Class, java.lang.String)
-	 */
-	public IResourceStream locate(final Class clazz, final String path)
-	{
-		// First try with the resource finder registered with the application (allows for markup reloading)
-		IResourceStream stream = locateByResourceFinder(clazz, path);
-		if (stream != null)
-		{
-			return stream;
-		}
-
-		// Then search the resource on the classpath
-		stream = locateByClassLoader(clazz, path);
-		if (stream != null)
-		{
-			return stream;
 		}
 
 		return null;