001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau; 018 019import java.text.*; 020 021/** 022 * General class metadata runtime operation exception. 023 * 024 * <h5 class='section'>See Also:</h5><ul> 025 026 * </ul> 027 * 028 * @serial exclude 029 */ 030public class ClassMetaRuntimeException extends BasicRuntimeException { 031 032 private static final long serialVersionUID = 1L; 033 034 /** 035 * Constructor. 036 * 037 * @param cause The cause of this exception. 038 * @param c The class name of the bean that caused the exception. 039 * @param message The {@link MessageFormat}-style message. 040 * @param args Optional {@link MessageFormat}-style arguments. 041 */ 042 public ClassMetaRuntimeException(Throwable cause, Class<?> c, String message, Object... args) { 043 super(cause, getMessage(cause, c, message), args); 044 } 045 046 /** 047 * Constructor. 048 * 049 * @param message The error message. 050 */ 051 public ClassMetaRuntimeException(String message) { 052 this((Throwable)null, null, message); 053 } 054 055 /** 056 * Constructor. 057 * 058 * @param message The error message. 059 * @param args Arguments passed in to the {@code String.format()} method. 060 */ 061 public ClassMetaRuntimeException(String message, Object...args) { 062 this(null, null, message, args); 063 } 064 065 /** 066 * Shortcut for calling <code><jk>new</jk> ClassMetaRuntimeException(String.format(c.getName() + <js>": "</js> + message, args));</code> 067 * 068 * @param c The class name of the bean that caused the exception. 069 * @param message The error message. 070 * @param args Arguments passed in to the {@code String.format()} method. 071 */ 072 public ClassMetaRuntimeException(Class<?> c, String message, Object... args) { 073 this(null, c, message, args); 074 } 075 076 /** 077 * Constructor. 078 * 079 * @param cause The initial cause of the exception. 080 */ 081 public ClassMetaRuntimeException(Throwable cause) { 082 this(cause, null, null); 083 } 084 085 private static String getMessage(Throwable cause, Class<?> c, String msg) { 086 if (msg != null) 087 return (c == null ? "" : c.getName() + ": ") + msg; 088 if (cause != null) 089 return (c == null ? "" : c.getName() + ": ") + cause.getMessage(); 090 return null; 091 } 092}