- 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. 25
      engine/src/core/com/jme3/asset/AssetConfig.java

@ -36,6 +36,8 @@ import java.io.DataInput;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Scanner; 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. * <code>AssetConfig</code> loads a config file to configure the asset manager.
@ -71,15 +73,32 @@ public class AssetConfig {
for (int i = 0; i < extensions.length; i++){ for (int i = 0; i < extensions.length; i++){
extensions[i] = extensions[i].trim(); extensions[i] = extensions[i].trim();
} }
if (hasClass(loaderClass)) {
manager.registerLoader(loaderClass, extensions); manager.registerLoader(loaderClass, extensions);
}else if (cmd.equals("LOCATOR")){ } else {
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot find loader {0}", loaderClass);
}
} else if (cmd.equals("LOCATOR")) {
String rootPath = scan.next(); String rootPath = scan.next();
String locatorClass = scan.nextLine().trim(); String locatorClass = scan.nextLine().trim();
if (hasClass(locatorClass)) {
manager.registerLocator(rootPath, locatorClass); manager.registerLocator(rootPath, locatorClass);
}else{ } else {
throw new IOException("Expected command, got '"+cmd+"'"); 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{ private static String readString(DataInput dataIn) throws IOException{

Loading…
Cancel
Save