View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.juneau;
18  
19  import static org.apache.juneau.commons.utils.Utils.*;
20  
21  import java.text.*;
22  
23  /**
24   * General class metadata runtime operation exception.
25   *
26   *
27   * @serial exclude
28   */
29  public class ClassMetaRuntimeException extends BasicRuntimeException {
30  
31  	private static final long serialVersionUID = 1L;
32  
33  	private static String getMessage(Throwable cause, Class<?> c, String msg) {
34  		if (nn(msg))
35  			return (c == null ? "" : cn(c) + ": ") + msg;
36  		if (nn(cause))
37  			return (c == null ? "" : cn(c) + ": ") + cause.getMessage();
38  		return null;
39  	}
40  
41  	/**
42  	 * Shortcut for calling <code><jk>new</jk> ClassMetaRuntimeException(String.format(c.getName() + <js>": "</js> + message, args));</code>
43  	 *
44  	 * @param c The class name of the bean that caused the exception.
45  	 * @param message The error message.
46  	 * @param args Arguments passed in to the {@code String.format()} method.
47  	 */
48  	public ClassMetaRuntimeException(Class<?> c, String message, Object...args) {
49  		this(null, c, message, args);
50  	}
51  
52  	/**
53  	 * Constructor.
54  	 *
55  	 * @param message The error message.
56  	 */
57  	public ClassMetaRuntimeException(String message) {
58  		this((Throwable)null, null, message);
59  	}
60  
61  	/**
62  	 * Constructor.
63  	 *
64  	 * @param message The error message.
65  	 * @param args Arguments passed in to the {@code String.format()} method.
66  	 */
67  	public ClassMetaRuntimeException(String message, Object...args) {
68  		this(null, null, message, args);
69  	}
70  
71  	/**
72  	 * Constructor.
73  	 *
74  	 * @param cause The initial cause of the exception.
75  	 */
76  	public ClassMetaRuntimeException(Throwable cause) {
77  		this(cause, null, null);
78  	}
79  
80  	/**
81  	 * Constructor.
82  	 *
83  	 * @param cause The cause of this exception.
84  	 * @param c The class name of the bean that caused the exception.
85  	 * @param message The {@link MessageFormat}-style message.
86  	 * @param args Optional {@link MessageFormat}-style arguments.
87  	 */
88  	public ClassMetaRuntimeException(Throwable cause, Class<?> c, String message, Object...args) {
89  		super(cause, getMessage(cause, c, message), args);
90  	}
91  
92  	@Override /* Overridden from BasicRuntimeException */
93  	public ClassMetaRuntimeException setMessage(String message, Object...args) {
94  		super.setMessage(message, args);
95  		return this;
96  	}
97  }