1 package org.apache.commons.beanutils2;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import static java.lang.String.format;
23
24 /**
25 * Base class for exceptions thrown by the library. Subclasses are used for wrapping the checked exceptions thrown by the
26 * {@code java.lang.refelct} and {@code java.lang.introspection} APIs.
27 */
28 public class BeanReflectionException
29 extends RuntimeException
30 {
31 private static final long serialVersionUID = 201206182113L;
32
33 private final Class<?> beanType;
34
35 /**
36 * Constructs a new instance of {@code BeanReflectionException}.
37 *
38 * @param cause the throwable that caused the exception.
39 * @param beanType the bean type, the exception is associated with.
40 * @param messagePattern the message pattern for the exception's message.
41 * @param arguments the arguments referenced by the format specifiers in the message pattern.
42 */
43 public BeanReflectionException( Throwable cause, Class<?> beanType, String messagePattern, Object... arguments )
44 {
45 super( format( messagePattern, arguments ), cause );
46 this.beanType = beanType;
47 }
48
49 /**
50 * Constructs a new instance of {@code BeanReflectionException}.
51 *
52 * @param cause the throwable that caused the exception.
53 * @param beanType the bean type, the exception is associated with.
54 */
55 public BeanReflectionException( Throwable cause, Class<?> beanType )
56 {
57 super( cause );
58 this.beanType = beanType;
59 }
60
61 /**
62 * Returns the type that caused the exception. This may be the {@link Class} object that was the target of a static
63 * method or constructor invocation (via a {@link ClassAccessor}) or the {@link Class} of a bean that was the target
64 * of a method invocation or property access (via a {@link BeanAccessor}).
65 *
66 * @return the type that caused the exception.
67 */
68 public Class<?> getBeanType()
69 {
70 return beanType;
71 }
72
73 }