001: /*
002: * Copyright 2002-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.beans.factory.support;
018:
019: import org.springframework.beans.MutablePropertyValues;
020: import org.springframework.beans.factory.config.ConstructorArgumentValues;
021:
022: /**
023: * Root bean definitions are the most common type of bean definition.
024: * They do not derive from a parent bean definition, and usually have a
025: * class plus optionally constructor argument values and property values.
026: *
027: * <p>Note that root bean definitions do not have to specify a bean class:
028: * This can be useful for deriving childs from such definitions, each with
029: * its own bean class but inheriting common property values and other settings.
030: *
031: * @author Rod Johnson
032: * @author Juergen Hoeller
033: * @see ChildBeanDefinition
034: */
035: public class RootBeanDefinition extends AbstractBeanDefinition {
036:
037: /** Package-visible field for caching the resolved constructor or factory method */
038: volatile Object resolvedConstructorOrFactoryMethod;
039:
040: /** Package-visible field for caching fully resolved constructor arguments */
041: volatile Object[] resolvedConstructorArguments;
042:
043: /** Package-visible field for caching partly prepared constructor arguments */
044: volatile Object[] preparedConstructorArguments;
045:
046: /**
047: * Create a new RootBeanDefinition, to be configured through its bean
048: * properties and configuration methods.
049: * @see #setBeanClass
050: * @see #setBeanClassName
051: * @see #setSingleton
052: * @see #setAutowireMode
053: * @see #setDependencyCheck
054: * @see #setConstructorArgumentValues
055: * @see #setPropertyValues
056: */
057: public RootBeanDefinition() {
058: super ();
059: }
060:
061: /**
062: * Create a new RootBeanDefinition for a singleton.
063: * @param beanClass the class of the bean to instantiate
064: */
065: public RootBeanDefinition(Class beanClass) {
066: super ();
067: setBeanClass(beanClass);
068: }
069:
070: /**
071: * Create a new RootBeanDefinition with the given singleton status.
072: * @param beanClass the class of the bean to instantiate
073: * @param singleton the singleton status of the bean
074: */
075: public RootBeanDefinition(Class beanClass, boolean singleton) {
076: super ();
077: setBeanClass(beanClass);
078: setSingleton(singleton);
079: }
080:
081: /**
082: * Create a new RootBeanDefinition for a singleton,
083: * using the given autowire mode.
084: * @param beanClass the class of the bean to instantiate
085: * @param autowireMode by name or type, using the constants in this interface
086: */
087: public RootBeanDefinition(Class beanClass, int autowireMode) {
088: super ();
089: setBeanClass(beanClass);
090: setAutowireMode(autowireMode);
091: }
092:
093: /**
094: * Create a new RootBeanDefinition for a singleton,
095: * using the given autowire mode.
096: * @param beanClass the class of the bean to instantiate
097: * @param autowireMode by name or type, using the constants in this interface
098: * @param dependencyCheck whether to perform a dependency check for objects
099: * (not applicable to autowiring a constructor, thus ignored there)
100: */
101: public RootBeanDefinition(Class beanClass, int autowireMode,
102: boolean dependencyCheck) {
103: super ();
104: setBeanClass(beanClass);
105: setAutowireMode(autowireMode);
106: if (dependencyCheck
107: && getResolvedAutowireMode() != AUTOWIRE_CONSTRUCTOR) {
108: setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
109: }
110: }
111:
112: /**
113: * Create a new RootBeanDefinition for a singleton,
114: * providing property values.
115: * @param beanClass the class of the bean to instantiate
116: * @param pvs the property values to apply
117: */
118: public RootBeanDefinition(Class beanClass, MutablePropertyValues pvs) {
119: super (null, pvs);
120: setBeanClass(beanClass);
121: }
122:
123: /**
124: * Create a new RootBeanDefinition with the given singleton status,
125: * providing property values.
126: * @param beanClass the class of the bean to instantiate
127: * @param pvs the property values to apply
128: * @param singleton the singleton status of the bean
129: */
130: public RootBeanDefinition(Class beanClass,
131: MutablePropertyValues pvs, boolean singleton) {
132: super (null, pvs);
133: setBeanClass(beanClass);
134: setSingleton(singleton);
135: }
136:
137: /**
138: * Create a new RootBeanDefinition for a singleton,
139: * providing constructor arguments and property values.
140: * @param beanClass the class of the bean to instantiate
141: * @param cargs the constructor argument values to apply
142: * @param pvs the property values to apply
143: */
144: public RootBeanDefinition(Class beanClass,
145: ConstructorArgumentValues cargs, MutablePropertyValues pvs) {
146: super (cargs, pvs);
147: setBeanClass(beanClass);
148: }
149:
150: /**
151: * Create a new RootBeanDefinition for a singleton,
152: * providing constructor arguments and property values.
153: * <p>Takes a bean class name to avoid eager loading of the bean class.
154: * @param beanClassName the name of the class to instantiate
155: * @param cargs the constructor argument values to apply
156: * @param pvs the property values to apply
157: */
158: public RootBeanDefinition(String beanClassName,
159: ConstructorArgumentValues cargs, MutablePropertyValues pvs) {
160: super (cargs, pvs);
161: setBeanClassName(beanClassName);
162: }
163:
164: /**
165: * Create a new RootBeanDefinition as deep copy of the given
166: * bean definition.
167: * @param original the original bean definition to copy from
168: */
169: public RootBeanDefinition(RootBeanDefinition original) {
170: super (original);
171: }
172:
173: public boolean equals(Object other) {
174: return (this == other || (other instanceof RootBeanDefinition && super
175: .equals(other)));
176: }
177:
178: public String toString() {
179: return "Root bean: " + super.toString();
180: }
181:
182: }
|