001    /*
002     * Copyright 2002-2004 the original author or authors.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.springframework.richclient.image;
017    
018    import org.springframework.core.io.Resource;
019    
020    /**
021     * Indicates that a image resource could not be found from an underlying data
022     * source.
023     * 
024     * @author Keith Donald
025     */
026    public class NoSuchImageResourceException extends RuntimeException {
027        private Object imageKey;
028    
029        /**
030         * Creates an exception message indicating the specified imageKey did not
031         * map to a valid resource.
032         * 
033         * @param imageKey
034         *            The unknown image key.
035         */
036        public NoSuchImageResourceException(Object imageKey) {
037            super();
038            this.imageKey = imageKey;
039        }
040    
041        /**
042         * Creates an exception message indicating the specified imageKey did not
043         * map to a valid resource. A cause is provided.
044         * 
045         * @param imageKey
046         *            The unknown image key.
047         * @param cause
048         *            The reason the resource was not found.
049         */
050        public NoSuchImageResourceException(Object imageKey, Throwable cause) {
051            super(cause);
052            this.imageKey = imageKey;
053        }
054    
055        public String getMessage() {
056            if (Resource.class.isInstance(imageKey)) 
057                return "No image at resource '" + imageKey + "' exists.";
058    
059            return "No image with key '" + imageKey + "' exists in source bundle.";
060        }
061    
062        public String toString() {
063            return getMessage();
064        }
065    
066    }