You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by wg...@apache.org on 2005/07/06 19:27:43 UTC

svn commit: r209482 - in /jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader: ClasspathResourceLoader.java FileResourceLoader.java JarResourceLoader.java

Author: wglass
Date: Wed Jul  6 10:27:41 2005
New Revision: 209482

URL: http://svn.apache.org/viewcvs?rev=209482&view=rev
Log:
Changed resource loaders to use List, Map instead of Vector, Hashtable.  
Verified and removed unnecessary synchronization.  
http://issues.apache.org/bugzilla/show_bug.cgi?id=35558

Thanks, mailmur!


Modified:
    jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java
    jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
    jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java

Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java?rev=209482&r1=209481&r2=209482&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java Wed Jul  6 10:27:41 2005
@@ -67,6 +67,7 @@
  *  I have also tried it with a WAR deployment, and that seemed to
  *  work just fine.
  *  
+ * @author <a href="mailto:mailmur@yahoo.com">Aki Nieminen</a>
  * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
  * @version $Id$
  */
@@ -91,7 +92,7 @@
      * @throws ResourceNotFoundException if template not found
      *         in  classpath.
      */
-    public synchronized InputStream getResourceStream( String name )
+    public InputStream getResourceStream( String name )
         throws ResourceNotFoundException
     {
         InputStream result = null;

Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java?rev=209482&r1=209481&r2=209482&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java Wed Jul  6 10:27:41 2005
@@ -22,13 +22,14 @@
 import java.io.BufferedInputStream;
 import java.io.FileNotFoundException;
 
-import java.util.Hashtable;
-import java.util.Vector;
+import java.util.Collections;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.velocity.util.StringUtils;
-
 import org.apache.velocity.runtime.resource.Resource;
-
 import org.apache.velocity.exception.ResourceNotFoundException;
 
 import org.apache.commons.collections.ExtendedProperties;
@@ -36,6 +37,7 @@
 /**
  * A loader for templates stored on the file system.
  *
+ * @author <a href="mailto:mailmur@yahoo.com">Aki Nieminen</a> 
  * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  * @version $Id$
  */
@@ -44,25 +46,31 @@
     /**
      * The paths to search for templates.
      */
-    private Vector paths = null;
+    private List paths;
 
     /**
      * Used to map the path that a template was found on
      * so that we can properly check the modification
-     * times of the files.
+     * times of the files. This is synchronizedMap
+     * instance.
      */
-    private Hashtable templatePaths = new Hashtable();
+    private Map templatePaths;    
 
     public void init( ExtendedProperties configuration)
     {
         rsvc.info("FileResourceLoader : initialization starting.");
         
-        paths = configuration.getVector("path");
+        paths = new ArrayList();
+        paths.addAll( configuration.getVector("path") );
+        
+        /**
+         * Create synchronized map instance
+         */
+        templatePaths = Collections.synchronizedMap(new HashMap());
         
         /*
          *  lets tell people what paths we will be using
          */
-
         int sz = paths.size();
 
         for( int i=0; i < sz; i++)
@@ -82,7 +90,7 @@
      * @throws ResourceNotFoundException if template not found
      *         in the file template path.
      */
-    public synchronized InputStream getResourceStream(String templateName)
+    public InputStream getResourceStream(String templateName)
         throws ResourceNotFoundException
     {
         /*
@@ -132,8 +140,7 @@
                  * from so that we can check its modification
                  * time.
                  */
-
-                templatePaths.put(templateName, path);
+                templatePaths.put(templateName, path);                    
                 return inputStream;
             }                
         }

Modified: jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java?rev=209482&r1=209481&r2=209482&view=diff
==============================================================================
--- jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java (original)
+++ jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java Wed Jul  6 10:27:41 2005
@@ -20,6 +20,8 @@
 
 import java.util.Hashtable;
 import java.util.Vector;
+import java.util.Map;
+import java.util.HashMap;
 
 import org.apache.velocity.util.StringUtils;
 import org.apache.velocity.runtime.resource.Resource;
@@ -53,6 +55,7 @@
  *  org.apache.velocity.test.MultiLoaderTestCase class
  * </p>
  * 
+ * @author <a href="mailto:mailmur@yahoo.com">Aki Nieminen</a>
  * @author <a href="mailto:daveb@miceda-data.com">Dave Bryson</a>
  * @version $Id$
  */
@@ -63,14 +66,14 @@
      * Key = the entry *excluding* plain directories
      * Value = the JAR URL
      */
-    private Hashtable entryDirectory = new Hashtable(559);
+    private Map entryDirectory = new HashMap(559);
     
     /**
      * Maps JAR URLs to the actual JAR
      * Key = the JAR URL
      * Value = the JAR
      */
-    private Hashtable jarfiles = new Hashtable(89);
+    private Map jarfiles = new HashMap(89);
    
     /**
      * Called by Velocity to initialize the loader
@@ -79,6 +82,9 @@
     {
         rsvc.info("JarResourceLoader : initialization starting.");
 
+        // rest of Velocity engine still use legacy Vector 
+        // and Hashtable classes. Classes are implicitly
+        // synchronized even if we don't need it.
         Vector paths = configuration.getVector("path");
 
         /*
@@ -155,7 +161,7 @@
      * Copy all the entries into the entryDirectory
      * It will overwrite any duplicate keys.
      */
-    private synchronized void addEntries( Hashtable entries )
+    private void addEntries( Hashtable entries )
     {
         entryDirectory.putAll( entries );
     }
@@ -169,7 +175,7 @@
      * @throws ResourceNotFoundException if template not found
      *         in the file template path.
      */
-    public synchronized InputStream getResourceStream( String source )
+    public InputStream getResourceStream( String source )
         throws ResourceNotFoundException
     {
         InputStream results = null;
@@ -230,13 +236,3 @@
         return 0;
     }
 }
-
-
-
-
-
-
-
-
-
-



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org