diff --git a/engine/src/core-plugins/com/jme3/export/binary/BinaryClassLoader.java b/engine/src/core-plugins/com/jme3/export/binary/BinaryClassLoader.java index 7adf0be6d..a1b370c43 100644 --- a/engine/src/core-plugins/com/jme3/export/binary/BinaryClassLoader.java +++ b/engine/src/core-plugins/com/jme3/export/binary/BinaryClassLoader.java @@ -37,6 +37,8 @@ import java.util.logging.Logger; import com.jme3.export.InputCapsule; import com.jme3.export.Savable; +import java.util.Iterator; +import java.util.List; /** * This class is mis-named and is located in an inappropriate package: @@ -80,4 +82,37 @@ public class BinaryClassLoader { } } + public static Savable fromName(String className, InputCapsule inputCapsule, List loaders) throws InstantiationException, + IllegalAccessException, ClassNotFoundException, IOException { + if(loaders == null){ + return fromName(className, inputCapsule); + } + for (Iterator it = loaders.iterator(); it.hasNext();) { + ClassLoader classLoader = it.next(); + try { + return (Savable)classLoader.loadClass(className).newInstance(); + } + catch (InstantiationException e) { + } + catch (IllegalAccessException e) { + } + + } + + try { + return (Savable)Class.forName(className).newInstance(); + } + catch (InstantiationException e) { + Logger.getLogger(BinaryClassLoader.class.getName()).severe( + "Could not access constructor of class '" + className + "'! \n" + + "Some types need to have the BinaryImporter set up in a special way. Please doublecheck the setup."); + throw e; + } + catch (IllegalAccessException e) { + Logger.getLogger(BinaryClassLoader.class.getName()).severe( + e.getMessage() + " \n" + + "Some types need to have the BinaryImporter set up in a special way. Please doublecheck the setup."); + throw e; + } + } } 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 c7b44c610..55a00afd0 100644 --- a/engine/src/core-plugins/com/jme3/export/binary/BinaryImporter.java +++ b/engine/src/core-plugins/com/jme3/export/binary/BinaryImporter.java @@ -48,8 +48,10 @@ 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; @@ -81,14 +83,22 @@ public final class BinaryImporter implements JmeImporter { private int aliasWidth; private static final boolean fastRead = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN; + + private List loaders; public BinaryImporter() { } - + public static boolean canUseFastBuffers(){ return fastRead; } + public void addClassLoader(ClassLoader loader){ + if(loaders == null) + loaders = new ArrayList(); + loaders.add(loader); + } + public static BinaryImporter getInstance() { return new BinaryImporter(); } @@ -284,7 +294,7 @@ public final class BinaryImporter implements JmeImporter { BinaryInputCapsule cap = new BinaryInputCapsule(this, bco); cap.setContent(dataArray, loc, loc+dataLength); - Savable out = BinaryClassLoader.fromName(bco.className, cap); + Savable out = BinaryClassLoader.fromName(bco.className, cap, loaders); capsuleTable.put(out, cap); contentTable.put(id, out);