+ Eliminated .util package
+ Renamed DefaultScopes -> Scopes + Renamed MalformedJavaConfigurationException -> MalformedConfigurationException
This commit is contained in:
parent
f43e1110e9
commit
c0c8117d51
|
|
@ -26,16 +26,16 @@ import java.util.List;
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class MalformedJavaConfigurationException extends RuntimeException {
|
public class MalformedConfigurationException extends RuntimeException {
|
||||||
|
|
||||||
private final List<? extends UsageError> errors;
|
private final List<? extends UsageError> errors;
|
||||||
|
|
||||||
public MalformedJavaConfigurationException(String message) {
|
public MalformedConfigurationException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
this.errors = new ArrayList<UsageError>();
|
this.errors = new ArrayList<UsageError>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MalformedJavaConfigurationException(UsageError... errors) {
|
public MalformedConfigurationException(UsageError... errors) {
|
||||||
super(toString(errors));
|
super(toString(errors));
|
||||||
this.errors = Arrays.asList(errors);
|
this.errors = Arrays.asList(errors);
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2009 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -13,22 +13,26 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.config.java.util;
|
package org.springframework.config.java;
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constant class contains the names of the scopes supported out of the box in Spring 2.0.
|
* Enumerates the names of the scopes supported out of the box in Spring.
|
||||||
|
* <p>
|
||||||
|
* Not modeled as an actual java enum because annotations that accept a scope
|
||||||
|
* attribute must allow for user-defined scope names. Given that java
|
||||||
|
* enums are not extensible, these must remain simple string constants.
|
||||||
*
|
*
|
||||||
* @author Costin Leau
|
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public abstract class DefaultScopes {
|
public class Scopes {
|
||||||
|
|
||||||
|
private Scopes() { }
|
||||||
|
|
||||||
public static final String SINGLETON = BeanDefinition.SCOPE_SINGLETON;
|
public static final String SINGLETON = "singleton"; // see BeanDefinition.SCOPE_SINGLETON;
|
||||||
|
|
||||||
public static final String PROTOTYPE = BeanDefinition.SCOPE_PROTOTYPE;
|
public static final String PROTOTYPE = "prototype"; // see BeanDefinition.SCOPE_PROTOTYPE;
|
||||||
|
|
||||||
public static final String REQUEST = "request"; // see WebApplicationContext.SCOPE_REQUEST;
|
public static final String REQUEST = "request"; // see WebApplicationContext.SCOPE_REQUEST;
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ package org.springframework.config.java;
|
||||||
* possible usage errors.
|
* possible usage errors.
|
||||||
*
|
*
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
* @see MalformedJavaConfigurationException
|
* @see MalformedConfigurationException
|
||||||
*/
|
*/
|
||||||
public abstract class UsageError {
|
public abstract class UsageError {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import org.springframework.config.java.ConfigurationClass;
|
||||||
import org.springframework.config.java.ConfigurationModel;
|
import org.springframework.config.java.ConfigurationModel;
|
||||||
import org.springframework.config.java.Factory;
|
import org.springframework.config.java.Factory;
|
||||||
import org.springframework.config.java.ModelMethod;
|
import org.springframework.config.java.ModelMethod;
|
||||||
|
import org.springframework.config.java.Scopes;
|
||||||
import org.springframework.config.java.UsageError;
|
import org.springframework.config.java.UsageError;
|
||||||
import org.springframework.config.java.Validator;
|
import org.springframework.config.java.Validator;
|
||||||
|
|
||||||
|
|
@ -90,7 +91,7 @@ public @interface Bean {
|
||||||
* Scope: whether the bean is a singleton, prototype or custom scope.
|
* Scope: whether the bean is a singleton, prototype or custom scope.
|
||||||
* Default is singleton.
|
* Default is singleton.
|
||||||
*/
|
*/
|
||||||
String scope() default BeanDefinition.SCOPE_SINGLETON;
|
String scope() default Scopes.SINGLETON;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bean autowire strategy.
|
* Bean autowire strategy.
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
import org.springframework.config.java.BeanDefinitionRegistrar;
|
import org.springframework.config.java.BeanDefinitionRegistrar;
|
||||||
import org.springframework.config.java.Configuration;
|
import org.springframework.config.java.Configuration;
|
||||||
import org.springframework.config.java.ConfigurationClass;
|
import org.springframework.config.java.ConfigurationClass;
|
||||||
import org.springframework.config.java.MalformedJavaConfigurationException;
|
import org.springframework.config.java.MalformedConfigurationException;
|
||||||
import org.springframework.config.java.ModelMethod;
|
import org.springframework.config.java.ModelMethod;
|
||||||
import org.springframework.config.java.UsageError;
|
import org.springframework.config.java.UsageError;
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
|
|
@ -72,7 +72,7 @@ class BeanRegistrar implements BeanDefinitionRegistrar {
|
||||||
// ensure that overriding is ok
|
// ensure that overriding is ok
|
||||||
if (bean.allowOverriding() == false) {
|
if (bean.allowOverriding() == false) {
|
||||||
UsageError error = configClass.new IllegalBeanOverrideError(null, method);
|
UsageError error = configClass.new IllegalBeanOverrideError(null, method);
|
||||||
throw new MalformedJavaConfigurationException(error);
|
throw new MalformedConfigurationException(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// overriding is legal, return immediately
|
// overriding is legal, return immediately
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.config.java.Configuration;
|
import org.springframework.config.java.Configuration;
|
||||||
import org.springframework.config.java.ConfigurationModel;
|
import org.springframework.config.java.ConfigurationModel;
|
||||||
import org.springframework.config.java.MalformedJavaConfigurationException;
|
import org.springframework.config.java.MalformedConfigurationException;
|
||||||
import org.springframework.config.java.UsageError;
|
import org.springframework.config.java.UsageError;
|
||||||
import org.springframework.config.java.internal.enhancement.ConfigurationEnhancer;
|
import org.springframework.config.java.internal.enhancement.ConfigurationEnhancer;
|
||||||
import org.springframework.config.java.internal.parsing.ConfigurationParser;
|
import org.springframework.config.java.internal.parsing.ConfigurationParser;
|
||||||
|
|
@ -102,7 +102,7 @@ public class ConfigurationPostProcessor implements Ordered, BeanFactoryPostProce
|
||||||
ArrayList<UsageError> errors = new ArrayList<UsageError>();
|
ArrayList<UsageError> errors = new ArrayList<UsageError>();
|
||||||
model.validate(errors);
|
model.validate(errors);
|
||||||
if (errors.size() > 0)
|
if (errors.size() > 0)
|
||||||
throw new MalformedJavaConfigurationException(errors.toArray(new UsageError[] { }));
|
throw new MalformedConfigurationException(errors.toArray(new UsageError[] { }));
|
||||||
|
|
||||||
modelBeanDefinitionReader.loadBeanDefinitions(model);
|
modelBeanDefinitionReader.loadBeanDefinitions(model);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,9 @@ import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostP
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.config.java.Configuration;
|
import org.springframework.config.java.Configuration;
|
||||||
|
import org.springframework.config.java.Scopes;
|
||||||
import org.springframework.config.java.ext.Bean;
|
import org.springframework.config.java.ext.Bean;
|
||||||
import org.springframework.config.java.support.ConfigurationPostProcessor;
|
import org.springframework.config.java.support.ConfigurationPostProcessor;
|
||||||
import org.springframework.config.java.util.DefaultScopes;
|
|
||||||
|
|
||||||
import test.beans.ITestBean;
|
import test.beans.ITestBean;
|
||||||
import test.beans.TestBean;
|
import test.beans.TestBean;
|
||||||
|
|
@ -89,7 +89,7 @@ public class BasicTests {
|
||||||
return bar;
|
return bar;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean(scope=DefaultScopes.PROTOTYPE)
|
@Bean(scope=Scopes.PROTOTYPE)
|
||||||
public TestBean baz() {
|
public TestBean baz() {
|
||||||
return new TestBean("bar");
|
return new TestBean("bar");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue