jME 2.0 - ResourceLocatorTool "improvements" patch

Hi,



I've updated the ResourceLocatorTool in a few ways:



Changed to using enums for types instead of statics.

Throw an exception rather than return null if a resource can't be located.

Iterate through the locators in the order they are added rather than reverse order.

Updated Javadoc.

Little bit of refactoring (removed multiple return points, make sync block shorter).



To be honest I'm not sure if there was some design decision I'm not aware of that means not using enums and returning null is better that what I've changed it too.  These appear to be improvements to me so I've made a patch for the devs to look over and decide  :slight_smile:





Thanks,

Chris


Index: src/com/jme/util/resource/ResourceLocator.java
===================================================================
--- src/com/jme/util/resource/ResourceLocator.java   (revision 3870)
+++ src/com/jme/util/resource/ResourceLocator.java   (working copy)
@@ -42,12 +42,14 @@
 public interface ResourceLocator {
 
     /**
-     * Locates a resource according to the strategy of the reousrce locator implementation (subclass).
+     * Locates a resource according to the strategy of the resource locator implementation (subclass).
      * @see SimpleResourceLocator
      * @see MultiFormatResourceLocator
      * @param resourceName the name of the resource to locate; it this is a path it must be slash separated (no backslashes) 
-     * @return a URL for the resource, null if the resource was not found
+     * @return a URL for the resource.
+     * @throws UnableToLocateResourceException If the resource can't be located for
+     *         any reason.
      */
-    public URL locateResource(String resourceName);
+    public URL locateResource(String resourceName) throws UnableToLocateResourceException;
    
 }
Index: src/com/jme/util/resource/ResourceLocatorTool.java
===================================================================
--- src/com/jme/util/resource/ResourceLocatorTool.java   (revision 3870)
+++ src/com/jme/util/resource/ResourceLocatorTool.java   (working copy)
@@ -40,57 +40,111 @@
 import java.util.logging.Logger;
 
 /**
- * Manager class for locator utility classes used to find various assets. (XXX: Needs more documentation)
+ * Manager class for locator utility classes used to find various assets.
+ * Various {@link ResourceLocator resource locators} can be registered using
+ * the {@link #addResourceLocator(ResourceLocatorTool.Type, ResourceLocator) addResource}
+ * method.
+ * <p>
+ * Resources can then be found using the
+ * {@link #locateResource(ResourceLocatorTool.Type, String) locateResource}
+ * method, by simply passing in some unique identifier for the resource.
+ * How the resource is actually located is dependent on the resource locators
+ * registered for the given {@link ResourceLocatorTool.Type resource type}. 
+ * Using resource types allows several different resources to use the same
+ * identifier, which in turn allows for easier resource management
+ * (i.e. allowing models and their textures to have the same name).
+ * </p><p>
+ * This completely decouples locating resources making moving resources during
+ * design, testing and 'live' phases the application simple and easy.
+ * </p>
  *
  * @author Joshua Slack
+ * @see    com.jme.util.resource.ResourceLocator
  */
