Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * Copyright 2002-2008 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.
    * You may obtain a copy of the License at
    *
    *      http://www.apache.org/licenses/LICENSE-2.0
    *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.springframework.beans.factory.support;
  
  import java.util.Arrays;
  import java.util.Map;
  import java.util.Set;
  
Base class for concrete, full-fledged org.springframework.beans.factory.config.BeanDefinition classes, factoring out common properties of RootBeanDefinition and ChildBeanDefinition.

The autowire constants match the ones defined in the org.springframework.beans.factory.config.AutowireCapableBeanFactory interface.

Author(s):
Rod Johnson
Juergen Hoeller
Rob Harrop
Mark Fisher
See also:
RootBeanDefinition
ChildBeanDefinition
  
  public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccessor
  		implements BeanDefinitionCloneable {

Constant that indicates no autowiring at all.

  
  	public static final int AUTOWIRE_NO = .;

Constant that indicates autowiring bean properties by name.

  
  	public static final int AUTOWIRE_BY_NAME = .;

Constant that indicates autowiring bean properties by type.

  
  	public static final int AUTOWIRE_BY_TYPE = .;

Constant that indicates autowiring a constructor.

  
Constant that indicates determining an appropriate autowire strategy through introspection of the bean class.

  
Constant that indicates no dependency check at all.

  
  	public static final int DEPENDENCY_CHECK_NONE = 0;

Constant that indicates dependency checking for object references.

  
 	public static final int DEPENDENCY_CHECK_OBJECTS = 1;

Constant that indicates dependency checking for "simple" properties.

 
 	public static final int DEPENDENCY_CHECK_SIMPLE = 2;

Constant that indicates dependency checking for all properties (object references as well as "simple" properties).

 
 	public static final int DEPENDENCY_CHECK_ALL = 3;
 
 
 	private volatile Object beanClass;
 
 	private String scope = ;
 
 	private boolean singleton = true;
 
 	private boolean prototype = false;
 
 	private boolean abstractFlag = false;
 
 	private boolean lazyInit = false;
 
 	private int autowireMode = ;
 
 
 	private String[] dependsOn;
 
 	private boolean autowireCandidate = true;
 
 	private final Map qualifiers = new LinkedHashMap();
 
 	private boolean primary = false;
 
 
 
 
 
 
 
 
 	private boolean enforceInitMethod = true;
 
 	private boolean enforceDestroyMethod = true;
 
 	private boolean synthetic = false;
 
 
 	private String description;
 
 	private Resource resource;


Create a new AbstractBeanDefinition with default settings.
 
 	protected AbstractBeanDefinition() {
 		this(nullnull);
 	}

Create a new AbstractBeanDefinition with the given constructor argument values and property values.
 
 	}

Create a new AbstractBeanDefinition as deep copy of the given bean definition.

Deprecated:
since Spring 2.5, in favor of AbstractBeanDefinition(org.springframework.beans.factory.config.BeanDefinition)
Parameters:
original the original bean definition to copy from
 
 		this((BeanDefinitionoriginal);
 	}

Create a new AbstractBeanDefinition as deep copy of the given bean definition.

