- make AssetConfig more robust when loading assetmanager config from file

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9074 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 13 years ago
parent 479fdd5624
commit 1cede40383
  1. 29
      engine/src/core/com/jme3/asset/AssetConfig.java

@ -36,6 +36,8 @@ import java.io.DataInput;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* <code>AssetConfig</code> loads a config file to configure the asset manager.
@ -71,16 +73,33 @@ public class AssetConfig {
for (int i = 0; i < extensions.length; i++){
extensions[i] = extensions[i].trim();
}
manager.registerLoader(loaderClass, extensions);
}else if (cmd.equals("LOCATOR")){
if (hasClass(loaderClass)) {
manager.registerLoader(loaderClass, extensions);
} else {
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot find loader {0}", loaderClass);
}
} else if (cmd.equals("LOCATOR")) {
String rootPath = scan.next();
String locatorClass = scan.nextLine().trim();
manager.registerLocator(rootPath, locatorClass);
}else{
throw new IOException("Expected command, got '"+cmd+"'");
if (hasClass(locatorClass)) {
manager.registerLocator(rootPath, locatorClass);
} else {
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot find locator {0}", locatorClass);
}
} else {
throw new IOException("Expected command, got '" + cmd + "'");
}
}
}
private boolean hasClass(String name) {
try {
Class clazz = Class.forName(name);
return clazz != null;
} catch (ClassNotFoundException ex) {
return false;
}
}
private static String readString(DataInput dataIn) throws IOException{
int length = dataIn.readUnsignedShort();

Loading…
Cancel
Save