spring bean parse -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

    BeanDefinitionParserDelegate

    解析

    如果id为空,就将name中的第一个值赋给id

    Entry-->BeanEntry

    public final class ParseState {

    /**

    * Tab character used when rendering the tree-style. representation.

    */

    private static final char TAB = '\t';

    /**

    * Internal {@link Stack} storage.

    */

    private final Stack state;

    /**

    * Create a new {@code ParseState} with an empty {@link Stack}.

    */

    public ParseState() {

    this.state = new Stack();

    }

    /**

    * Create a new {@code ParseState} whose {@link Stack} is a {@link Object#clone clone}

    * of that of the passed in {@code ParseState}.

    */

    @SuppressWarnings("unchecked")

    private ParseState(ParseState other) {

    this.state = (Stack) other.state.clone();

    }

    /**

    * Add a new {@link Entry} to the {@link Stack}.

    */

    public void push(Entry entry) {

    this.state.push(entry);

    }

    /**

    * Remove an {@link Entry} from the {@link Stack}.

    */

    public void pop() {

    this.state.pop();

    }

    /**

    * Return the {@link Entry} currently at the top of the {@link Stack} or

    * {@code null} if the {@link Stack} is empty.

    */

    public Entry peek() {

    return this.state.empty() ? null : this.state.peek();

    }

    /**

    * Create a new instance of {@link ParseState} which is an independent snapshot

    * of this instance.

    */

    public ParseState snapshot() {

    return new ParseState(this);

    }

    /**

    * Returns a tree-style. representation of the current {@code ParseState}.

    */

    @Override

    public String toString() {

    StringBuilder sb = new StringBuilder();

    for (int x = 0; x < this.state.size(); x++) {

    if (x > 0) {

    sb.append('\n');

    for (int y = 0; y < x; y++) {

    sb.append(TAB);

    }

    sb.append("-> ");

    }

    sb.append(this.state.get(x));

    }

    return sb.toString();

    }

    /**

    * Marker interface for entries into the {@link ParseState}.

    */

    public interface Entry {

    }

    }

    public class BeanEntry implements ParseState.Entry {

    private String beanDefinitionName;

    /**

    * Creates a new instance of {@link BeanEntry} class.

    * @param beanDefinitionName the name of the associated bean definition

    */

    public BeanEntry(String beanDefinitionName) {

    this.beanDefinitionName = beanDefinitionName;

    }

    @Override

    public String toString() {

    return "Bean '" + this.beanDefinitionName + "'";

    }

    }

    BeanDefinition的实例:GenericBeanDefinition bd = new GenericBeanDefinition();

    AbstractBeanDefinition-->BeanMetadataAttributeAccessor

    public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport implements BeanMetadataElement {

    private Object source;

    ........

    }

    public abstract class AttributeAccessorSupport implements AttributeAccessor, Serializable {

    /** Map with String keys and Object values */

    private final Map attributes = new LinkedHashMap(0);

    ....

    }

    BeanMetadataAttribute attribute :

    public class BeanMetadataAttribute implements BeanMetadataElement {

    private final String name;

    private final Object value;

    private Object source;

    }

    LookupOverride:

    public class LookupOverride extends MethodOverride {

    private final String beanName;

    private Method method;

    .......}

    public abstract class MethodOverride implements BeanMetadataElement {

    private final String methodName;

    private boolean verloaded = true;

    private Object source;

    ...........}

    public class MethodOverrides {

    private final Set verrides = new LinkedHashSet(0);

    ......}

    ReplaceOverride:

    public class ReplaceOverride extends MethodOverride {

    private final String methodReplacerBeanName;

    private List typeIdentifiers = new LinkedList();

    ,

spring bean parse

电脑资料

spring bean parse》(https://www.unjs.com)。。。。。}

    constructor-arg:只有一个子元素(must not contain more than one sub-element)

    is only allowed to contain either 'ref' attribute OR 'value' attribute OR sub-element

    ref作为属性,则转换成RuntimeBeanReference

    public class RuntimeBeanReference implements BeanReference {

    private final String beanName;

    private final boolean toParent;

    private Object source;

    。。。。}

    如果value作为属性则转换成:

    public class TypedStringValue implements BeanMetadataElement {

    private String value;

    private volatile Object targetType;

    private Object source;

    private String specifiedTypeName;

    private volatile boolean dynamic;

    。。。。。}

    构造函数解析存放的对象:

    public class ConstructorArgumentValues {

    private final Map indexedArgumentValues = new LinkedHashMap(0);

    private final List genericArgumentValues = new LinkedList();

    。。。。}

    对应

    没有index的利用genericArgumentValues存放

    Property解析:

    public class PropertyValue extends BeanMetadataAttributeAccessor implements Serializable {

    private final String name;

    private final Object value;

    private Object source;

    private boolean ptional = false;

    private boolean converted = false;

    private Object convertedValue;

    /** Package-visible field that indicates whether conversion is necessary */

    volatile Boolean conversionNecessary;

    /** Package-visible field for caching the resolved property path tokens */

    transient volatile Object resolvedTokens;

    .......}

    其中PropertyValue 中的value保存的类型就是ManagedList

    public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccessor

    implements BeanDefinition, Cloneable {

    .........

    private MutablePropertyValues propertyValues;

    .........

    } 作为存储默认元素的属性

    Qualifier子元素的解析:

    public class AutowireCandidateQualifier extends BeanMetadataAttributeAccessor {

    public static String VALUE_KEY = "value";

    private final String typeName;

    ......

    }

    public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport implements BeanMetadataElement {

    private Object source;

    ..............

    }

    public abstract class AttributeAccessorSupport implements AttributeAccessor, Serializable {

    /** Map with String keys and Object values */

    private final Map attributes = new LinkedHashMap(0);

    ........

    }

最新文章