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 org.apache.commons.beanutils2.Assertions.checkNotNull;
23
24 /**
25 * Entry point into the API. Provides methods for:
26 * <p><ul>
27 * <li>Accessing properties of a bean
28 * <li>Accessing classes
29 * <li>Loading classes by name
30 * </ul><p>
31 * All methods will throw {@code NullPointerException} if null is passed in.
32 */
33 public final class BeanUtils
34 {
35
36 // POJO/JavaBean stuff
37
38 /**
39 * Creates a {@link BeanAcessor} for the given bean, that allows access to the bean's properties and methods.
40 *
41 * @param bean the bean to be accessed. Must not be {@code null}!
42 * @param <B> the type of the bean.
43 * @return a BeanAccessor for the given bean.
44 */
45 public static <B> BeanAccessor<B> on( B bean )
46 {
47 bean = checkNotNull( bean, "No bean specified" );
48 return new DefaultBeanAccessor<B>( bean );
49 }
50
51 // introspection stuff
52
53 /**
54 * Creates a {@link ClassAccessor} for the given type that allows for creating instances of the type and calling
55 * static methods.
56 *
57 * @param beanType the type to be accessed. Must not be {@code null}!
58 * @param <B> the type modeled by the given class object.
59 * @return a ClassAccessor for the given type.
60 */
61 public static <B> ClassAccessor<B> on( Class<B> beanType )
62 {
63 beanType = checkNotNull( beanType, "No bean class specified" );
64 return new DefaultClassAccessor<B>( beanType );
65 }
66
67 /**
68 * Creates a {@link ClassLoaderBuilder} that allows to load the type given by {@code beanTypeName}.
69 *
70 * @param beanTypeName the name of the type to load. Must not be {@code null}!
71 * @return the ClassLoaderBuilder for the given type name.
72 */
73 public static ClassLoaderBuilder onClassName( String beanTypeName )
74 {
75 beanTypeName = checkNotNull( beanTypeName, "No bean class name specified" );
76 return new DefaultClassLoaderBuilder( beanTypeName );
77 }
78
79 /**
80 * Hidden constructor, this class cannot be instantiated directly
81 */
82 private BeanUtils()
83 {
84 // do nothing
85 }
86
87 }