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 static org.apache.juneau.commons.utils.Utils.*;
020
021import java.text.*;
022
023/**
024 * General class metadata runtime operation exception.
025 *
026 *
027 * @serial exclude
028 */
029public class ClassMetaRuntimeException extends BasicRuntimeException {
030
031   private static final long serialVersionUID = 1L;
032
033   private static String getMessage(Throwable cause, Class<?> c, String msg) {
034      if (nn(msg))
035         return (c == null ? "" : cn(c) + ": ") + msg;
036      if (nn(cause))
037         return (c == null ? "" : cn(c) + ": ") + cause.getMessage();
038      return null;
039   }
040
041   /**
042    * Shortcut for calling <code><jk>new</jk> ClassMetaRuntimeException(String.format(c.getName() + <js>": "</js> + message, args));</code>
043    *
044    * @param c The class name of the bean that caused the exception.
045    * @param message The error message.
046    * @param args Arguments passed in to the {@code String.format()} method.
047    */
048   public ClassMetaRuntimeException(Class<?> c, String message, Object...args) {
049      this(null, c, message, args);
050   }
051
052   /**
053    * Constructor.
054    *
055    * @param message The error message.
056    */
057   public ClassMetaRuntimeException(String message) {
058      this((Throwable)null, null, message);
059   }
060
061   /**
062    * Constructor.
063    *
064    * @param message The error message.
065    * @param args Arguments passed in to the {@code String.format()} method.
066    */
067   public ClassMetaRuntimeException(String message, Object...args) {
068      this(null, null, message, args);
069   }
070
071   /**
072    * Constructor.
073    *
074    * @param cause The initial cause of the exception.
075    */
076   public ClassMetaRuntimeException(Throwable cause) {
077      this(cause, null, null);
078   }
079
080   /**
081    * Constructor.
082    *
083    * @param cause The cause of this exception.
084    * @param c The class name of the bean that caused the exception.
085    * @param message The {@link MessageFormat}-style message.
086    * @param args Optional {@link MessageFormat}-style arguments.
087    */
088   public ClassMetaRuntimeException(Throwable cause, Class<?> c, String message, Object...args) {
089      super(cause, getMessage(cause, c, message), args);
090   }
091
092   @Override /* Overridden from BasicRuntimeException */
093   public ClassMetaRuntimeException setMessage(String message, Object...args) {
094      super.setMessage(message, args);
095      return this;
096   }
097}