| 
01 /*02  * Copyright 2008-2015 the original author or authors.
 03  *
 04  * Licensed under the Apache License, Version 2.0 (the "License");
 05  * you may not use this file except in compliance with the License.
 06  * You may obtain a copy of the License at
 07  *
 08  *     http://www.apache.org/licenses/LICENSE-2.0
 09  *
 10  * Unless required by applicable law or agreed to in writing, software
 11  * distributed under the License is distributed on an "AS IS" BASIS,
 12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  * See the License for the specific language governing permissions and
 14  * limitations under the License.
 15  */
 16 package griffon.exceptions;
 17
 18 import griffon.core.artifact.GriffonArtifact;
 19 import griffon.core.artifact.GriffonClass;
 20
 21 import javax.annotation.Nonnull;
 22
 23 /**
 24  * @author Andres Almiray
 25  * @since 2.0.0
 26  */
 27 public class ArtifactNotFoundException extends GriffonException {
 28     private static final long serialVersionUID = -7881105306242340254L;
 29
 30     public ArtifactNotFoundException(@Nonnull Throwable cause) {
 31         super("Could not find artifact", checkNonNull(cause, "cause"));
 32     }
 33
 34     public ArtifactNotFoundException(@Nonnull Class<?> clazz) {
 35         super(format(clazz));
 36     }
 37
 38     public ArtifactNotFoundException(@Nonnull GriffonClass griffonClass, @Nonnull Throwable cause) {
 39         super(format(griffonClass), checkNonNull(cause, "cause"));
 40     }
 41
 42     public ArtifactNotFoundException(@Nonnull Class<? extends GriffonArtifact> clazz, @Nonnull String name) {
 43         super(format(clazz, name));
 44     }
 45
 46     private static String format(GriffonClass griffonClass) {
 47         return "Could not find artifact for " + checkNonNull(griffonClass, "griffonClass").getPropertyName();
 48     }
 49
 50     private static String format(Class<?> clazz) {
 51         return "Could not find artifact for " + checkNonNull(clazz, "clazz");
 52     }
 53
 54     private static String format(Class<? extends GriffonArtifact> clazz, String name) {
 55         return "Could not find artifact of type " + checkNonNull(clazz, "clazz") + " named " + checkNonBlank(name, "name");
 56     }
 57 }
 |