001package org.apache.commons.beanutils2; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import static java.lang.String.format; 023 024/** 025 * Base class for exceptions thrown by the library. Subclasses are used for wrapping the checked exceptions thrown by the 026 * {@code java.lang.refelct} and {@code java.lang.introspection} APIs. 027 */ 028public class BeanReflectionException 029 extends RuntimeException 030{ 031 private static final long serialVersionUID = 201206182113L; 032 033 private final Class<?> beanType; 034 035 /** 036 * Constructs a new instance of {@code BeanReflectionException}. 037 * 038 * @param cause the throwable that caused the exception. 039 * @param beanType the bean type, the exception is associated with. 040 * @param messagePattern the message pattern for the exception's message. 041 * @param arguments the arguments referenced by the format specifiers in the message pattern. 042 */ 043 public BeanReflectionException( Throwable cause, Class<?> beanType, String messagePattern, Object... arguments ) 044 { 045 super( format( messagePattern, arguments ), cause ); 046 this.beanType = beanType; 047 } 048 049 /** 050 * Constructs a new instance of {@code BeanReflectionException}. 051 * 052 * @param cause the throwable that caused the exception. 053 * @param beanType the bean type, the exception is associated with. 054 */ 055 public BeanReflectionException( Throwable cause, Class<?> beanType ) 056 { 057 super( cause ); 058 this.beanType = beanType; 059 } 060 061 /** 062 * Returns the type that caused the exception. This may be the {@link Class} object that was the target of a static 063 * method or constructor invocation (via a {@link ClassAccessor}) or the {@link Class} of a bean that was the target 064 * of a method invocation or property access (via a {@link BeanAccessor}). 065 * 066 * @return the type that caused the exception. 067 */ 068 public Class<?> getBeanType() 069 { 070 return beanType; 071 } 072 073}