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 /**
23 * Provides access to constructors and static methods on a class.
24 *
25 * @param <B> The type modeled by this {@code ClassAccessor}.
26 */
27 public interface ClassAccessor<B>
28 {
29
30 // constructors
31
32 /**
33 * Creates a new instance of type {@code B} by calling the parameterless constructor of the wrapped class.
34 *
35 * @return a {@link BeanAccessor} that wraps the new instance.
36 * @throws BeanInstantiationException if the class wrapped by this {@code ClassAccessor} is not instantiable (for
37 * example if it is a primitive type).
38 * @throws NoSuchConstructorException if the class wrapped by this {@code ClassAccessor} does not provide a default
39 * constructor.
40 * @throws ConstructorNotAccessibleException if the constructor is not accessible.
41 * @throws ConstructorInvocationException if the constructor invocation threw an exception.
42 */
43 BeanAccessor<B> newInstance();
44
45 /**
46 * Invokes the constructor with the parameter list represented by {@code arguments} on the wrapped class. Primitive
47 * types may be converted to wrapper types and vice versa to match the methods signature.
48 *
49 * @param arguments the list of arguments to invoke the constructor with. None of the {@code Argument} objects must
50 * be {@code null}. If you want to pass {@code null} to the constructor use
51 * {@link Argument#nullArgument(Class)}.
52 * @return a {@link BeanAccessor} that wrapped the new instance
53 * @throws BeanInstantiationException if the class wrapped by this {@code ClassAccessor} is not instantiable (for
54 * example if it is a primitive type).
55 * @throws NoSuchConstructorException if no constructor that matches {@code arguments} can be found.
56 * @throws ConstructorNotAccessibleException if the constructor is not accessible.
57 * @throws ConstructorInvocationException if the constructor invocation threw an exception.
58 */
59 BeanAccessor<B> invokeConstructor( Argument<?>... arguments );
60
61 /**
62 * Invokes the constructor with the parameter list represented by {@code arguments} on the wrapped class. Invoking
63 * an exact constructor in this context means to not perform any type conversations during invocation.
64 *
65 * @param arguments the list of arguments to invoke the constructor with. None of the {@code Argument} objects must
66 * be {@code null}. If you want to pass {@code null} to the constructor use
67 * {@link Argument#nullArgument(Class)}.
68 * @return a {@link BeanAccessor} that wrapped the new instance
69 * @throws BeanInstantiationException if the class wrapped by this {@code ClassAccessor} is not instantiable (for
70 * example if it is a primitive type).
71 * @throws NoSuchConstructorException if no constructor that matches {@code arguments} exactly (without type
72 * conversation) can be found.
73 * @throws ConstructorNotAccessibleException if the constructor is not accessible.
74 * @throws ConstructorInvocationException if the constructor invocation threw an exception.
75 */
76 BeanAccessor<B> invokeExactConstructor( Argument<?>... arguments );
77
78 // bean properties
79
80 /**
81 * Provides access to the {@link BeanProperties} defined by the wrapped class.
82 *
83 * @return the {@link BeanProperties} for the wrapped class.
84 */
85 BeanProperties<B> getProperties();
86
87 // static methods invocation
88
89 /**
90 * Invokes the method with name {@code methodName} on the wrapped class. Primitive types may be converted to wrapper
91 * types and vice versa to match the methods signature.
92 *
93 * @param methodName the name of the method to invoke. Must not be {@code null}!
94 * @return the {@link ArgumentsAccessor} for this method invocation.
95 */
96 ArgumentsAccessor invokeStatic( String methodName );
97
98 /**
99 * Invokes the method with name {@code methodName} on the wrapped class. Invoking an exact method in this context
100 * means to not perform any type conversations during invocation.
101 *
102 * @param methodName the name of the method to invoke. Must not be {@code null}!
103 * @return the {@link ArgumentsAccessor} for this method invocation.
104 */
105 ArgumentsAccessor invokeExactStatic( String methodName );
106
107 }