Skip to content

Commit

Permalink
Removed parsing support for the 'singleton' attribute in an XML bean …
Browse files Browse the repository at this point in the history
…definition

Following the introduction of spring-beans-4.0.xsd and the corresponding removal of the pre-2.0 spring-beans.dtd.

Issue: SPR-10437
  • Loading branch information
jhoeller authored and unknown committed May 7, 2013
1 parent 0fc5a5d commit 2c3a8a5
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess

private String scope = SCOPE_DEFAULT;

private boolean singleton = true;

private boolean prototype = false;

private boolean abstractFlag = false;

private boolean lazyInit = false;
Expand Down Expand Up @@ -409,8 +405,6 @@ public Class resolveBeanClass(ClassLoader classLoader) throws ClassNotFoundExcep
*/
public void setScope(String scope) {
this.scope = scope;
this.singleton = SCOPE_SINGLETON.equals(scope) || SCOPE_DEFAULT.equals(scope);
this.prototype = SCOPE_PROTOTYPE.equals(scope);
}

/**
Expand All @@ -420,33 +414,13 @@ public String getScope() {
return this.scope;
}

/**
* Set if this a <b>Singleton</b>, with a single, shared instance returned
* on all calls. In case of "false", the BeanFactory will apply the <b>Prototype</b>
* design pattern, with each caller requesting an instance getting an independent
* instance. How this is exactly defined will depend on the BeanFactory.
* <p>"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".
* @deprecated since Spring 2.5, in favor of {@link #setScope}
* @see #setScope
* @see #SCOPE_SINGLETON
* @see #SCOPE_PROTOTYPE
*/
@Deprecated
public void setSingleton(boolean singleton) {
this.scope = (singleton ? SCOPE_SINGLETON : SCOPE_PROTOTYPE);
this.singleton = singleton;
this.prototype = !singleton;
}

/**
* Return whether this a <b>Singleton</b>, with a single shared instance
* returned from all calls.
* @see #SCOPE_SINGLETON
*/
public boolean isSingleton() {
return this.singleton;
return SCOPE_SINGLETON.equals(scope) || SCOPE_DEFAULT.equals(scope);
}