-
 public class ResourceLocatorTool {
+    /** Classes logger */
     private static final Logger logger = Logger.getLogger(ResourceLocatorTool.class
             .getName());
 
-    public static final String TYPE_TEXTURE = "texture";
-    public static final String TYPE_MODEL = "model";
-    public static final String TYPE_PARTICLE = "particle";
-    public static final String TYPE_AUDIO = "audio";
-    public static final String TYPE_SHADER = "shader";
+    /** Map of registered {@link ResourceLocator resource locators} */
+    private static final Map<ResourceLocatorTool.Type, ArrayList<ResourceLocator>> locatorMap =
+            new HashMap<ResourceLocatorTool.Type, ArrayList<ResourceLocator>>();
 
-    private static final Map<String, ArrayList<ResourceLocator>> locatorMap = new HashMap<String, ArrayList<ResourceLocator>>();
-
-    public static URL locateResource(String resourceType, String resourceName) {
-        if (resourceName == null) {
-            return null;
-        }
+   
+    /**
+     * Attempts to locates a resource with the given name using the registered
+     * resource locators.
+     * <p>
+     * All the locators for the given resource type are iterated through in the
+     * order they are added to this tool.  As soon as any one of these locators
+     * finds the resource it's location is returned without checking the
+     * remaining locators.
+     * </p><p>
+     * If none of the locators find the resource then a last ditch effort is
+     * made to use Java's built in classpath resource locating features.  If this
+     * fails then a <code>UnableToLocateResourceException</code> is thrown.
+     * </p>
+     *
+     * @param  resourceType The type of resource to locate.
+     * @param  resourceName The unique identifier of the resource to locate.
+     * @return A URL pointing to the location of the given resource.
+     * @throws UnableToLocateResourceException If the resource can't be located
+     *         for any reason.
+     * @see    #addResourceLocator(com.jme.util.resource.ResourceLocatorTool.Type, ResourceLocator)
+     * @see    #removeResourceLocator(com.jme.util.resource.ResourceLocatorTool.Type, ResourceLocator)
+     * @see    java.lang.Class#getResource(String)
+     */
+    public static URL locateResource(ResourceLocatorTool.Type resourceType, String resourceName)
+        throws UnableToLocateResourceException
+    {
+        URL resourceURL = null;
+       
         synchronized (locatorMap) {
             ArrayList<ResourceLocator> bases = locatorMap.get(resourceType);
+           
             if (bases != null) {
-                for (int i = bases.size(); --i >= 0; ) {
-                    ResourceLocator loc = bases.get(i);
-                    URL rVal = loc.locateResource(resourceName);
-                    if (rVal != null) {
-                        return rVal;
+                for (ResourceLocator loc : bases) {
+                    resourceURL = loc.locateResource(resourceName);
+                    if (resourceURL != null) {
+                        break;
                     }
                 }
             }
-            // last resort...
+        }
+       
+        // last resort...
+        if (null == resourceURL) {
             try {
-                URL u = ResourceLocatorTool.class.getResource(resourceName);
-                if (u != null) {
-                    return u;
-                }
+                resourceURL = ResourceLocatorTool.class.getResource(resourceName);
+
             } catch (Exception e) {
                 logger.logp(Level.WARNING, ResourceLocatorTool.class.getName(),
-                        "locateResource(String, String)", e.getMessage(), e);
+                        "locateResource(ResourceLocatorTool.Type, String)", e.getMessage(), e);
             }
+        }
 
-            logger.warning("Unable to locate: "+resourceName);
-            return null;
+        if (null == resourceURL) {
+            throw new UnableToLocateResourceException("resource " + resourceName + " not found!");
         }
+       
+        return resourceURL;
     }
 
-    public static void addResourceLocator(String resourceType,
-            ResourceLocator locator) {
-        if (locator == null) return;
+    /**
+     * Adds a resource locator to this tool.  Added resource locators will
+     * be used by the <code>locateResource</code> method to locate resources.
+     *
+     * @param resourceType The type of resources the locator can find.
+     * @param locator The locator to add, if <code>null</code> is passed then
+     *        nothing is added and no action is taken.
+     * @see   #removeResourceLocator(com.jme.util.resource.ResourceLocatorTool.Type, ResourceLocator)
+     * @see   #locateResource(com.jme.util.resource.ResourceLocatorTool.Type, String)
+     */
+    public static void addResourceLocator(ResourceLocatorTool.Type resourceType, ResourceLocator locator) {
+        if (locator == null) {
+            return;
+        }
+       
         synchronized (locatorMap) {
             ArrayList<ResourceLocator> bases = locatorMap.get(resourceType);
             if (bases == null) {
@@ -104,14 +158,54 @@
         }
     }
 
-    public static boolean removeResourceLocator(String resourceType,
-            ResourceLocator locator) {
+    /**
+     * Removes a resource locator from this tool.  Once a locator is removed
+     * it will no longer to be used to locate resources.
+     *
+     * @param  resourceType The type of resources the locator can find, used to
+     *         make sure the correct locator is removed.
+     * @param  locator The locator to remove, if <code>null</code> is passed
+     *         then nothing is removed and no action is taken.
+     * @return <code>true</code> if the locator is removed, <code>false</code>
+     *         otherwise.
+     * @see    #addResourceLocator(com.jme.util.resource.ResourceLocatorTool.Type, ResourceLocator)
+     * @see    #locateResource(com.jme.util.resource.ResourceLocatorTool.Type, String)
+     */
+    public static boolean removeResourceLocator(ResourceLocatorTool.Type resourceType, ResourceLocator locator) {
+        boolean removed = false;
+       
         synchronized (locatorMap) {
             ArrayList<ResourceLocator> bases = locatorMap.get(resourceType);
-            if (bases == null) {
-                return false;
+            if (bases != null) {
+                removed = bases.remove(locator);
             }
-            return bases.remove(locator);
         }
+       
+        return removed;
     }
+   
+   
+   
+   
+   
+    /**
+     * Enum of possible resource types locators can be registered against.
+     *
+     * @see ResourceLocatorTool
+     */
+    public enum Type {
+        /** Texture and image files such as png, jpeg, dds etc */
+        TEXTURE,
+        /** Model files such as collada, md5 etc */
+        MODEL,
+        /** Particle files saved using the ren particle editor */
+        PARTICLE,
+        /** Audio files such as mp3, ogg, midi etc */
+        AUDIO,
+        /** Shader files */
+        SHADER,
+        /** Property files such as properties, conf etc */
+        PROPERTIES;
+    }
+   
 }
Index: src/com/jme/util/TextureKey.java
===================================================================
--- src/com/jme/util/TextureKey.java   (revision 3870)
+++ src/com/jme/util/TextureKey.java   (working copy)
@@ -134,7 +134,7 @@
         String file = capsule.readString("file", null);
         if (file != null)
             location = ResourceLocatorTool.locateResource(
-                    ResourceLocatorTool.TYPE_TEXTURE, URLDecoder.decode(file,
+                    ResourceLocatorTool.Type.TEXTURE, URLDecoder.decode(file,
                             "UTF-8"));
         if (location == null && protocol != null && host != null
                 && file != null) {
Index: src/com/jme/util/TextureManager.java
===================================================================
--- src/com/jme/util/TextureManager.java   (revision 3870)
+++ src/com/jme/util/TextureManager.java   (working copy)
@@ -188,7 +188,7 @@
      */
     private static URL getTextureURL(String file) {
         URL url = ResourceLocatorTool.locateResource(
-                ResourceLocatorTool.TYPE_TEXTURE, file);
+                ResourceLocatorTool.Type.TEXTURE, file);
         if (url == null) {
             try {
                 url = new URL("file:" + file);
Index: src/com/jmex/audio/openal/OpenALSystem.java
===================================================================
--- src/com/jmex/audio/openal/OpenALSystem.java   (revision 3870)
+++ src/com/jmex/audio/openal/OpenALSystem.java   (working copy)
@@ -209,7 +209,7 @@
     @Override
     public OpenALAudioTrack createAudioTrack(String resourceStr, boolean stream) {
         synchronized(this) {
-            URL resource = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_AUDIO, resourceStr);
+            URL resource = ResourceLocatorTool.locateResource(ResourceLocatorTool.Type.AUDIO, resourceStr);
             if (resource == null) {
                 logger.warning("Could not locate audio file: "+resourceStr);
                 return null;
Index: src/com/jmex/model/collada/ColladaImporter.java
===================================================================
--- src/com/jmex/model/collada/ColladaImporter.java   (revision 3870)
+++ src/com/jmex/model/collada/ColladaImporter.java   (working copy)
@@ -2477,7 +2477,7 @@
     private void loadTexture(TextureState ts, String filename,
             ColladaMaterial mat, int index) {
         URL textureURL = ResourceLocatorTool.locateResource(
-                ResourceLocatorTool.TYPE_TEXTURE, filename);
+                ResourceLocatorTool.Type.TEXTURE, filename);
        
         if (textureURL != null) {
             Texture t0 = TextureManager.loadTexture(textureURL, mat
Index: src/com/jmex/model/collada/ColladaToJme.java
===================================================================
--- src/com/jmex/model/collada/ColladaToJme.java   (revision 3870)
+++ src/com/jmex/model/collada/ColladaToJme.java   (working copy)
@@ -62,7 +62,7 @@
         outDir = args[2];
        
         ResourceLocatorTool.addResourceLocator(
-                ResourceLocatorTool.TYPE_TEXTURE, new SimpleResourceLocator(
+                ResourceLocatorTool.Type.TEXTURE, new SimpleResourceLocator(
                         new File(texDir).toURI()));
        
         //make sure outDir exists:
Index: src/com/jmex/model/converters/AseToJme.java
===================================================================
--- src/com/jmex/model/converters/AseToJme.java   (revision 3870)
+++ src/com/jmex/model/converters/AseToJme.java   (working copy)
@@ -343,7 +343,7 @@
 
                     String filename =
                         materials.get(j).file;
-                    URL fileURL = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, filename);
+                    URL fileURL = ResourceLocatorTool.locateResource(ResourceLocatorTool.Type.TEXTURE, filename);
                     if (fileURL == null) {
                         logger.warning("Could not locate texture: " + filename);
                         continue;
Index: src/com/jmex/model/converters/maxutils/MaterialBlock.java
===================================================================
--- src/com/jmex/model/converters/maxutils/MaterialBlock.java   (revision 3870)
+++ src/com/jmex/model/converters/maxutils/MaterialBlock.java   (working copy)
@@ -215,7 +215,7 @@
    private Texture createTexture(TextureChunk tc) {
       Texture t = new Texture2D();
       URL url = ResourceLocatorTool.locateResource(
-                ResourceLocatorTool.TYPE_TEXTURE, tc.texName);
+                ResourceLocatorTool.Type.TEXTURE, tc.texName);
         if (url != null) {
             t.setImageLocation(url.toString());
         }
Index: src/com/jmex/model/converters/MilkToJme.java
===================================================================
--- src/com/jmex/model/converters/MilkToJme.java   (revision 3870)
+++ src/com/jmex/model/converters/MilkToJme.java   (working copy)
@@ -203,7 +203,7 @@
             String texFile=cutAtNull(tempChar);
             if (texFile.length()!=0){
                 URL texURL = ResourceLocatorTool.locateResource(
-                        ResourceLocatorTool.TYPE_TEXTURE, texFile);
+                        ResourceLocatorTool.Type.TEXTURE, texFile);
                 if (texURL != null) {
                     texState = DisplaySystem.getDisplaySystem().getRenderer()
                     .createTextureState();
Index: src/com/jmex/model/util/ModelLoader.java
===================================================================
--- src/com/jmex/model/util/ModelLoader.java   (revision 3870)
+++ src/com/jmex/model/util/ModelLoader.java   (working copy)
@@ -132,8 +132,8 @@
 
                     // Add to resource locator
                     SimpleResourceLocator locator = new SimpleResourceLocator(file.getParentFile().toURI());
-                    ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, locator);
-                    ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_MODEL, locator);
+                    ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.Type.TEXTURE, locator);
+                    ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.Type.MODEL, locator);
 
                     final Node modelNode = loadModel(file);
                     outputElapsed(time);
@@ -308,7 +308,7 @@
             props = ( p == null ? new String[0] : p );
         }
         public void setFile( String file ) { this.file = file; }
-        protected URL getURL() { return ResourceLocatorTool.locateResource( ResourceLocatorTool.TYPE_MODEL, file ); }
+        protected URL getURL() { return ResourceLocatorTool.locateResource( ResourceLocatorTool.Type.MODEL, file ); }
         public Node call() throws Exception
         {
             if( converter == null )

Index: src/jmetest/effects/RenParticleEditor.java
===================================================================
--- src/jmetest/effects/RenParticleEditor.java   (revision 3870)
+++ src/jmetest/effects/RenParticleEditor.java   (working copy)
@@ -623,7 +623,7 @@
         File file = fileChooser.getSelectedFile();
         prefs.put("particle_dir", file.getParent().toString());
         SimpleResourceLocator locator = new SimpleResourceLocator(file.getParentFile().toURI());
-        ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, locator);
+        ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.Type.TEXTURE, locator);
         try {
             Spatial obj = (Spatial) BinaryImporter.getInstance().load(file);
             if (obj instanceof Node && !(obj instanceof ParticleSystem)) {
@@ -660,7 +660,7 @@
                     + "': " + e, "File Error", JOptionPane.ERROR_MESSAGE);
             logger.log(Level.WARNING, "Couldn't open '" + file, e);
         } finally {
-            ResourceLocatorTool.removeResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, locator);
+            ResourceLocatorTool.removeResourceLocator(ResourceLocatorTool.Type.TEXTURE, locator);
         }
     }
 
@@ -672,7 +672,7 @@
         File file = fileChooser.getSelectedFile();
         prefs.put("particle_dir", file.getParent());
         SimpleResourceLocator locator = new SimpleResourceLocator(file.getParentFile().toURI());
-        ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, locator);
+        ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.Type.TEXTURE, locator);
         try {
             Spatial obj = (Spatial) BinaryImporter.getInstance().load(file);
             int lidx = particleNode.getQuantity();
@@ -708,7 +708,7 @@
                     + "': " + e, "File Error", JOptionPane.ERROR_MESSAGE);
             logger.log(Level.WARNING, "Couldn't open '" + file, e);
         } finally {
-            ResourceLocatorTool.removeResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, locator);
+            ResourceLocatorTool.removeResourceLocator(ResourceLocatorTool.Type.TEXTURE, locator);
         }
     }
 
Index: src/jmetest/effects/TestProjectedTexture.java
===================================================================
--- src/jmetest/effects/TestProjectedTexture.java   (revision 3870)
+++ src/jmetest/effects/TestProjectedTexture.java   (working copy)
@@ -117,7 +117,7 @@
       try {
             try {
                 ResourceLocatorTool.addResourceLocator(
-                        ResourceLocatorTool.TYPE_TEXTURE,
+                        ResourceLocatorTool.Type.TEXTURE,
                         new SimpleResourceLocator(TestProjectedTexture.class
                                 .getClassLoader().getResource(
                                         "jmetest/data/model/msascii/")));
Index: src/jmetest/intersection/TestPick.java
===================================================================
--- src/jmetest/intersection/TestPick.java   (revision 3870)
+++ src/jmetest/intersection/TestPick.java   (working copy)
@@ -88,7 +88,7 @@
    protected void simpleInitGame() {
         try {
             ResourceLocatorTool.addResourceLocator(
-                    ResourceLocatorTool.TYPE_TEXTURE,
+                    ResourceLocatorTool.Type.TEXTURE,
                     new SimpleResourceLocator(TestPick.class
                             .getClassLoader().getResource(
                                     "jmetest/data/model/msascii/")));
Index: src/jmetest/renderer/loader/TestASEJmeWrite.java
===================================================================
--- src/jmetest/renderer/loader/TestASEJmeWrite.java   (revision 3870)
+++ src/jmetest/renderer/loader/TestASEJmeWrite.java   (working copy)
@@ -64,7 +64,7 @@
     protected void simpleInitGame() {
         try {
             ResourceLocatorTool.addResourceLocator(
-                    ResourceLocatorTool.TYPE_TEXTURE,
+                    ResourceLocatorTool.Type.TEXTURE,
                     new SimpleResourceLocator(TestFireMilk.class
                             .getClassLoader()
                             .getResource("jmetest/data/model/")));
Index: src/jmetest/renderer/loader/TestColladaLoading.java
===================================================================
--- src/jmetest/renderer/loader/TestColladaLoading.java   (revision 3870)
+++ src/jmetest/renderer/loader/TestColladaLoading.java   (working copy)
@@ -55,7 +55,7 @@
     protected void simpleInitGame() {
         try {
             ResourceLocatorTool.addResourceLocator(
-                    ResourceLocatorTool.TYPE_TEXTURE,
+                    ResourceLocatorTool.Type.TEXTURE,
                     new SimpleResourceLocator(TestColladaLoading.class
                             .getClassLoader().getResource(
                                     "jmetest/data/model/collada/")));
Index: src/jmetest/renderer/loader/TestFireMilk.java
===================================================================
--- src/jmetest/renderer/loader/TestFireMilk.java   (revision 3870)
+++ src/jmetest/renderer/loader/TestFireMilk.java   (working copy)
@@ -94,12 +94,12 @@
 
     try {
         ResourceLocatorTool.addResourceLocator(
-                ResourceLocatorTool.TYPE_TEXTURE,
+                ResourceLocatorTool.Type.TEXTURE,
                 new SimpleResourceLocator(TestFireMilk.class
                         .getClassLoader().getResource(
                                 "jmetest/data/model/msascii/")));
         ResourceLocatorTool.addResourceLocator(
-                ResourceLocatorTool.TYPE_TEXTURE,
+                ResourceLocatorTool.Type.TEXTURE,
                 new SimpleResourceLocator(TestFireMilk.class
                         .getClassLoader().getResource(
                                 "jmetest/data/texture/")));
Index: src/jmetest/renderer/loader/TestMilkJmeWrite.java
===================================================================
--- src/jmetest/renderer/loader/TestMilkJmeWrite.java   (revision 3870)
+++ src/jmetest/renderer/loader/TestMilkJmeWrite.java   (working copy)
@@ -64,7 +64,7 @@
     protected void simpleInitGame() {
         try {
             ResourceLocatorTool.addResourceLocator(
-                    ResourceLocatorTool.TYPE_TEXTURE,
+                    ResourceLocatorTool.Type.TEXTURE,
                     new SimpleResourceLocator(TestMilkJmeWrite.class
                             .getClassLoader().getResource(
                                     "jmetest/data/model/msascii/")));
Index: src/jmetest/renderer/loader/TestNormalmap.java
===================================================================
--- src/jmetest/renderer/loader/TestNormalmap.java   (revision 3870)
+++ src/jmetest/renderer/loader/TestNormalmap.java   (working copy)
@@ -183,7 +183,7 @@
 
         try {
             ResourceLocatorTool.addResourceLocator(
-                    ResourceLocatorTool.TYPE_TEXTURE,
+                    ResourceLocatorTool.Type.TEXTURE,
                     new SimpleResourceLocator(TestMipMaps.class
                             .getClassLoader().getResource(
                                     "jmetest/data/model/collada/")));
Index: src/jmetest/renderer/TestAutoClodMesh.java
===================================================================
--- src/jmetest/renderer/TestAutoClodMesh.java   (revision 3870)
+++ src/jmetest/renderer/TestAutoClodMesh.java   (working copy)
@@ -113,7 +113,7 @@
    
     try {
         ResourceLocatorTool.addResourceLocator(
-                ResourceLocatorTool.TYPE_TEXTURE,
+                ResourceLocatorTool.Type.TEXTURE,
                 new SimpleResourceLocator(TestAutoClodMesh.class
                         .getClassLoader()
                         .getResource("jmetest/data/model/")));
Index: src/jmetest/renderer/TestCameraMan.java
===================================================================
--- src/jmetest/renderer/TestCameraMan.java   (revision 3870)
+++ src/jmetest/renderer/TestCameraMan.java   (working copy)
@@ -111,7 +111,7 @@
   protected void simpleInitGame() {
       try {
         ResourceLocatorTool.addResourceLocator(
-                    ResourceLocatorTool.TYPE_TEXTURE,
+                    ResourceLocatorTool.Type.TEXTURE,
                     new SimpleResourceLocator(TestCameraMan.class
                             .getClassLoader().getResource(
                                     "jmetest/data/model/msascii/")));
Index: src/jmetest/renderer/TestClodMesh.java
===================================================================
--- src/jmetest/renderer/TestClodMesh.java   (revision 3870)
+++ src/jmetest/renderer/TestClodMesh.java   (working copy)
@@ -158,7 +158,7 @@
    
     try {
         ResourceLocatorTool.addResourceLocator(
-                ResourceLocatorTool.TYPE_TEXTURE,
+                ResourceLocatorTool.Type.TEXTURE,
                 new SimpleResourceLocator(TestClodMesh.class
                         .getClassLoader()
                         .getResource("jmetest/data/model/")));
Index: src/jmetest/renderer/TestCubeMapGLSL.java
===================================================================
--- src/jmetest/renderer/TestCubeMapGLSL.java   (revision 3870)
+++ src/jmetest/renderer/TestCubeMapGLSL.java   (working copy)
@@ -128,7 +128,7 @@
 
         try {
             ResourceLocatorTool.addResourceLocator(
-                    ResourceLocatorTool.TYPE_TEXTURE,
+                    ResourceLocatorTool.Type.TEXTURE,
                     new SimpleResourceLocator(TestColladaLoading.class
                             .getClassLoader().getResource(
                                     "jmetest/data/texture/")));
Index: src/jmetest/renderer/TestMipMaps.java
===================================================================
--- src/jmetest/renderer/TestMipMaps.java   (revision 3870)
+++ src/jmetest/renderer/TestMipMaps.java   (working copy)
@@ -147,7 +147,7 @@
     private void setupModel() {
         try {
             ResourceLocatorTool.addResourceLocator(
-                    ResourceLocatorTool.TYPE_TEXTURE,
+                    ResourceLocatorTool.Type.TEXTURE,
                     new SimpleResourceLocator(TestMipMaps.class
                             .getClassLoader().getResource(
                                     "jmetest/data/model/collada/")));
Index: src/jmetest/renderer/TestSharedNode.java
===================================================================
--- src/jmetest/renderer/TestSharedNode.java   (revision 3870)
+++ src/jmetest/renderer/TestSharedNode.java   (working copy)
@@ -91,7 +91,7 @@
 
         try {
             ResourceLocatorTool.addResourceLocator(
-                    ResourceLocatorTool.TYPE_TEXTURE,
+                    ResourceLocatorTool.Type.TEXTURE,
                     new SimpleResourceLocator(TestSharedNode.class
                             .getClassLoader().getResource(
                                     "jmetest/data/model/msascii/")));
Index: src/jmetest/renderer/TestSpatialLookAt.java
===================================================================
--- src/jmetest/renderer/TestSpatialLookAt.java   (revision 3870)
+++ src/jmetest/renderer/TestSpatialLookAt.java   (working copy)
@@ -217,7 +217,7 @@
         Node camBox;
         try {
             ResourceLocatorTool.addResourceLocator(
-                    ResourceLocatorTool.TYPE_TEXTURE,
+                    ResourceLocatorTool.Type.TEXTURE,
                     new SimpleResourceLocator(TestSpatialLookAt.class
                             .getClassLoader().getResource(
                                     "jmetest/data/model/msascii/")));
Index: src/jmetest/renderer/TestSphere.java
===================================================================
--- src/jmetest/renderer/TestSphere.java   (revision 3870)
+++ src/jmetest/renderer/TestSphere.java   (working copy)
@@ -96,12 +96,12 @@
    
     try {
         MultiFormatResourceLocator loc2 = new MultiFormatResourceLocator(new File("c:/").toURI(), ".jpg", ".png", ".tga");
-        ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, loc2);
+        ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.Type.TEXTURE, loc2);
     } catch (Exception e) {
         e.printStackTrace();
     }
    
-    URL u = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, "/model/grass.gif");
+    URL u = ResourceLocatorTool.locateResource(ResourceLocatorTool.Type.TEXTURE, "/model/grass.gif");
     System.err.println("FOUND URL: "+u);
    
     TextureState ts = display.getRenderer().createTextureState();
Index: src/jmetest/scalarfields/TestMetaballs.java
===================================================================
--- src/jmetest/scalarfields/TestMetaballs.java   (revision 3870)
+++ src/jmetest/scalarfields/TestMetaballs.java   (working copy)
@@ -99,7 +99,7 @@
 
         try {
             ResourceLocatorTool.addResourceLocator(
-                    ResourceLocatorTool.TYPE_TEXTURE,
+                    ResourceLocatorTool.Type.TEXTURE,
                     new SimpleResourceLocator( getClass().getResource(
                             "/jmetest/data/texture/" ) ) );
         } catch ( Exception e ) {
Index: src/jmetest/TutorialGuide/HelloIntersection.java
===================================================================
--- src/jmetest/TutorialGuide/HelloIntersection.java   (revision 3870)
+++ src/jmetest/TutorialGuide/HelloIntersection.java   (working copy)
@@ -161,7 +161,7 @@
 
         try {
             ResourceLocatorTool.addResourceLocator(
-                    ResourceLocatorTool.TYPE_TEXTURE,
+                    ResourceLocatorTool.Type.TEXTURE,
                     new SimpleResourceLocator(getClass().getResource(
                             "/jmetest/data/texture/")));
         } catch (Exception e) {

Using enums instead of statics is a 2.0 goal so let's hope an SVN writing dev will pick this up…

Very good start, can the close coupling of ResourceLocator and the Map member locatorMap be either bridged or separated. Simple reason is that it would be nice to allow custom entries or easy changes to the API. Prime example is the defiition of type includes PROPERTIES, some may like an XML file, some may like a blah …


I will have a look at this this week.  The reason that types were not made enums was precisely so that customs types were simple to add.

Type is just a nice way of looking for the same unique identifier in different places.  You could stick all you resources in the same folder and find them all using the TEXTURE type.



That's why I didn't think using an enum would be that bad, and since jME is open source we'll be able to add any popular ones directly to the core if they really are needed.

IMO returning null is preferable to throwing an exception because generating an exception is quite heavy  and I'd like to be able to use ResourceLocatorTool to determine if a certain resource exists at all (and in a fast way),

Naturally, if ResourceLocatorTool already determines if a resource exists by catching exceptions rather than preventing them my preference might be a bit more work than just to replace "throw new NoSuchElementException(…)" with "return null" at one point.

I just stumbled about this patch and saw its not committed yet.

Someone wants to review this patch and maybe put it in?



Maybe the Enum name could be changed to ResourceType tho, to make it a bit shorter and more general applicable.

I would also just return null and not throw an exception if a resource is not found.



Also the JavaDocs are a fine addition.