Polishing
This commit is contained in:
parent
7fb0ad37da
commit
f4de1ea147
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 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.
|
||||||
|
@ -202,19 +202,13 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
// Generate the proxy class and create a proxy instance.
|
// Generate the proxy class and create a proxy instance.
|
||||||
return createProxyClassAndInstance(enhancer, callbacks);
|
return createProxyClassAndInstance(enhancer, callbacks);
|
||||||
}
|
}
|
||||||
catch (CodeGenerationException ex) {
|
catch (CodeGenerationException | IllegalArgumentException ex) {
|
||||||
throw new AopConfigException("Could not generate CGLIB subclass of class [" +
|
throw new AopConfigException("Could not generate CGLIB subclass of class [" +
|
||||||
this.advised.getTargetClass() + "]: " +
|
this.advised.getTargetClass() + "]: " +
|
||||||
"Common causes of this problem include using a final class or a non-visible class",
|
"Common causes of this problem include using a final class or a non-visible class",
|
||||||
ex);
|
ex);
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException ex) {
|
catch (Throwable ex) {
|
||||||
throw new AopConfigException("Could not generate CGLIB subclass of class [" +
|
|
||||||
this.advised.getTargetClass() + "]: " +
|
|
||||||
"Common causes of this problem include using a final class or a non-visible class",
|
|
||||||
ex);
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
// TargetSource.getTarget() failed
|
// TargetSource.getTarget() failed
|
||||||
throw new AopConfigException("Unexpected AOP exception", ex);
|
throw new AopConfigException("Unexpected AOP exception", ex);
|
||||||
}
|
}
|
||||||
|
@ -256,7 +250,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
* methods across ClassLoaders, and writes warnings to the log for each one found.
|
* methods across ClassLoaders, and writes warnings to the log for each one found.
|
||||||
*/
|
*/
|
||||||
private void doValidateClass(Class<?> proxySuperClass, ClassLoader proxyClassLoader) {
|
private void doValidateClass(Class<?> proxySuperClass, ClassLoader proxyClassLoader) {
|
||||||
if (Object.class != proxySuperClass) {
|
if (proxySuperClass != Object.class) {
|
||||||
Method[] methods = proxySuperClass.getDeclaredMethods();
|
Method[] methods = proxySuperClass.getDeclaredMethods();
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
int mod = method.getModifiers();
|
int mod = method.getModifiers();
|
||||||
|
|
|
@ -66,18 +66,17 @@ import static org.junit.Assert.*;
|
||||||
*/
|
*/
|
||||||
public class ConfigurationClassPostProcessorTests {
|
public class ConfigurationClassPostProcessorTests {
|
||||||
|
|
||||||
private DefaultListableBeanFactory beanFactory;
|
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setup() {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
|
||||||
QualifierAnnotationAutowireCandidateResolver acr = new QualifierAnnotationAutowireCandidateResolver();
|
QualifierAnnotationAutowireCandidateResolver acr = new QualifierAnnotationAutowireCandidateResolver();
|
||||||
acr.setBeanFactory(bf);
|
acr.setBeanFactory(this.beanFactory);
|
||||||
bf.setAutowireCandidateResolver(acr);
|
this.beanFactory.setAutowireCandidateResolver(acr);
|
||||||
this.beanFactory = bf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enhanced {@link Configuration} classes are only necessary for respecting
|
* Enhanced {@link Configuration} classes are only necessary for respecting
|
||||||
* certain bean semantics, like singleton-scoping, scoped proxies, etc.
|
* certain bean semantics, like singleton-scoping, scoped proxies, etc.
|
||||||
|
@ -950,7 +949,6 @@ public class ConfigurationClassPostProcessorTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public static class RawRepositoryConfiguration {
|
public static class RawRepositoryConfiguration {
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2017 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.
|
||||||
|
@ -22,11 +22,11 @@ import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
import org.springframework.core.type.AnnotationMetadata;
|
import org.springframework.core.type.AnnotationMetadata;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
@ -38,24 +38,15 @@ import static org.junit.Assert.*;
|
||||||
*/
|
*/
|
||||||
public class Spr11202Tests {
|
public class Spr11202Tests {
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext context;
|
@Test
|
||||||
|
|
||||||
@After
|
|
||||||
public void close() {
|
|
||||||
if (context != null) {
|
|
||||||
context.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test // Fails
|
|
||||||
public void testWithImporter() {
|
public void testWithImporter() {
|
||||||
context = new AnnotationConfigApplicationContext(Wrapper.class);
|
ApplicationContext context = new AnnotationConfigApplicationContext(Wrapper.class);
|
||||||
assertEquals("foo", context.getBean("value"));
|
assertEquals("foo", context.getBean("value"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // Passes
|
@Test
|
||||||
public void testWithoutImporter() {
|
public void testWithoutImporter() {
|
||||||
context = new AnnotationConfigApplicationContext(Config.class);
|
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||||
assertEquals("foo", context.getBean("value"));
|
assertEquals("foo", context.getBean("value"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +56,7 @@ public class Spr11202Tests {
|
||||||
protected static class Wrapper {
|
protected static class Wrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static class Selector implements ImportSelector {
|
protected static class Selector implements ImportSelector {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -73,6 +65,7 @@ public class Spr11202Tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
protected static class Config {
|
protected static class Config {
|
||||||
|
|
||||||
|
@ -95,6 +88,7 @@ public class Spr11202Tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static class NoBarCondition implements Condition {
|
protected static class NoBarCondition implements Condition {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -106,12 +100,14 @@ public class Spr11202Tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Documented
|
@Documented
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
protected static @interface Bar {
|
protected @interface Bar {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static class FooFactoryBean implements FactoryBean<Foo>, InitializingBean {
|
protected static class FooFactoryBean implements FactoryBean<Foo>, InitializingBean {
|
||||||
|
|
||||||
private Foo foo = new Foo();
|
private Foo foo = new Foo();
|
||||||
|
@ -137,6 +133,7 @@ public class Spr11202Tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static class Foo {
|
protected static class Foo {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 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.
|
||||||
|
@ -32,6 +32,7 @@ import static org.junit.Assert.*;
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class Spr6602Tests {
|
public class Spr6602Tests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testXmlBehavior() throws Exception {
|
public void testXmlBehavior() throws Exception {
|
||||||
doAssertions(new ClassPathXmlApplicationContext("Spr6602Tests-context.xml", Spr6602Tests.class));
|
doAssertions(new ClassPathXmlApplicationContext("Spr6602Tests-context.xml", Spr6602Tests.class));
|
||||||
|
@ -59,8 +60,10 @@ public class Spr6602Tests {
|
||||||
assertThat(bar3, is(not(bar4)));
|
assertThat(bar3, is(not(bar4)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public static class FooConfig {
|
public static class FooConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Foo foo() throws Exception {
|
public Foo foo() throws Exception {
|
||||||
return new Foo(barFactory().getObject());
|
return new Foo(barFactory().getObject());
|
||||||
|
@ -72,7 +75,9 @@ public class Spr6602Tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class Foo {
|
public static class Foo {
|
||||||
|
|
||||||
final Bar bar;
|
final Bar bar;
|
||||||
|
|
||||||
public Foo(Bar bar) {
|
public Foo(Bar bar) {
|
||||||
|
@ -80,9 +85,11 @@ public class Spr6602Tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class Bar {
|
public static class Bar {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class BarFactory implements FactoryBean<Bar> {
|
public static class BarFactory implements FactoryBean<Bar> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 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.
|
||||||
|
@ -63,8 +63,8 @@ import org.springframework.tests.sample.beans.TestBean;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Miscellaneous system tests covering {@link Bean} naming, aliases, scoping and error
|
* Miscellaneous system tests covering {@link Bean} naming, aliases, scoping and
|
||||||
* handling within {@link Configuration} class definitions.
|
* error handling within {@link Configuration} class definitions.
|
||||||
*
|
*
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
@ -72,30 +72,6 @@ import static org.junit.Assert.*;
|
||||||
*/
|
*/
|
||||||
public class ConfigurationClassProcessingTests {
|
public class ConfigurationClassProcessingTests {
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link BeanFactory}, populates it with a {@link BeanDefinition} for
|
|
||||||
* each of the given {@link Configuration} <var>configClasses</var>, and then
|
|
||||||
* post-processes the factory using JavaConfig's {@link ConfigurationClassPostProcessor}.
|
|
||||||
* When complete, the factory is ready to service requests for any {@link Bean} methods
|
|
||||||
* declared by <var>configClasses</var>.
|
|
||||||
*/
|
|
||||||
private DefaultListableBeanFactory initBeanFactory(Class<?>... configClasses) {
|
|
||||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
|
||||||
for (Class<?> configClass : configClasses) {
|
|
||||||
String configBeanName = configClass.getName();
|
|
||||||
factory.registerBeanDefinition(configBeanName, new RootBeanDefinition(configClass));
|
|
||||||
}
|
|
||||||
ConfigurationClassPostProcessor ccpp = new ConfigurationClassPostProcessor();
|
|
||||||
ccpp.postProcessBeanDefinitionRegistry(factory);
|
|
||||||
ccpp.postProcessBeanFactory(factory);
|
|
||||||
RequiredAnnotationBeanPostProcessor rapp = new RequiredAnnotationBeanPostProcessor();
|
|
||||||
rapp.setBeanFactory(factory);
|
|
||||||
factory.addBeanPostProcessor(rapp);
|
|
||||||
factory.freezeConfiguration();
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final ExpectedException exception = ExpectedException.none();
|
public final ExpectedException exception = ExpectedException.none();
|
||||||
|
|
||||||
|
@ -267,6 +243,30 @@ public class ConfigurationClassProcessingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link BeanFactory}, populates it with a {@link BeanDefinition}
|
||||||
|
* for each of the given {@link Configuration} {@code configClasses}, and then
|
||||||
|
* post-processes the factory using JavaConfig's {@link ConfigurationClassPostProcessor}.
|
||||||
|
* When complete, the factory is ready to service requests for any {@link Bean} methods
|
||||||
|
* declared by {@code configClasses}.
|
||||||
|
*/
|
||||||
|
private DefaultListableBeanFactory initBeanFactory(Class<?>... configClasses) {
|
||||||
|
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||||
|
for (Class<?> configClass : configClasses) {
|
||||||
|
String configBeanName = configClass.getName();
|
||||||
|
factory.registerBeanDefinition(configBeanName, new RootBeanDefinition(configClass));
|
||||||
|
}
|
||||||
|
ConfigurationClassPostProcessor ccpp = new ConfigurationClassPostProcessor();
|
||||||
|
ccpp.postProcessBeanDefinitionRegistry(factory);
|
||||||
|
ccpp.postProcessBeanFactory(factory);
|
||||||
|
RequiredAnnotationBeanPostProcessor rapp = new RequiredAnnotationBeanPostProcessor();
|
||||||
|
rapp.setBeanFactory(factory);
|
||||||
|
factory.addBeanPostProcessor(rapp);
|
||||||
|
factory.freezeConfiguration();
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
static class ConfigWithBeanWithCustomName {
|
static class ConfigWithBeanWithCustomName {
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-20167the 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.
|
||||||
|
@ -1538,14 +1538,8 @@ public class AnnotationUtilsTests {
|
||||||
assertArrayEquals(new char[] { 'x', 'y', 'z' }, chars);
|
assertArrayEquals(new char[] { 'x', 'y', 'z' }, chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
// The following "varargs" suppression is necessary for javac from OpenJDK
|
|
||||||
// (1.8.0_60-b27); however, Eclipse warns that it's unnecessary. See the following
|
|
||||||
// Eclipse issues for details.
|
|
||||||
//
|
|
||||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=344783
|
|
||||||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=349669#c10
|
|
||||||
// @SuppressWarnings("varargs")
|
|
||||||
static <T> T[] asArray(T... arr) {
|
static <T> T[] asArray(T... arr) {
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,31 +40,28 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
|
||||||
* Default ParserContext instance for non-template expressions.
|
* Default ParserContext instance for non-template expressions.
|
||||||
*/
|
*/
|
||||||
private static final ParserContext NON_TEMPLATE_PARSER_CONTEXT = new ParserContext() {
|
private static final ParserContext NON_TEMPLATE_PARSER_CONTEXT = new ParserContext() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getExpressionPrefix() {
|
public String getExpressionPrefix() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getExpressionSuffix() {
|
public String getExpressionSuffix() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTemplate() {
|
public boolean isTemplate() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Expression parseExpression(String expressionString) throws ParseException {
|
public Expression parseExpression(String expressionString) throws ParseException {
|
||||||
return parseExpression(expressionString, NON_TEMPLATE_PARSER_CONTEXT);
|
return parseExpression(expressionString, NON_TEMPLATE_PARSER_CONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Expression parseExpression(String expressionString, ParserContext context)
|
public Expression parseExpression(String expressionString, ParserContext context) throws ParseException {
|
||||||
throws ParseException {
|
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
context = NON_TEMPLATE_PARSER_CONTEXT;
|
context = NON_TEMPLATE_PARSER_CONTEXT;
|
||||||
}
|
}
|
||||||
|
@ -77,11 +74,12 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Expression parseTemplate(String expressionString, ParserContext context)
|
|
||||||
throws ParseException {
|
private Expression parseTemplate(String expressionString, ParserContext context) throws ParseException {
|
||||||
if (expressionString.isEmpty()) {
|
if (expressionString.isEmpty()) {
|
||||||
return new LiteralExpression("");
|
return new LiteralExpression("");
|
||||||
}
|
}
|
||||||
|
|
||||||
Expression[] expressions = parseExpressions(expressionString, context);
|
Expression[] expressions = parseExpressions(expressionString, context);
|
||||||
if (expressions.length == 1) {
|
if (expressions.length == 1) {
|
||||||
return expressions[0];
|
return expressions[0];
|
||||||
|
@ -109,8 +107,7 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
|
||||||
* @return the parsed expressions
|
* @return the parsed expressions
|
||||||
* @throws ParseException when the expressions cannot be parsed
|
* @throws ParseException when the expressions cannot be parsed
|
||||||
*/
|
*/
|
||||||
private Expression[] parseExpressions(String expressionString, ParserContext context)
|
private Expression[] parseExpressions(String expressionString, ParserContext context) throws ParseException {
|
||||||
throws ParseException {
|
|
||||||
List<Expression> expressions = new LinkedList<>();
|
List<Expression> expressions = new LinkedList<>();
|
||||||
String prefix = context.getExpressionPrefix();
|
String prefix = context.getExpressionPrefix();
|
||||||
String suffix = context.getExpressionSuffix();
|
String suffix = context.getExpressionSuffix();
|
||||||
|
@ -120,35 +117,29 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
|
||||||
if (prefixIndex >= startIdx) {
|
if (prefixIndex >= startIdx) {
|
||||||
// an inner expression was found - this is a composite
|
// an inner expression was found - this is a composite
|
||||||
if (prefixIndex > startIdx) {
|
if (prefixIndex > startIdx) {
|
||||||
expressions.add(createLiteralExpression(context,
|
expressions.add(new LiteralExpression(expressionString.substring(startIdx, prefixIndex)));
|
||||||
expressionString.substring(startIdx, prefixIndex)));
|
|
||||||
}
|
}
|
||||||
int afterPrefixIndex = prefixIndex + prefix.length();
|
int afterPrefixIndex = prefixIndex + prefix.length();
|
||||||
int suffixIndex = skipToCorrectEndSuffix(prefix, suffix,
|
int suffixIndex = skipToCorrectEndSuffix(suffix, expressionString, afterPrefixIndex);
|
||||||
expressionString, afterPrefixIndex);
|
|
||||||
|
|
||||||
if (suffixIndex == -1) {
|
if (suffixIndex == -1) {
|
||||||
throw new ParseException(expressionString, prefixIndex,
|
throw new ParseException(expressionString, prefixIndex,
|
||||||
"No ending suffix '" + suffix
|
"No ending suffix '" + suffix + "' for expression starting at character " +
|
||||||
+ "' for expression starting at character "
|
prefixIndex + ": " + expressionString.substring(prefixIndex));
|
||||||
+ prefixIndex + ": "
|
|
||||||
+ expressionString.substring(prefixIndex));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (suffixIndex == afterPrefixIndex) {
|
if (suffixIndex == afterPrefixIndex) {
|
||||||
throw new ParseException(expressionString, prefixIndex,
|
throw new ParseException(expressionString, prefixIndex,
|
||||||
"No expression defined within delimiter '" + prefix + suffix
|
"No expression defined within delimiter '" + prefix + suffix +
|
||||||
+ "' at character " + prefixIndex);
|
"' at character " + prefixIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
String expr = expressionString.substring(prefixIndex + prefix.length(),
|
String expr = expressionString.substring(prefixIndex + prefix.length(), suffixIndex);
|
||||||
suffixIndex);
|
|
||||||
expr = expr.trim();
|
expr = expr.trim();
|
||||||
|
|
||||||
if (expr.isEmpty()) {
|
if (expr.isEmpty()) {
|
||||||
throw new ParseException(expressionString, prefixIndex,
|
throw new ParseException(expressionString, prefixIndex,
|
||||||
"No expression defined within delimiter '" + prefix + suffix
|
"No expression defined within delimiter '" + prefix + suffix +
|
||||||
+ "' at character " + prefixIndex);
|
"' at character " + prefixIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
expressions.add(doParseExpression(expr, context));
|
expressions.add(doParseExpression(expr, context));
|
||||||
|
@ -156,18 +147,13 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// no more ${expressions} found in string, add rest as static text
|
// no more ${expressions} found in string, add rest as static text
|
||||||
expressions.add(createLiteralExpression(context,
|
expressions.add(new LiteralExpression(expressionString.substring(startIdx)));
|
||||||
expressionString.substring(startIdx)));
|
|
||||||
startIdx = expressionString.length();
|
startIdx = expressionString.length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return expressions.toArray(new Expression[expressions.size()]);
|
return expressions.toArray(new Expression[expressions.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Expression createLiteralExpression(ParserContext context, String text) {
|
|
||||||
return new LiteralExpression(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if the specified suffix can be found at the supplied position in the
|
* Return true if the specified suffix can be found at the supplied position in the
|
||||||
* supplied expression string.
|
* supplied expression string.
|
||||||
|
@ -192,15 +178,15 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
|
||||||
/**
|
/**
|
||||||
* Copes with nesting, for example '${...${...}}' where the correct end for the first
|
* Copes with nesting, for example '${...${...}}' where the correct end for the first
|
||||||
* ${ is the final }.
|
* ${ is the final }.
|
||||||
* @param prefix the prefix
|
|
||||||
* @param suffix the suffix
|
* @param suffix the suffix
|
||||||
* @param expressionString the expression string
|
* @param expressionString the expression string
|
||||||
* @param afterPrefixIndex the most recently found prefix location for which the
|
* @param afterPrefixIndex the most recently found prefix location for which the
|
||||||
* matching end suffix is being sought
|
* matching end suffix is being sought
|
||||||
* @return the position of the correct matching nextSuffix or -1 if none can be found
|
* @return the position of the correct matching nextSuffix or -1 if none can be found
|
||||||
*/
|
*/
|
||||||
private int skipToCorrectEndSuffix(String prefix, String suffix,
|
private int skipToCorrectEndSuffix(String suffix, String expressionString, int afterPrefixIndex)
|
||||||
String expressionString, int afterPrefixIndex) throws ParseException {
|
throws ParseException {
|
||||||
|
|
||||||
// Chew on the expression text - relying on the rules:
|
// Chew on the expression text - relying on the rules:
|
||||||
// brackets must be in pairs: () [] {}
|
// brackets must be in pairs: () [] {}
|
||||||
// string literals are "..." or '...' and these may contain unmatched brackets
|
// string literals are "..." or '...' and these may contain unmatched brackets
|
||||||
|
@ -226,16 +212,15 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
|
||||||
case ']':
|
case ']':
|
||||||
case ')':
|
case ')':
|
||||||
if (stack.isEmpty()) {
|
if (stack.isEmpty()) {
|
||||||
throw new ParseException(expressionString, pos, "Found closing '"
|
throw new ParseException(expressionString, pos, "Found closing '" + ch +
|
||||||
+ ch + "' at position " + pos + " without an opening '"
|
"' at position " + pos + " without an opening '" +
|
||||||
+ Bracket.theOpenBracketFor(ch) + "'");
|
Bracket.theOpenBracketFor(ch) + "'");
|
||||||
}
|
}
|
||||||
Bracket p = stack.pop();
|
Bracket p = stack.pop();
|
||||||
if (!p.compatibleWithCloseBracket(ch)) {
|
if (!p.compatibleWithCloseBracket(ch)) {
|
||||||
throw new ParseException(expressionString, pos, "Found closing '"
|
throw new ParseException(expressionString, pos, "Found closing '" + ch +
|
||||||
+ ch + "' at position " + pos
|
"' at position " + pos + " but most recent opening is '" + p.bracket +
|
||||||
+ " but most recent opening is '" + p.bracket
|
"' at position " + p.pos);
|
||||||
+ "' at position " + p.pos);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\'':
|
case '\'':
|
||||||
|
@ -244,8 +229,7 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
|
||||||
int endLiteral = expressionString.indexOf(ch, pos + 1);
|
int endLiteral = expressionString.indexOf(ch, pos + 1);
|
||||||
if (endLiteral == -1) {
|
if (endLiteral == -1) {
|
||||||
throw new ParseException(expressionString, pos,
|
throw new ParseException(expressionString, pos,
|
||||||
"Found non terminating string literal starting at position "
|
"Found non terminating string literal starting at position " + pos);
|
||||||
+ pos);
|
|
||||||
}
|
}
|
||||||
pos = endLiteral;
|
pos = endLiteral;
|
||||||
break;
|
break;
|
||||||
|
@ -254,9 +238,8 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
|
||||||
}
|
}
|
||||||
if (!stack.isEmpty()) {
|
if (!stack.isEmpty()) {
|
||||||
Bracket p = stack.pop();
|
Bracket p = stack.pop();
|
||||||
throw new ParseException(expressionString, p.pos, "Missing closing '"
|
throw new ParseException(expressionString, p.pos, "Missing closing '" +
|
||||||
+ Bracket.theCloseBracketFor(p.bracket) + "' for '" + p.bracket
|
Bracket.theCloseBracketFor(p.bracket) + "' for '" + p.bracket + "' at position " + p.pos);
|
||||||
+ "' at position " + p.pos);
|
|
||||||
}
|
}
|
||||||
if (!isSuffixHere(expressionString, pos, suffix)) {
|
if (!isSuffixHere(expressionString, pos, suffix)) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -265,6 +248,17 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actually parse the expression string and return an Expression object.
|
||||||
|
* @param expressionString the raw expression string to parse
|
||||||
|
* @param context a context for influencing this expression parsing routine (optional)
|
||||||
|
* @return an evaluator for the parsed expression
|
||||||
|
* @throws ParseException an exception occurred during parsing
|
||||||
|
*/
|
||||||
|
protected abstract Expression doParseExpression(String expressionString, ParserContext context)
|
||||||
|
throws ParseException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This captures a type of bracket and the position in which it occurs in the
|
* This captures a type of bracket and the position in which it occurs in the
|
||||||
* expression. The positional information is used if an error has to be reported
|
* expression. The positional information is used if an error has to be reported
|
||||||
|
@ -313,14 +307,4 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Actually parse the expression string and return an Expression object.
|
|
||||||
* @param expressionString the raw expression string to parse
|
|
||||||
* @param context a context for influencing this expression parsing routine (optional)
|
|
||||||
* @return an evaluator for the parsed expression
|
|
||||||
* @throws ParseException an exception occurred during parsing
|
|
||||||
*/
|
|
||||||
protected abstract Expression doParseExpression(String expressionString,
|
|
||||||
ParserContext context) throws ParseException;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1361,7 +1361,7 @@ element.
|
||||||
|
|
||||||
<bean id="theClientBean" class="...">
|
<bean id="theClientBean" class="...">
|
||||||
<property name="targetName">
|
<property name="targetName">
|
||||||
<idref bean="theTargetBean" />
|
<idref bean="theTargetBean"/>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
----
|
----
|
||||||
|
@ -1375,7 +1375,7 @@ following snippet:
|
||||||
<bean id="theTargetBean" class="..." />
|
<bean id="theTargetBean" class="..." />
|
||||||
|
|
||||||
<bean id="client" class="...">
|
<bean id="client" class="...">
|
||||||
<property name="targetName" value="theTargetBean" />
|
<property name="targetName" value="theTargetBean"/>
|
||||||
</bean>
|
</bean>
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue