Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -194,7 +194,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
this.wrappedObject = ObjectUtils.unwrapOptional(object);
|
||||
Assert.notNull(this.wrappedObject, "Target object must not be null");
|
||||
this.nestedPath = (nestedPath != null ? nestedPath : "");
|
||||
this.rootObject = (!"".equals(this.nestedPath) ? rootObject : this.wrappedObject);
|
||||
this.rootObject = (!this.nestedPath.isEmpty() ? rootObject : this.wrappedObject);
|
||||
this.nestedPropertyAccessors = null;
|
||||
this.typeConverterDelegate = new TypeConverterDelegate(this, this.wrappedObject);
|
||||
}
|
||||
@@ -958,6 +958,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
return tokens;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(getClass().getName());
|
||||
@@ -971,6 +972,9 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A handler for a specific property.
|
||||
*/
|
||||
protected abstract static class PropertyHandler {
|
||||
|
||||
private final Class<?> propertyType;
|
||||
@@ -1026,6 +1030,9 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Holder class used to store property tokens.
|
||||
*/
|
||||
protected static class PropertyTokenHolder {
|
||||
|
||||
public PropertyTokenHolder(String name) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -243,18 +243,19 @@ public interface ListableBeanFactory extends BeanFactory {
|
||||
throws BeansException;
|
||||
|
||||
/**
|
||||
* Find all names of beans whose {@code Class} has the supplied {@link Annotation}
|
||||
* Find all names of beans which are annotated with the supplied {@link Annotation}
|
||||
* type, without creating corresponding bean instances yet.
|
||||
* <p>Note that this method considers objects created by FactoryBeans, which means
|
||||
* that FactoryBeans will get initialized in order to determine their object type.
|
||||
* @param annotationType the type of annotation to look for
|
||||
* @return the names of all matching beans
|
||||
* @since 4.0
|
||||
* @see #findAnnotationOnBean
|
||||
*/
|
||||
String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotationType);
|
||||
|
||||
/**
|
||||
* Find all beans whose {@code Class} has the supplied {@link Annotation} type,
|
||||
* Find all beans which are annotated with the supplied {@link Annotation} type,
|
||||
* returning a Map of bean names with corresponding bean instances.
|
||||
* <p>Note that this method considers objects created by FactoryBeans, which means
|
||||
* that FactoryBeans will get initialized in order to determine their object type.
|
||||
@@ -263,18 +264,21 @@ public interface ListableBeanFactory extends BeanFactory {
|
||||
* keys and the corresponding bean instances as values
|
||||
* @throws BeansException if a bean could not be created
|
||||
* @since 3.0
|
||||
* @see #findAnnotationOnBean
|
||||
*/
|
||||
Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) throws BeansException;
|
||||
|
||||
/**
|
||||
* Find an {@link Annotation} of {@code annotationType} on the specified
|
||||
* bean, traversing its interfaces and super classes if no annotation can be
|
||||
* found on the given class itself.
|
||||
* Find an {@link Annotation} of {@code annotationType} on the specified bean,
|
||||
* traversing its interfaces and super classes if no annotation can be found on
|
||||
* the given class itself.
|
||||
* @param beanName the name of the bean to look for annotations on
|
||||
* @param annotationType the annotation class to look for
|
||||
* @param annotationType the type of annotation to look for
|
||||
* @return the annotation of the given type if found, or {@code null} otherwise
|
||||
* @throws NoSuchBeanDefinitionException if there is no bean with the given name
|
||||
* @since 3.0
|
||||
* @see #getBeanNamesForAnnotation
|
||||
* @see #getBeansWithAnnotation
|
||||
*/
|
||||
@Nullable
|
||||
<A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
|
||||
|
||||
@@ -352,7 +352,8 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
|
||||
|
||||
/**
|
||||
* Apply the provided default values to this bean.
|
||||
* @param defaults the defaults to apply
|
||||
* @param defaults the default settings to apply
|
||||
* @since 2.5
|
||||
*/
|
||||
public void applyDefaults(BeanDefinitionDefaults defaults) {
|
||||
setLazyInit(defaults.isLazyInit());
|
||||
@@ -515,6 +516,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
|
||||
/**
|
||||
* Return whether this bean should be lazily initialized, i.e. not
|
||||
* eagerly instantiated on startup. Only applicable to a singleton bean.
|
||||
* @return whether to apply lazy-init semantics ({@code false} by default)
|
||||
*/
|
||||
@Override
|
||||
public boolean isLazyInit() {
|
||||
@@ -523,8 +525,9 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
|
||||
|
||||
/**
|
||||
* Set the autowire mode. This determines whether any automagical detection
|
||||
* and setting of bean references will happen. Default is AUTOWIRE_NO,
|
||||
* which means there's no autowire.
|
||||
* and setting of bean references will happen. Default is AUTOWIRE_NO
|
||||
* which means there won't be convention-based autowiring by name or type
|
||||
* (however, there may still be explicit annotation-driven autowiring).
|
||||
* @param autowireMode the autowire mode to set.
|
||||
* Must be one of the constants defined in this class.
|
||||
* @see #AUTOWIRE_NO
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,16 +23,17 @@ import org.springframework.util.StringUtils;
|
||||
* A simple holder for {@code BeanDefinition} property defaults.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.5
|
||||
*/
|
||||
public class BeanDefinitionDefaults {
|
||||
|
||||
private boolean lazyInit;
|
||||
|
||||
private int dependencyCheck = AbstractBeanDefinition.DEPENDENCY_CHECK_NONE;
|
||||
|
||||
private int autowireMode = AbstractBeanDefinition.AUTOWIRE_NO;
|
||||
|
||||
private int dependencyCheck = AbstractBeanDefinition.DEPENDENCY_CHECK_NONE;
|
||||
|
||||
@Nullable
|
||||
private String initMethodName;
|
||||
|
||||
@@ -40,43 +41,84 @@ public class BeanDefinitionDefaults {
|
||||
private String destroyMethodName;
|
||||
|
||||
|
||||
/**
|
||||
* Set whether beans should be lazily initialized by default.
|
||||
* <p>If {@code false}, the bean will get instantiated on startup by bean
|
||||
* factories that perform eager initialization of singletons.
|
||||
*/
|
||||
public void setLazyInit(boolean lazyInit) {
|
||||
this.lazyInit = lazyInit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether beans should be lazily initialized by default, i.e. not
|
||||
* eagerly instantiated on startup. Only applicable to singleton beans.
|
||||
* @return whether to apply lazy-init semantics ({@code false} by default)
|
||||
*/
|
||||
public boolean isLazyInit() {
|
||||
return this.lazyInit;
|
||||
}
|
||||
|
||||
public void setDependencyCheck(int dependencyCheck) {
|
||||
this.dependencyCheck = dependencyCheck;
|
||||
}
|
||||
|
||||
public int getDependencyCheck() {
|
||||
return this.dependencyCheck;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the autowire mode. This determines whether any automagical detection
|
||||
* and setting of bean references will happen. Default is AUTOWIRE_NO
|
||||
* which means there won't be convention-based autowiring by name or type
|
||||
* (however, there may still be explicit annotation-driven autowiring).
|
||||
* @param autowireMode the autowire mode to set.
|
||||
* Must be one of the constants defined in {@link AbstractBeanDefinition}.
|
||||
*/
|
||||
public void setAutowireMode(int autowireMode) {
|
||||
this.autowireMode = autowireMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default autowire mode.
|
||||
*/
|
||||
public int getAutowireMode() {
|
||||
return this.autowireMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dependency check code.
|
||||
* @param dependencyCheck the code to set.
|
||||
* Must be one of the constants defined in {@link AbstractBeanDefinition}.
|
||||
*/
|
||||
public void setDependencyCheck(int dependencyCheck) {
|
||||
this.dependencyCheck = dependencyCheck;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default dependency check code.
|
||||
*/
|
||||
public int getDependencyCheck() {
|
||||
return this.dependencyCheck;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the default initializer method.
|
||||
*/
|
||||
public void setInitMethodName(@Nullable String initMethodName) {
|
||||
this.initMethodName = (StringUtils.hasText(initMethodName) ? initMethodName : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the default initializer method.
|
||||
*/
|
||||
@Nullable
|
||||
public String getInitMethodName() {
|
||||
return this.initMethodName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the default destroy method.
|
||||
*/
|
||||
public void setDestroyMethodName(@Nullable String destroyMethodName) {
|
||||
this.destroyMethodName = (StringUtils.hasText(destroyMethodName) ? destroyMethodName : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the default destroy method.
|
||||
*/
|
||||
@Nullable
|
||||
public String getDestroyMethodName() {
|
||||
return this.destroyMethodName;
|
||||
|
||||
@@ -563,12 +563,6 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a {@link Annotation} of {@code annotationType} on the specified
|
||||
* bean, traversing its interfaces and super classes if no annotation can be
|
||||
* found on the given class itself, as well as checking its raw bean class
|
||||
* if not found on the exposed bean reference (e.g. in case of a proxy).
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
|
||||
@@ -580,14 +574,12 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
ann = AnnotationUtils.findAnnotation(beanType, annotationType);
|
||||
}
|
||||
if (ann == null && containsBeanDefinition(beanName)) {
|
||||
BeanDefinition bd = getMergedBeanDefinition(beanName);
|
||||
if (bd instanceof AbstractBeanDefinition) {
|
||||
AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
|
||||
if (abd.hasBeanClass()) {
|
||||
Class<?> beanClass = abd.getBeanClass();
|
||||
if (beanClass != beanType) {
|
||||
ann = AnnotationUtils.findAnnotation(beanClass, annotationType);
|
||||
}
|
||||
// Check raw bean class, e.g. in case of a proxy.
|
||||
RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName);
|
||||
if (bd.hasBeanClass()) {
|
||||
Class<?> beanClass = bd.getBeanClass();
|
||||
if (beanClass != beanType) {
|
||||
ann = AnnotationUtils.findAnnotation(beanClass, annotationType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1793,10 +1785,11 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
@Override
|
||||
@Nullable
|
||||
public Object getOrderSource(Object obj) {
|
||||
RootBeanDefinition beanDefinition = getRootBeanDefinition(this.instancesToBeanNames.get(obj));
|
||||
if (beanDefinition == null) {
|
||||
String beanName = this.instancesToBeanNames.get(obj);
|
||||
if (beanName == null || !containsBeanDefinition(beanName)) {
|
||||
return null;
|
||||
}
|
||||
RootBeanDefinition beanDefinition = getMergedLocalBeanDefinition(beanName);
|
||||
List<Object> sources = new ArrayList<>(2);
|
||||
Method factoryMethod = beanDefinition.getResolvedFactoryMethod();
|
||||
if (factoryMethod != null) {
|
||||
@@ -1808,17 +1801,6 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
}
|
||||
return sources.toArray();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private RootBeanDefinition getRootBeanDefinition(@Nullable String beanName) {
|
||||
if (beanName != null && containsBeanDefinition(beanName)) {
|
||||
BeanDefinition bd = getMergedBeanDefinition(beanName);
|
||||
if (bd instanceof RootBeanDefinition) {
|
||||
return (RootBeanDefinition) bd;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ public class BeanDefinitionParserDelegate {
|
||||
/**
|
||||
* Populate the given DocumentDefaultsDefinition instance with the default lazy-init,
|
||||
* autowire, dependency check settings, init-method, destroy-method and merge settings.
|
||||
* Support nested 'beans' element use cases by falling back to <literal>parentDefaults</literal>
|
||||
* Support nested 'beans' element use cases by falling back to {@code parentDefaults}
|
||||
* in case the defaults are not explicitly set locally.
|
||||
* @param defaults the defaults to populate
|
||||
* @param parentDefaults the parent BeanDefinitionParserDelegate (if any) defaults to fall back to
|
||||
@@ -377,7 +377,7 @@ public class BeanDefinitionParserDelegate {
|
||||
*/
|
||||
public BeanDefinitionDefaults getBeanDefinitionDefaults() {
|
||||
BeanDefinitionDefaults bdd = new BeanDefinitionDefaults();
|
||||
bdd.setLazyInit("TRUE".equalsIgnoreCase(this.defaults.getLazyInit()));
|
||||
bdd.setLazyInit(TRUE_VALUE.equalsIgnoreCase(this.defaults.getLazyInit()));
|
||||
bdd.setAutowireMode(getAutowireMode(DEFAULT_VALUE));
|
||||
bdd.setInitMethodName(this.defaults.getInitMethod());
|
||||
bdd.setDestroyMethodName(this.defaults.getDestroyMethod());
|
||||
|
||||
Reference in New Issue
Block a user