Parameters:
original the original bean definition to copy from
 
 	protected AbstractBeanDefinition(BeanDefinition original) {
 		setScope(original.getScope());
 		setAbstract(original.isAbstract());
 		setLazyInit(original.isLazyInit());
 		setRole(original.getRole());
 		setSource(original.getSource());
 		copyAttributesFrom(original);
 
 		if (original instanceof AbstractBeanDefinition) {
 			AbstractBeanDefinition originalAbd = (AbstractBeanDefinitionoriginal;
 			if (originalAbd.hasBeanClass()) {
 				setBeanClass(originalAbd.getBeanClass());
 			}
 			setDependsOn(originalAbd.getDependsOn());
 			copyQualifiersFrom(originalAbd);
 			setPrimary(originalAbd.isPrimary());
 			setSynthetic(originalAbd.isSynthetic());
 			setResource(originalAbd.getResource());
 		}
 		else {
 		}
 	}


Override settings in this bean definition (assumably a copied parent from a parent-child inheritance relationship) from the given bean definition (assumably the child).

 
 	public void overrideFrom(AbstractBeanDefinition other) {
 	}

Override settings in this bean definition (assumably a copied parent from a parent-child inheritance relationship) from the given bean definition (assumably the child).
  • Will override beanClass if specified in the given bean definition.
  • Will always take abstract, scope, lazyInit, autowireMode, dependencyCheck, and dependsOn from the given bean definition.
  • Will add constructorArgumentValues, propertyValues, methodOverrides from the given bean definition to existing ones.
  • Will override factoryBeanName, factoryMethodName, initMethodName, and destroyMethodName if specified in the given bean definition.
 
 	public void overrideFrom(BeanDefinition other) {
 		if (other.getBeanClassName() != null) {
 		}
 		if (other.getFactoryBeanName() != null) {
 		}
 		if (other.getFactoryMethodName() != null) {
 		}
 		setScope(other.getScope());
 		setRole(other.getRole());
 		setSource(other.getSource());
 
 		if (other instanceof AbstractBeanDefinition) {
 			if (otherAbd.hasBeanClass()) {
 			}
 			copyQualifiersFrom(otherAbd);
 			setPrimary(otherAbd.isPrimary());
 			if (otherAbd.getInitMethodName() != null) {
 			}
 			if (otherAbd.getDestroyMethodName() != null) {
 			}
 			setResource(otherAbd.getResource());
 		}
 		else {
 		}
 	}

Apply the provided default values to this bean.

Parameters:
defaults the defaults to apply
 
 	public void applyDefaults(BeanDefinitionDefaults defaults) {
 		setLazyInit(defaults.isLazyInit());
 	}


Return whether this definition specifies a bean class.
 
 	public boolean hasBeanClass() {
 		return (this. instanceof Class);
 	}

Specify the class for this bean.
 
 	public void setBeanClass(Class beanClass) {
 		this. = beanClass;
 	}

Return the class of the wrapped bean, if already resolved.

Returns:
the bean class, or null if none defined
Throws:
java.lang.IllegalStateException if the bean definition does not define a bean class, or a specified bean class name has not been resolved into an actual Class
 
 	public Class getBeanClass() throws IllegalStateException {
 		Object beanClassObject = this.;
 		if (beanClassObject == null) {
 			throw new IllegalStateException("No bean class specified on bean definition");
 		}
 		if (!(beanClassObject instanceof Class)) {
 			throw new IllegalStateException(
 					"Bean class name [" + beanClassObject + "] has not been resolved into an actual Class");
 		}
 		return (ClassbeanClassObject;
 	}
 
 	public void setBeanClassName(String beanClassName) {
 		this. = beanClassName;
 	}
 
 	public String getBeanClassName() {
 		Object beanClassObject = this.;
 		if (beanClassObject instanceof Class) {
 			return ((ClassbeanClassObject).getName();
 		}
 		else {
 			return (StringbeanClassObject;
 		}
 	}

Determine the class of the wrapped bean, resolving it from a specified class name if necessary. Will also reload a specified Class from its name when called with the bean class already resolved.

Parameters:
classLoader the ClassLoader to use for resolving a (potential) class name
Returns:
the resolved bean class
Throws:
java.lang.ClassNotFoundException if the class name could be resolved
 
 	public Class resolveBeanClass(ClassLoader classLoaderthrows ClassNotFoundException {
 		String className = getBeanClassName();
 		if (className == null) {
 			return null;
 		}
 		Class resolvedClass = ClassUtils.forName(classNameclassLoader);
 		this. = resolvedClass;
 		return resolvedClass;
 	}


Set the name of the target scope for the bean.

Default is "singleton"; the out-of-the-box alternative is "prototype". Extended bean factories might support further scopes.

 
 	public void setScope(String scope) {
 		Assert.notNull(scope"Scope must not be null");
 		this. = scope;
 		this. = .equals(scope);
 		this. = .equals(scope);
 	}

Return the name of the target scope for the bean.
 
 	public String getScope() {
 		return this.;
 	}

Set if this a Singleton, with a single, shared instance returned on all calls. In case of "false", the BeanFactory will apply the Prototype design pattern, with each caller requesting an instance getting an independent instance. How this is exactly defined will depend on the BeanFactory.

"Singletons" are the commoner type, so the default is "true". Note that as of Spring 2.0, this flag is just an alternative way to specify scope="singleton" or scope="prototype".

 
 	public void setSingleton(boolean singleton) {
 		this. = (singleton ?  : );
 		this. = singleton;
 		this. = !singleton;
 	}

Return whether this a Singleton, with a single shared instance returned from all calls.

 
 	public boolean isSingleton() {
 		return this.;
 	}

Return whether this a Prototype, with an independent instance returned for each call.

 
 	public boolean isPrototype() {
 		return this.;
 	}

Set if this bean is "abstract", i.e. not meant to be instantiated itself but rather just serving as parent for concrete child bean definitions.

Default is "false". Specify true to tell the bean factory to not try to instantiate that particular bean in any case.

 
 	public void setAbstract(boolean abstractFlag) {
 		this. = abstractFlag;
 	}

Return whether this bean is "abstract", i.e. not meant to be instantiated itself but rather just serving as parent for concrete child bean definitions.
 
 	public boolean isAbstract() {
 		return this.;
 	}

Set whether this bean should be lazily initialized.

If false, the bean will get instantiated on startup by bean factories that perform eager initialization of singletons.

 
 	public void setLazyInit(boolean lazyInit) {
 		this. = lazyInit;
 	}

Return whether this bean should be lazily initialized, i.e. not eagerly instantiated on startup. Only applicable to a singleton bean.
 
 	public boolean isLazyInit() {
 		return this.;
 	}


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.

Parameters:
autowireMode the autowire mode to set. Must be one of the constants defined in this class.
See also:
AUTOWIRE_NO
AUTOWIRE_BY_NAME
AUTOWIRE_BY_TYPE
AUTOWIRE_CONSTRUCTOR
AUTOWIRE_AUTODETECT
 
 	public void setAutowireMode(int autowireMode) {
 		this. = autowireMode;
 	}

Return the autowire mode as specified in the bean definition.
 
 	public int getAutowireMode() {
 		return this.;
 	}

Return the resolved autowire code, (resolving AUTOWIRE_AUTODETECT to AUTOWIRE_CONSTRUCTOR or AUTOWIRE_BY_TYPE).

 
 	public int getResolvedAutowireMode() {
 		if (this. == ) {
 			// Work out whether to apply setter autowiring or constructor autowiring.
 			// If it has a no-arg constructor it's deemed to be setter autowiring,
 			// otherwise we'll try constructor autowiring.
 			Constructor[] constructors = getBeanClass().getConstructors();
 			for (int i = 0; i < constructors.lengthi++) {
 				if (constructors[i].getParameterTypes().length == 0) {
 				}
 			}
 		}
 		else {
 			return this.;
 		}
 	}

Set the dependency check code.

Parameters:
dependencyCheck the code to set. Must be one of the four constants defined in this class.
See also:
DEPENDENCY_CHECK_NONE
DEPENDENCY_CHECK_OBJECTS
DEPENDENCY_CHECK_SIMPLE
DEPENDENCY_CHECK_ALL
 
 	public void setDependencyCheck(int dependencyCheck) {
 		this. = dependencyCheck;
 	}

Return the dependency check code.
 
 	public int getDependencyCheck() {
 		return this.;
 	}

Set the names of the beans that this bean depends on being initialized. The bean factory will guarantee that these beans get initialized before.

Note that dependencies are normally expressed through bean properties or constructor arguments. This property should just be necessary for other kinds of dependencies like statics (*ugh*) or database preparation on startup.

 
 	public void setDependsOn(String[] dependsOn) {
 		this. = dependsOn;
 	}

Return the bean names that this bean depends on.
 
 	public String[] getDependsOn() {
 		return this.;
 	}

Set whether this bean is a candidate for getting autowired into some other bean.
 
 	public void setAutowireCandidate(boolean autowireCandidate) {
 		this. = autowireCandidate;
 	}

Return whether this bean is a candidate for getting autowired into some other bean.
 
 	public boolean isAutowireCandidate() {
 		return this.;
 	}

Register a qualifier to be used for autowire candidate resolution, keyed by the qualifier's type name.

 
 	public void addQualifier(AutowireCandidateQualifier qualifier) {
 		this..put(qualifier.getTypeName(), qualifier);
 	}

Return whether this bean has the specified qualifier.
 
 	public boolean hasQualifier(String typeName) {
 		return this..keySet().contains(typeName);
 	}

Return the qualifier mapped to the provided type name.
 
 		return (AutowireCandidateQualifierthis..get(typeName);
 	}

Return all registered qualifiers.

Returns:
the Set of AutowireCandidateQualifier objects.
 
 	public Set getQualifiers() {
 		return new LinkedHashSet(this..values());
 	}

Copy the qualifiers from the supplied AbstractBeanDefinition to this bean definition.

Parameters:
source the AbstractBeanDefinition to copy from
 
 	protected void copyQualifiersFrom(AbstractBeanDefinition source) {
 		Assert.notNull(source"Source must not be null");
 		this..putAll(source.qualifiers);
 	}

Set whether this bean is a primary autowire candidate. If this value is true for exactly one bean among multiple matching candidates, it will serve as a tie-breaker.
 
 	public void setPrimary(boolean primary) {
 		this. = primary;
 	}

Return whether this bean is a primary autowire candidate. If this value is true for exactly one bean among multiple matching candidates, it will serve as a tie-breaker.
 
 	public boolean isPrimary() {
 		return this.;
 	}


Specify constructor argument values for this bean.
 
 	public void setConstructorArgumentValues(ConstructorArgumentValues constructorArgumentValues) {
 				(constructorArgumentValues != null ? constructorArgumentValues : new ConstructorArgumentValues());
 	}

Return constructor argument values for this bean (never null).
 
 	}

Return if there are constructor argument values defined for this bean.
 
 	public boolean hasConstructorArgumentValues() {
 	}

Specify property values for this bean, if any.
 
 	public void setPropertyValues(MutablePropertyValues propertyValues) {
 		this. = (propertyValues != null ? propertyValues : new MutablePropertyValues());
 	}

Return property values for this bean (never null).
 
 		return this.;
 	}

Specify method overrides for the bean, if any.
 
 	public void setMethodOverrides(MethodOverrides methodOverrides) {
 		this. = (methodOverrides != null ? methodOverrides : new MethodOverrides());
 	}

Return information about methods to be overridden by the IoC container. This will be empty if there are no method overrides. Never returns null.
 
 		return this.;
 	}
 
 
 	public void setFactoryBeanName(String factoryBeanName) {
 		this. = factoryBeanName;
 	}
 
 	public String getFactoryBeanName() {
 		return this.;
 	}
 
 	public void setFactoryMethodName(String factoryMethodName) {
 		this. = factoryMethodName;
 	}
 
 		return this.;
 	}

Set the name of the initializer method. The default is null in which case there is no initializer method.
 
 	public void setInitMethodName(String initMethodName) {
 		this. = initMethodName;
 	}

Return the name of the initializer method.
 
 	public String getInitMethodName() {
 		return this.;
 	}

Specify whether or not the configured init method is the default. Default value is false.

 
 	public void setEnforceInitMethod(boolean enforceInitMethod) {
 		this. = enforceInitMethod;
 	}

Indicate whether the configured init method is the default.

 
 	public boolean isEnforceInitMethod() {
 		return this.;
 	}

Set the name of the destroy method. The default is null in which case there is no destroy method.
 
 	public void setDestroyMethodName(String destroyMethodName) {
 		this. = destroyMethodName;
 	}

Return the name of the destroy method.
 
 		return this.;
 	}

