OSDN Git Service

Use BinaryClassLoader for XML persistence, so that just like our .jme binary files...
authorblaine.dev <blaine.dev@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Mon, 3 Aug 2009 03:29:15 +0000 (03:29 +0000)
committerblaine.dev <blaine.dev@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Mon, 3 Aug 2009 03:29:15 +0000 (03:29 +0000)
Most of the files modified in this commit are just comments clarifying tricky, non-intuitive, or troublesome behavior.

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@4560 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

src/com/jme/util/TextureKey.java
src/com/jme/util/export/binary/BinaryClassLoader.java
src/com/jme/util/export/binary/BinaryLoaderModule.java
src/com/jme/util/export/xml/DOMInputCapsule.java
src/com/jme/util/export/xml/DOMOutputCapsule.java
src/com/jme/util/export/xml/XMLImporter.java
src/com/jme/util/resource/AbsoluteResourceLocator.java
src/com/jme/util/resource/RelativeResourceLocator.java

index 9298acb..c0adf64 100644 (file)
@@ -52,6 +52,12 @@ import com.jme.util.resource.ResourceLocatorTool;
  * @version $Id$
  */
 final public class TextureKey implements Savable {
+    /* There is a problem with the way that URLS are resolved in this class.
+     * The URL should only be resolved to read from them (and the resolved URL
+     * not saved).
+     * Resolving it at read() time means we have to save rooted URL.  If the
+     * read in URL is relative, we losing the benefits of that relativity and
+     * if we later write(), we will save 'location' with an absolute URL. */
 
     protected URL location = null;
     protected boolean flipped;
@@ -204,4 +210,4 @@ final public class TextureKey implements Savable {
                 + fileType;
         return x;
     }
-}
\ No newline at end of file
+}
index 9dc6026..7ce0b8d 100644 (file)
@@ -56,8 +56,12 @@ import com.jme.util.export.binary.modules.BinaryWireframeStateModule;
 import com.jme.util.export.binary.modules.BinaryZBufferStateModule;
 
 /**
- * @author mpowell
+ * This class is mis-named and is located in an inappropriate package:
+ * It is not binary-specific (it is in fact used for XML format too), and it
+ * is not a java.lang.ClassLoader, which is what "class loader" is for Java
+ * developers.
  *
+ * @author mpowell
  */
 public class BinaryClassLoader {
 
index e5aaad5..36dc4ad 100644 (file)
@@ -47,5 +47,16 @@ import com.jme.util.export.Savable;
  */
 public interface BinaryLoaderModule {
     public String getKey();
+
+    /**
+     * The inputCapsule parameter is not used at all.
+     *
+     * The DOMOutputStream class calls this method with a null parameter, so
+     * if you make use of the parameter, either handle null 'inputCapsule'
+     * or rearrange the class hierarchy to satisfy DOMOuptutStream.
+     *
+     * @param inputCapsule  A value which is currently ignored by all
+     *                      implementation classes.
+     */
     public Savable load(InputCapsule inputCapsule) throws IOException;
 }
index 131b7e0..a86173b 100644 (file)
@@ -58,6 +58,7 @@ import com.jme.util.TextureKey;
 import com.jme.util.TextureManager;
 import com.jme.util.export.InputCapsule;
 import com.jme.util.export.Savable;
+import com.jme.util.export.binary.BinaryClassLoader;
 import com.jme.util.geom.BufferUtils;
 
 /**
@@ -977,7 +978,7 @@ public class DOMInputCapsule implements InputCapsule {
             } else if (currentElem.hasAttribute("class")) {
                 className = currentElem.getAttribute("class");
             }
-            tmp = (Savable) Thread.currentThread().getContextClassLoader().loadClass(className).newInstance();
+            tmp = BinaryClassLoader.fromName(className, null);
             String refID = currentElem.getAttribute("reference_ID");
             if (refID.length() < 1) refID = currentElem.getAttribute("id");
             if (refID.length() > 0) referencedSavables.put(refID, tmp);
index ac9c6d1..8c61dad 100644 (file)
@@ -458,12 +458,16 @@ public class DOMOutputCapsule implements OutputCapsule {
         Element el = writtenSavables.get(object);
         
         String className = null;
-        if(!object.getClass().getName().equals(name)){
-            className = object.getClass().getName();
+        if(!object.getClassTag().getName().equals(name)){
+            className = object.getClassTag().getName();
         }
         try {
             doc.createElement(name);
         } catch (DOMException e) {
+            // Ridiculous fallback behavior.
+            // Would be far better to throw than to totally disregard the
+            // specified "name" and write a class name instead!
+            // (Besides the fact we are clobbering the managed .getClassTag()).
             name = "Object";
             className = object.getClass().getName();
         }
index 221ebfd..10984e0 100644 (file)
@@ -130,6 +130,15 @@ public class XMLImporter implements JMEImporter, ResourceLocator {
         return new XMLImporter();
     }
 
+    /*
+     * This returns rooted URLs, so you can use them to load resources.
+     *
+     * For persistence purposes, you should store the input to this method,
+     * not the output, because the input may be relative whereas the output is
+     * rooted to ensure it can load its resource successfully.
+     *
+     * @see com.jme.util.resource.RelativeRsoruceLocator#locateResource(String)
+     */
     public URL locateResource(String resourceName) {
         if (baseUri == null || resourceName == null
                 || resourceName.length() < 1 || resourceName.charAt(0) == '/'
index d3ef370..ee3e158 100644 (file)
@@ -72,14 +72,19 @@ public class AbsoluteResourceLocator implements ResourceLocator {
     private static final Logger logger =
             Logger.getLogger(AbsoluteResourceLocator.class.getName());
 
-    private Pattern baseUriPattern = null;
-    private URL pathlessBaseUrl = null;
+    private Pattern baseUriPattern;
+    private URL pathlessBaseUrl;
 
     /**
      * Instantiate a locator for any resource present at the specified
      * absolute resource path.
      */
     public AbsoluteResourceLocator() {
+        try {
+            pathlessBaseUrl = new URL("file:");
+        } catch (MalformedURLException mue) {
+            throw new RuntimeException(mue);
+        }
     }
 
     /**
@@ -98,15 +103,14 @@ public class AbsoluteResourceLocator implements ResourceLocator {
      * </P>
      *
      * @param baseURI <B>IMPORTANT</B>:  The whole purpose here is to specify
-     *        a path with an absolue path to validate against.
+     *        a path with an absolute path to validate against.
      *        Therefore, to cover an entire web site, you must use
      *        <CODE>http://pub.admc.com/</CODE>, not
      *        <CODE>http://pub.admc.com</CODE>.
      * @throws IllegalArgumentException if the specified baseUri does not have
-     *         an absolue URI path, or is otherwise unacceptable.
+     *         an absolute URI path, or is otherwise unacceptable.
      */
     public AbsoluteResourceLocator(URI baseUri) {
-logger.severe("base url: " + baseUri);
         String basePath = baseUri.getPath();
         // Every test I run shows a real getPath(), but there may be URI types,
         // current or future, which I have not tested, therefore...
index 00520a0..f1faba1 100644 (file)
@@ -75,6 +75,12 @@ public class RelativeResourceLocator implements ResourceLocator {
     }
 
     /*
+     * This returns rooted URLs, so you can use them to load resources.
+     *
+     * For persistence purposes, you should store the input to this method,
+     * not the output, because the input may be relative whereas the output is
+     * rooted to ensure it can load its resource successfully.
+     *
      * @returns null if resource not found, according to algorithm specified
      *          in the class JavaDoc.
      * @see RelativeResourceLocator