From 1cede40383d8e625cb9b72f6a74430d03f5df762 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Mon, 16 Jan 2012 00:24:30 +0000 Subject: [PATCH] - 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 --- .../src/core/com/jme3/asset/AssetConfig.java | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/engine/src/core/com/jme3/asset/AssetConfig.java b/engine/src/core/com/jme3/asset/AssetConfig.java index 8b1517092..eaf203600 100644 --- a/engine/src/core/com/jme3/asset/AssetConfig.java +++ b/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; /** * AssetConfig 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();