Specify whether or not the configured destroy method is the default. Default value is false.

 
 	public void setEnforceDestroyMethod(boolean enforceDestroyMethod) {
 		this. = enforceDestroyMethod;
 	}

Indicate whether the configured destroy method is the default.

 
 	public boolean isEnforceDestroyMethod() {
 		return this.;
 	}


Set whether this bean definition is 'synthetic', that is, not defined by the application itself (for example, an infrastructure bean such as a helper for auto-proxying, created through &ltaop:config>).
 
 	public void setSynthetic(boolean synthetic) {
 		this. = synthetic;
 	}

Return whether this bean definition is 'synthetic', that is, not defined by the application itself.
 
 	public boolean isSynthetic() {
 		return this.;
 	}

Set the role hint for this BeanDefinition.
 
 	public void setRole(int role) {
 		this. = role;
 	}

Return the role hint for this BeanDefinition.
 
 	public int getRole() {
 		return this.;
 	}


Set a human-readable description of this bean definition.
 
 	public void setDescription(String description) {
 		this. = description;
 	}
 
 	public String getDescription() {
 		return this.;
 	}

Set the resource that this bean definition came from (for the purpose of showing context in case of errors).
 
 	public void setResource(Resource resource) {
 		this. = resource;
 	}

Return the resource that this bean definition came from.
 
 	public Resource getResource() {
 		return this.;
 	}

