|
| 1 | +/* |
| 2 | + * Copyright 2002-2022 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.beans; |
| 18 | + |
| 19 | +import java.beans.BeanInfo; |
| 20 | +import java.beans.IntrospectionException; |
| 21 | +import java.beans.PropertyDescriptor; |
| 22 | +import java.beans.SimpleBeanInfo; |
| 23 | +import java.util.Collection; |
| 24 | + |
| 25 | +import org.springframework.core.Ordered; |
| 26 | +import org.springframework.lang.NonNull; |
| 27 | + |
| 28 | +/** |
| 29 | + * {@link BeanInfoFactory} implementation that bypasses the standard {@link java.beans.Introspector} |
| 30 | + * for faster introspection, reduced to basic property determination (as commonly needed in Spring). |
| 31 | + * |
| 32 | + * <p>Used by default in 6.0 through direct invocation from {@link CachedIntrospectionResults}. |
| 33 | + * Potentially configured via a {@code META-INF/spring.factories} file with the following content, |
| 34 | + * overriding other custom {@code org.springframework.beans.BeanInfoFactory} declarations: |
| 35 | + * {@code org.springframework.beans.BeanInfoFactory=org.springframework.beans.SimpleBeanInfoFactory} |
| 36 | + * |
| 37 | + * <p>Ordered at {@code Ordered.LOWEST_PRECEDENCE - 1} to override {@link ExtendedBeanInfoFactory} |
| 38 | + * (registered by default in 5.3) if necessary while still allowing other user-defined |
| 39 | + * {@link BeanInfoFactory} types to take precedence. |
| 40 | + * |
| 41 | + * @author Juergen Hoeller |
| 42 | + * @since 6.0 |
| 43 | + * @see ExtendedBeanInfoFactory |
| 44 | + * @see CachedIntrospectionResults |
| 45 | + */ |
| 46 | +class SimpleBeanInfoFactory implements BeanInfoFactory, Ordered { |
| 47 | + |
| 48 | + @Override |
| 49 | + @NonNull |
| 50 | + public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException { |
| 51 | + Collection<PropertyDescriptor> pds = PropertyDescriptorUtils.determineBasicProperties(beanClass); |
| 52 | + return new SimpleBeanInfo() { |
| 53 | + @Override |
| 54 | + public PropertyDescriptor[] getPropertyDescriptors() { |
| 55 | + return pds.toArray(PropertyDescriptorUtils.EMPTY_PROPERTY_DESCRIPTOR_ARRAY); |
| 56 | + } |
| 57 | + }; |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public int getOrder() { |
| 62 | + return Ordered.LOWEST_PRECEDENCE - 1; |
| 63 | + } |
| 64 | + |
| 65 | +} |
0 commit comments