From 9f16b989fe3276a3d3449008f5ba2f1137171b03 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Tue, 8 Nov 2011 21:18:53 +0000 Subject: [PATCH] - add a way to add a classpath for loading in-asset classes to AssetManager, use in BinaryImporter git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8600 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/asset/AndroidAssetManager.java | 18 +++++++++++++++++ .../jme3/export/binary/BinaryImporter.java | 12 +---------- .../src/core/com/jme3/asset/AssetManager.java | 19 ++++++++++++++++++ .../com/jme3/asset/DesktopAssetManager.java | 20 ++++++++++++++++++- 4 files changed, 57 insertions(+), 12 deletions(-) diff --git a/engine/src/android/com/jme3/asset/AndroidAssetManager.java b/engine/src/android/com/jme3/asset/AndroidAssetManager.java index de70b24a5..77734f190 100644 --- a/engine/src/android/com/jme3/asset/AndroidAssetManager.java +++ b/engine/src/android/com/jme3/asset/AndroidAssetManager.java @@ -39,6 +39,8 @@ import java.util.logging.Logger; import com.jme3.asset.plugins.AndroidLocator; import com.jme3.asset.plugins.ClasspathLocator; import com.jme3.audio.plugins.AndroidAudioLoader; +import java.util.ArrayList; +import java.util.List; /** * AndroidAssetManager is an implementation of DesktopAssetManager for Android @@ -48,6 +50,7 @@ import com.jme3.audio.plugins.AndroidAudioLoader; public class AndroidAssetManager extends DesktopAssetManager { private static final Logger logger = Logger.getLogger(AndroidAssetManager.class.getName()); + private List classLoaders; public AndroidAssetManager() { this(null); @@ -94,6 +97,21 @@ public class AndroidAssetManager extends DesktopAssetManager { logger.info("AndroidAssetManager created."); } + public void addClassLoader(ClassLoader loader){ + if(classLoaders == null) + classLoaders = new ArrayList(); + classLoaders.add(loader); + } + + public void removeClassLoader(ClassLoader loader){ + if(classLoaders != null) + classLoaders.remove(loader); + } + + public List getClassLoaders(){ + return classLoaders; + } + /** * Loads a texture. * diff --git a/engine/src/core-plugins/com/jme3/export/binary/BinaryImporter.java b/engine/src/core-plugins/com/jme3/export/binary/BinaryImporter.java index 0870e0d9c..afc131543 100644 --- a/engine/src/core-plugins/com/jme3/export/binary/BinaryImporter.java +++ b/engine/src/core-plugins/com/jme3/export/binary/BinaryImporter.java @@ -50,10 +50,8 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.nio.ByteOrder; -import java.util.ArrayList; import java.util.HashMap; import java.util.IdentityHashMap; -import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -88,8 +86,6 @@ public final class BinaryImporter implements JmeImporter { private static final boolean fastRead = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN; - private List loaders; - public BinaryImporter() { } @@ -101,12 +97,6 @@ public final class BinaryImporter implements JmeImporter { return fastRead; } - public void addClassLoader(ClassLoader loader){ - if(loaders == null) - loaders = new ArrayList(); - loaders.add(loader); - } - public static BinaryImporter getInstance() { return new BinaryImporter(); } @@ -346,7 +336,7 @@ public final class BinaryImporter implements JmeImporter { int dataLength = ByteUtils.convertIntFromBytes(dataArray, loc); loc+=4; - Savable out = SavableClassUtil.fromName(bco.className, loaders); + Savable out = SavableClassUtil.fromName(bco.className, assetManager.getClassLoaders()); BinaryInputCapsule cap = new BinaryInputCapsule(this, out, bco); cap.setContent(dataArray, loc, loc+dataLength); diff --git a/engine/src/core/com/jme3/asset/AssetManager.java b/engine/src/core/com/jme3/asset/AssetManager.java index 49c9ef4fc..e9bb120e9 100644 --- a/engine/src/core/com/jme3/asset/AssetManager.java +++ b/engine/src/core/com/jme3/asset/AssetManager.java @@ -40,6 +40,7 @@ import com.jme3.scene.Spatial; import com.jme3.shader.Shader; import com.jme3.shader.ShaderKey; import com.jme3.texture.Texture; +import java.util.List; /** * AssetManager provides an interface for managing the data assets @@ -47,6 +48,24 @@ import com.jme3.texture.Texture; */ public interface AssetManager { + /** + * Adds a ClassLoader that is used to load *Classes* that are needed for Assets like j3o models. + * This does *not* allow loading assets from that classpath, use registerLocator for that. + * @param loader A ClassLoader that Classes in asset files can be loaded from + */ + public void addClassLoader(ClassLoader loader); + + /** + * Remove a ClassLoader from the list of registered ClassLoaders + */ + public void removeClassLoader(ClassLoader loader); + + /** + * Retrieve the list of registered ClassLoaders that are used for loading Classes from + * asset files. + */ + public List getClassLoaders(); + /** * Registers a loader for the given extensions. * @param loaderClassName diff --git a/engine/src/desktop/com/jme3/asset/DesktopAssetManager.java b/engine/src/desktop/com/jme3/asset/DesktopAssetManager.java index e8fac3610..1a8393916 100644 --- a/engine/src/desktop/com/jme3/asset/DesktopAssetManager.java +++ b/engine/src/desktop/com/jme3/asset/DesktopAssetManager.java @@ -44,7 +44,9 @@ import com.jme3.texture.Texture; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -62,6 +64,7 @@ public class DesktopAssetManager implements AssetManager { private final ImplHandler handler = new ImplHandler(this); private AssetEventListener eventListener = null; + private List classLoaders; // private final ThreadingManager threadingMan = new ThreadingManager(this); // private final Set alreadyLoadingSet = new HashSet(); @@ -95,6 +98,21 @@ public class DesktopAssetManager implements AssetManager { logger.info("DesktopAssetManager created."); } + public void addClassLoader(ClassLoader loader){ + if(classLoaders == null) + classLoaders = new ArrayList(); + classLoaders.add(loader); + } + + public void removeClassLoader(ClassLoader loader){ + if(classLoaders != null) + classLoaders.remove(loader); + } + + public List getClassLoaders(){ + return classLoaders; + } + public void setAssetEventListener(AssetEventListener listener){ eventListener = listener; } @@ -198,7 +216,7 @@ public class DesktopAssetManager implements AssetManager { * @param key * @return */ - public T loadAsset(AssetKey key){ + public T loadAsset(AssetKey key){ if (key == null) throw new IllegalArgumentException("key cannot be null");