Set a description of the resource that this bean definition came from (for the purpose of showing context in case of errors).
 
 	public void setResourceDescription(String resourceDescription) {
 		this. = new DescriptiveResource(resourceDescription);
 	}
 
 		return (this. != null ? this..getDescription() : null);
 	}

Set the originating (e.g. decorated) BeanDefinition, if any.
 
 	public void setOriginatingBeanDefinition(BeanDefinition originatingBd) {
 		this. = new BeanDefinitionResource(originatingBd);
 	}
 
 		return (this. instanceof BeanDefinitionResource ?
 	}

Validate this bean definition.

Throws:
BeanDefinitionValidationException in case of validation failure
 
 	public void validate() throws BeanDefinitionValidationException {
 		if (!getMethodOverrides().isEmpty() && getFactoryMethodName() != null) {
 					"Cannot combine static factory method with method overrides: " +
 					"the static factory method must create the instance");
 		}
 
 		if (hasBeanClass()) {
 		}
 	}

Validate and prepare the method overrides defined for this bean. Checks for existence of a method with the specified name.

Throws:
BeanDefinitionValidationException in case of validation failure
 
 		// Check that lookup methods exists.
 		MethodOverrides methodOverrides = getMethodOverrides();
 		if (!methodOverrides.isEmpty()) {
 			for (Iterator it = methodOverrides.getOverrides().iterator(); it.hasNext(); ) {
 			}
 		}
 	}

