ArtifactNotFoundException.java
01 /*
02  * Copyright 2008-2017 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     private static final String CAUSE = "cause";
30     private static final String CLAZZ = "clazz";
31 
32     public ArtifactNotFoundException(@Nonnull Throwable cause) {
33         super("Could not find artifact", checkNonNull(cause, CAUSE));
34     }
35 
36     public ArtifactNotFoundException(@Nonnull Class<?> clazz) {
37         super(format(clazz));
38     }
39 
40     public ArtifactNotFoundException(@Nonnull GriffonClass griffonClass, @Nonnull Throwable cause) {
41         super(format(griffonClass), checkNonNull(cause, CAUSE));
42     }
43 
44     public ArtifactNotFoundException(@Nonnull Class<? extends GriffonArtifact> clazz, @Nonnull String name) {
45         super(format(clazz, name));
46     }
47 
48     private static String format(GriffonClass griffonClass) {
49         return "Could not find artifact for " + checkNonNull(griffonClass, "griffonClass").getPropertyName();
50     }
51 
52     private static String format(Class<?> clazz) {
53         return "Could not find artifact for " + checkNonNull(clazz, CLAZZ).getName();
54     }
55 
56     private static String format(Class<? extends GriffonArtifact> clazz, String name) {
57         return "Could not find artifact of type " + checkNonNull(clazz, CLAZZ).getName() " named " + checkNonBlank(name, "name");
58     }
59 }