* AssetManager will now throw an exception when there are issues with loading/locating an asset
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7027 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
0df414d2f0
commit
a83216731e
17
engine/src/core/com/jme3/asset/AssetLoadException.java
Normal file
17
engine/src/core/com/jme3/asset/AssetLoadException.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package com.jme3.asset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>AssetLoadException</code> is thrown when the {@link AssetManager}
|
||||||
|
* is able to find the requested asset, but there was a problem while loading
|
||||||
|
* it.
|
||||||
|
*
|
||||||
|
* @author Kirill Vainer
|
||||||
|
*/
|
||||||
|
public class AssetLoadException extends RuntimeException {
|
||||||
|
public AssetLoadException(String message){
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
public AssetLoadException(String message, Throwable cause){
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
}
|
14
engine/src/core/com/jme3/asset/AssetNotFoundException.java
Normal file
14
engine/src/core/com/jme3/asset/AssetNotFoundException.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package com.jme3.asset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>AssetNotFoundException</code> is thrown when the {@link AssetManager}
|
||||||
|
* is unable to locate the requested asset using any of the registered
|
||||||
|
* {@link AssetLocator}s.
|
||||||
|
*
|
||||||
|
* @author Kirill Vainer
|
||||||
|
*/
|
||||||
|
public class AssetNotFoundException extends RuntimeException {
|
||||||
|
public AssetNotFoundException(String message){
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -192,11 +192,11 @@ public class DesktopAssetManager implements AssetManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is thread-safe.
|
|
||||||
* @param name
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* <font color="red">Thread-safe.</font>
|
* <font color="red">Thread-safe.</font>
|
||||||
|
*
|
||||||
|
* @param <T>
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public <T> T loadAsset(AssetKey<T> key){
|
public <T> T loadAsset(AssetKey<T> key){
|
||||||
if (eventListener != null)
|
if (eventListener != null)
|
||||||
@ -220,35 +220,29 @@ public class DesktopAssetManager implements AssetManager {
|
|||||||
if (o == null){
|
if (o == null){
|
||||||
AssetLoader loader = handler.aquireLoader(key);
|
AssetLoader loader = handler.aquireLoader(key);
|
||||||
if (loader == null){
|
if (loader == null){
|
||||||
logger.log(Level.WARNING,"No loader registered for type {0}.",
|
throw new IllegalStateException("No loader registered for type \"" +
|
||||||
key.getExtension());
|
key.getExtension() + "\"");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handler.getLocatorCount() == 0){
|
if (handler.getLocatorCount() == 0){
|
||||||
logger.warning("There are no locators currently"+
|
throw new IllegalStateException("There are no locators currently"+
|
||||||
" registered. Use AssetManager."+
|
" registered. Use AssetManager."+
|
||||||
"registerLocator() to register a"+
|
"registerLocator() to register a"+
|
||||||
" locator.");
|
" locator.");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetInfo info = handler.tryLocate(key);
|
AssetInfo info = handler.tryLocate(key);
|
||||||
if (info == null){
|
if (info == null){
|
||||||
logger.log(Level.WARNING, "Cannot locate resource: {0}", key);
|
throw new AssetNotFoundException(key.toString());
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
o = loader.load(info);
|
o = loader.load(info);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.log(Level.WARNING, "Failed to load resource: "+key, ex);
|
throw new AssetLoadException("An exception has occured while loading asset: " + key, ex);
|
||||||
}
|
}
|
||||||
if (o == null){
|
if (o == null){
|
||||||
logger.log(Level.WARNING, "Error occured while loading resource {0} using {1}",
|
throw new AssetLoadException("Error occured while loading asset \"" + key + "\" using" + loader.getClass().getSimpleName());
|
||||||
new Object[]{key, loader.getClass().getSimpleName()});
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}else{
|
}else{
|
||||||
if (logger.isLoggable(Level.FINER)){
|
if (logger.isLoggable(Level.FINER)){
|
||||||
logger.log(Level.FINER, "Loaded {0} with {1}",
|
logger.log(Level.FINER, "Loaded {0} with {1}",
|
||||||
|
@ -56,7 +56,7 @@ public class FileLocator implements AssetLocator {
|
|||||||
|
|
||||||
root = new File(rootPath);
|
root = new File(rootPath);
|
||||||
if (!root.isDirectory())
|
if (!root.isDirectory())
|
||||||
throw new RuntimeException("Given root path not a directory");
|
throw new IllegalArgumentException("Given root path \"" + root + "\" not a directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class AssetInfoFile extends AssetInfo {
|
private static class AssetInfoFile extends AssetInfo {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user