Validate and prepare the given method override. Checks for existence of a method with the specified name, marking it as not overloaded if none found.

Parameters:
mo the MethodOverride object to validate
Throws:
BeanDefinitionValidationException in case of validation failure
 
 		int count = ClassUtils.getMethodCountForName(getBeanClass(), mo.getMethodName());
 		if (count == 0) {
 					"Invalid method override: no method with name '" + mo.getMethodName() +
 					"' on class [" + getBeanClassName() + "]");
 		}
 		else if (count == 1) {
 			// Mark override as not overloaded, to avoid the overhead of arg type checking.
 			mo.setOverloaded(false);
 		}
 	}


Public declaration of Object's clone() method. Delegates to cloneBeanDefinition().

 
 	public Object clone() {
 	}

Clone this bean definition. To be implemented by concrete subclasses.

Returns:
the cloned bean definition object
 
 
 
 	public boolean equals(Object other) {
 		if (this == other) {
 			return true;
 		}
 		if (!(other instanceof AbstractBeanDefinition)) {
 			return false;
 		}
 
 
 		if (!ObjectUtils.nullSafeEquals(getBeanClassName(), that.getBeanClassName())) return false;
 		if (!ObjectUtils.nullSafeEquals(this.that.scope)) return false;
 		if (this. != that.abstractFlagreturn false;
 		if (this. != that.lazyInitreturn false;
 
 		if (this. != that.autowireModereturn false;
 		if (this. != that.dependencyCheckreturn false;
 		if (!Arrays.equals(this.that.dependsOn)) return false;
 		if (this. != that.autowireCandidatereturn false;
 		if (!ObjectUtils.nullSafeEquals(this.that.qualifiers)) return false;
 		if (this. != that.primaryreturn false;
 
 		if (!ObjectUtils.nullSafeEquals(this.that.constructorArgumentValues)) return false;
 		if (!ObjectUtils.nullSafeEquals(this.that.propertyValues)) return false;
 		if (!ObjectUtils.nullSafeEquals(this.that.methodOverrides)) return false;
 
 		if (!ObjectUtils.nullSafeEquals(this.that.factoryBeanName)) return false;
 		if (!ObjectUtils.nullSafeEquals(this.that.factoryMethodName)) return false;
 		if (!ObjectUtils.nullSafeEquals(this.that.initMethodName)) return false;
 		if (this. != that.enforceInitMethodreturn false;
 		if (!ObjectUtils.nullSafeEquals(this.that.destroyMethodName)) return false;
 		if (this. != that.enforceDestroyMethodreturn false;
 
 		if (this. != that.syntheticreturn false;
 		if (this. != that.rolereturn false;
 
 		return super.equals(other);
 	}
 
 	public int hashCode() {
 		int hashCode = ObjectUtils.nullSafeHashCode(getBeanClassName());
 		hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.);
 		hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.);
 		hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.);
 		hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.);
 		hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.);
 		hashCode = 29 * hashCode + super.hashCode();
 		return hashCode;
 	}
 
 	public String toString() {
 		StringBuffer sb = new StringBuffer("class [");
 		sb.append("; scope=").append(this.);
 		sb.append("; abstract=").append(this.);
 		sb.append("; lazyInit=").append(this.);
 		sb.append("; autowireMode=").append(this.);
 		sb.append("; dependencyCheck=").append(this.);
 		sb.append("; autowireCandidate=").append(this.);
 		sb.append("; primary=").append(this.);
 		sb.append("; factoryBeanName=").append(this.);
 		sb.append("; factoryMethodName=").append(this.);
 		sb.append("; initMethodName=").append(this.);
 		sb.append("; destroyMethodName=").append(this.);
 		if (this. != null) {
 			sb.append("; defined in ").append(this..getDescription());
 		}
 		return sb.toString();
 	}
 
New to GrepCode? Check out our FAQ X