/**
Expand All @@ -455,7 +429,7 @@ public boolean isSingleton() {
* @see #SCOPE_PROTOTYPE
*/
public boolean isPrototype() {
return this.prototype;
return SCOPE_PROTOTYPE.equals(scope);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
Expand Down Expand Up @@ -166,28 +166,6 @@ public BeanDefinitionBuilder setFactoryMethod(String factoryMethod) {
return this;
}

/**
* Set the name of the factory bean to use for this definition.
* @deprecated since Spring 2.5, in favor of preparing this on the
* {@link #getRawBeanDefinition() raw BeanDefinition object}
*/
@Deprecated
public BeanDefinitionBuilder setFactoryBean(String factoryBean, String factoryMethod) {
this.beanDefinition.setFactoryBeanName(factoryBean);
this.beanDefinition.setFactoryMethodName(factoryMethod);
return this;
}

/**
* Add an indexed constructor arg value. The current index is tracked internally
* and all additions are at the present point.
* @deprecated since Spring 2.5, in favor of {@link #addConstructorArgValue}
*/
@Deprecated
public BeanDefinitionBuilder addConstructorArg(Object value) {
return addConstructorArgValue(value);
}

/**
* Add an indexed constructor arg value. The current index is tracked internally
* and all additions are at the present point.
Expand Down Expand Up @@ -253,17 +231,6 @@ public BeanDefinitionBuilder setScope(String scope) {
return this;
}

/**
* Set whether or not this definition describes a singleton bean,
* as alternative to {@link #setScope}.
* @deprecated since Spring 2.5, in favor of {@link #setScope}
*/
@Deprecated
public BeanDefinitionBuilder setSingleton(boolean singleton) {
this.beanDefinition.setSingleton(singleton);
return this;
}

/**
* Set whether or not this definition is abstract.
*/
Expand Down Expand Up @@ -319,26 +286,4 @@ public BeanDefinitionBuilder setRole(int role) {
return this;
}

/**
* Set the source of this definition.
* @deprecated since Spring 2.5, in favor of preparing this on the
* {@link #getRawBeanDefinition() raw BeanDefinition object}
*/
@Deprecated
public BeanDefinitionBuilder setSource(Object source) {
this.beanDefinition.setSource(source);
return this;
}

/**
* Set the description associated with this definition.
* @deprecated since Spring 2.5, in favor of preparing this on the
* {@link #getRawBeanDefinition() raw BeanDefinition object}
*/
@Deprecated
public BeanDefinitionBuilder setResourceDescription(String resourceDescription) {
this.beanDefinition.setResourceDescription(resourceDescription);
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,33 +113,6 @@ public RootBeanDefinition(Class beanClass) {
setBeanClass(beanClass);
}

/**
* Create a new RootBeanDefinition with the given singleton status.
* @param beanClass the class of the bean to instantiate
* @param singleton the singleton status of the bean
* @deprecated since Spring 2.5, in favor of {@link #setScope}
*/
@Deprecated
public RootBeanDefinition(Class beanClass, boolean singleton) {
super();
setBeanClass(beanClass);
setSingleton(singleton);
}

/**
* Create a new RootBeanDefinition for a singleton,
* using the given autowire mode.
* @param beanClass the class of the bean to instantiate
* @param autowireMode by name or type, using the constants in this interface
* @deprecated as of Spring 3.0, in favor of {@link #setAutowireMode} usage
*/
@Deprecated
public RootBeanDefinition(Class beanClass, int autowireMode) {
super();
setBeanClass(beanClass);
setAutowireMode(autowireMode);
}

/**
* Create a new RootBeanDefinition for a singleton,
* using the given autowire mode.
Expand All @@ -157,34 +130,6 @@ public RootBeanDefinition(Class beanClass, int autowireMode, boolean dependencyC
}
}

/**
* Create a new RootBeanDefinition for a singleton,
* providing property values.
* @param beanClass the class of the bean to instantiate
* @param pvs the property values to apply
* @deprecated as of Spring 3.0, in favor of {@link #getPropertyValues} usage
*/
@Deprecated
public RootBeanDefinition(Class beanClass, MutablePropertyValues pvs) {
super(null, pvs);
setBeanClass(beanClass);
}

/**
* Create a new RootBeanDefinition with the given singleton status,
* providing property values.
* @param beanClass the class of the bean to instantiate
* @param pvs the property values to apply
* @param singleton the singleton status of the bean
* @deprecated since Spring 2.5, in favor of {@link #setScope}
*/
@Deprecated
public RootBeanDefinition(Class beanClass, MutablePropertyValues pvs, boolean singleton) {
super(null, pvs);
setBeanClass(beanClass);
setSingleton(singleton);
}

/**
* Create a new RootBeanDefinition for a singleton,
* providing constructor arguments and property values.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
Expand Down Expand Up @@ -137,8 +137,6 @@ public class BeanDefinitionParserDelegate {

public static final String SCOPE_ATTRIBUTE = "scope";

public static final String SINGLETON_ATTRIBUTE = "singleton";

public static final String LAZY_INIT_ATTRIBUTE = "lazy-init";

public static final String AUTOWIRE_ATTRIBUTE = "autowire";
Expand Down Expand Up @@ -598,16 +596,7 @@ public AbstractBeanDefinition parseBeanDefinitionAttributes(Element ele, String
BeanDefinition containingBean, AbstractBeanDefinition bd) {

if (ele.hasAttribute(SCOPE_ATTRIBUTE)) {
// Spring 2.x "scope" attribute
bd.setScope(ele.getAttribute(SCOPE_ATTRIBUTE));
if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) {
error("Specify either 'scope' or 'singleton', not both", ele);
}
}
else if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) {
// Spring 1.x "singleton" attribute
bd.setScope(TRUE_VALUE.equals(ele.getAttribute(SINGLETON_ATTRIBUTE)) ?
BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE);
}
else if (containingBean != null) {
// Take default from containing bean in case of an inner bean definition.
Expand Down

0 comments on commit 2c3a8a5

Please sign in to comment.