* 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> | ||||
|      * | ||||
|      * @param <T> | ||||
|      * @param key | ||||
|      * @return | ||||
|      */ | ||||
|     public <T> T loadAsset(AssetKey<T> key){ | ||||
|         if (eventListener != null) | ||||
| @ -220,35 +220,29 @@ public class DesktopAssetManager implements AssetManager { | ||||
|         if (o == null){ | ||||
|             AssetLoader loader = handler.aquireLoader(key); | ||||
|             if (loader == null){ | ||||
|                 logger.log(Level.WARNING,"No loader registered for type {0}.", | ||||
|                                             key.getExtension()); | ||||
|                 return null; | ||||
|                 throw new IllegalStateException("No loader registered for type \"" + | ||||
|                                                 key.getExtension() + "\""); | ||||
|             } | ||||
| 
 | ||||
|             if (handler.getLocatorCount() == 0){ | ||||
|                 logger.warning("There are no locators currently"+ | ||||
|                                " registered. Use AssetManager."+ | ||||
|                                "registerLocator() to register a"+ | ||||
|                                " locator."); | ||||
|                 return null; | ||||
|                 throw new IllegalStateException("There are no locators currently"+ | ||||
|                                                 " registered. Use AssetManager."+ | ||||
|                                                 "registerLocator() to register a"+ | ||||
|                                                 " locator."); | ||||
|             } | ||||
| 
 | ||||
|             AssetInfo info = handler.tryLocate(key); | ||||
|             if (info == null){ | ||||
|                 logger.log(Level.WARNING, "Cannot locate resource: {0}", key); | ||||
|                 return null; | ||||
|                 throw new AssetNotFoundException(key.toString()); | ||||
|             } | ||||
| 
 | ||||
|             try { | ||||
|                 o = loader.load(info); | ||||
|             } 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){ | ||||
|                 logger.log(Level.WARNING, "Error occured while loading resource {0} using {1}", | ||||
|                         new Object[]{key, loader.getClass().getSimpleName()}); | ||||
|                  | ||||
|                 return null; | ||||
|                 throw new AssetLoadException("Error occured while loading asset \"" + key + "\" using" + loader.getClass().getSimpleName()); | ||||
|             }else{ | ||||
|                 if (logger.isLoggable(Level.FINER)){ | ||||
|                     logger.log(Level.FINER, "Loaded {0} with {1}", | ||||
|  | ||||
| @ -56,7 +56,7 @@ public class FileLocator implements AssetLocator { | ||||
| 
 | ||||
|         root = new File(rootPath); | ||||
|         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 { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user