fixed two problems with asset manager:

1. can't load classes from asset class loaders.
2. can't load resources from asset class loaders.
fix-456
javasabr 8 years ago committed by Rémy Bouquet
parent abab0a553f
commit fac8266b5c
  1. 16
      jme3-core/src/main/java/com/jme3/export/SavableClassUtil.java
  2. 12
      jme3-core/src/plugins/java/com/jme3/asset/plugins/ClasspathLocator.java

@ -34,6 +34,7 @@ package com.jme3.export;
import com.jme3.animation.Animation; import com.jme3.animation.Animation;
import com.jme3.effect.shapes.*; import com.jme3.effect.shapes.*;
import com.jme3.material.MatParamTexture; import com.jme3.material.MatParamTexture;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
@ -187,16 +188,21 @@ public class SavableClassUtil {
if (loaders == null) { if (loaders == null) {
return fromName(className); return fromName(className);
} }
String newClassName = remapClass(className); String newClassName = remapClass(className);
synchronized(loaders) { synchronized (loaders) {
for (ClassLoader classLoader : loaders){ for (ClassLoader classLoader : loaders) {
final Class<?> loadedClass;
try { try {
return (Savable) classLoader.loadClass(newClassName).newInstance(); loadedClass = classLoader.loadClass(newClassName);
} catch (final ClassNotFoundException e) {
continue;
}
try {
return (Savable) loadedClass.newInstance();
} catch (InstantiationException e) { } catch (InstantiationException e) {
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
} }
} }
} }

@ -37,6 +37,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
@ -90,6 +91,17 @@ public class ClasspathLocator implements AssetLocator {
}else{ }else{
url = Thread.currentThread().getContextClassLoader().getResource(name); url = Thread.currentThread().getContextClassLoader().getResource(name);
} }
if (url == null) {
final List<ClassLoader> classLoaders = manager.getClassLoaders();
for (final ClassLoader classLoader : classLoaders) {
url = classLoader.getResource(name);
if(url != null) {
break;
}
}
}
if (url == null) if (url == null)
return null; return null;

Loading…
Cancel
Save