org.springframework.expression.ConstructorResolver Java Examples

The following examples show how to use org.springframework.expression.ConstructorResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConstructorInvocationTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddingConstructorResolvers() {
	StandardEvaluationContext ctx = new StandardEvaluationContext();

	// reflective constructor accessor is the only one by default
	List<ConstructorResolver> constructorResolvers = ctx.getConstructorResolvers();
	assertEquals(1, constructorResolvers.size());

	ConstructorResolver dummy = new DummyConstructorResolver();
	ctx.addConstructorResolver(dummy);
	assertEquals(2, ctx.getConstructorResolvers().size());

	List<ConstructorResolver> copy = new ArrayList<ConstructorResolver>();
	copy.addAll(ctx.getConstructorResolvers());
	assertTrue(ctx.removeConstructorResolver(dummy));
	assertFalse(ctx.removeConstructorResolver(dummy));
	assertEquals(1, ctx.getConstructorResolvers().size());

	ctx.setConstructorResolvers(copy);
	assertEquals(2, ctx.getConstructorResolvers().size());
}
 
Example #2
Source File: ConstructorReference.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Go through the list of registered constructor resolvers and see if any can find a
 * constructor that takes the specified set of arguments.
 * @param typeName the type trying to be constructed
 * @param argumentTypes the types of the arguments supplied that the constructor must take
 * @param state the current state of the expression
 * @return a reusable ConstructorExecutor that can be invoked to run the constructor or null
 * @throws SpelEvaluationException if there is a problem locating the constructor
 */
private ConstructorExecutor findExecutorForConstructor(String typeName,
		List<TypeDescriptor> argumentTypes, ExpressionState state)
		throws SpelEvaluationException {

	EvaluationContext evalContext = state.getEvaluationContext();
	List<ConstructorResolver> ctorResolvers = evalContext.getConstructorResolvers();
	if (ctorResolvers != null) {
		for (ConstructorResolver ctorResolver : ctorResolvers) {
			try {
				ConstructorExecutor ce = ctorResolver.resolve(state.getEvaluationContext(), typeName, argumentTypes);
				if (ce != null) {
					return ce;
				}
			}
			catch (AccessException ex) {
				throw new SpelEvaluationException(getStartPosition(), ex,
						SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM, typeName,
						FormatHelper.formatMethodForMessage("", argumentTypes));
			}
		}
	}
	throw new SpelEvaluationException(getStartPosition(), SpelMessage.CONSTRUCTOR_NOT_FOUND, typeName,
			FormatHelper.formatMethodForMessage("", argumentTypes));
}
 
Example #3
Source File: ConstructorReference.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Go through the list of registered constructor resolvers and see if any can find a
 * constructor that takes the specified set of arguments.
 * @param typeName the type trying to be constructed
 * @param argumentTypes the types of the arguments supplied that the constructor must take
 * @param state the current state of the expression
 * @return a reusable ConstructorExecutor that can be invoked to run the constructor or null
 * @throws SpelEvaluationException if there is a problem locating the constructor
 */
private ConstructorExecutor findExecutorForConstructor(String typeName,
		List<TypeDescriptor> argumentTypes, ExpressionState state)
		throws SpelEvaluationException {

	EvaluationContext evalContext = state.getEvaluationContext();
	List<ConstructorResolver> ctorResolvers = evalContext.getConstructorResolvers();
	if (ctorResolvers != null) {
		for (ConstructorResolver ctorResolver : ctorResolvers) {
			try {
				ConstructorExecutor ce = ctorResolver.resolve(state.getEvaluationContext(), typeName, argumentTypes);
				if (ce != null) {
					return ce;
				}
			}
			catch (AccessException ex) {
				throw new SpelEvaluationException(getStartPosition(), ex,
						SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM, typeName,
						FormatHelper.formatMethodForMessage("", argumentTypes));
			}
		}
	}
	throw new SpelEvaluationException(getStartPosition(), SpelMessage.CONSTRUCTOR_NOT_FOUND, typeName,
			FormatHelper.formatMethodForMessage("", argumentTypes));
}
 
Example #4
Source File: ConstructorInvocationTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testAddingConstructorResolvers() {
	StandardEvaluationContext ctx = new StandardEvaluationContext();

	// reflective constructor accessor is the only one by default
	List<ConstructorResolver> constructorResolvers = ctx.getConstructorResolvers();
	assertEquals(1, constructorResolvers.size());

	ConstructorResolver dummy = new DummyConstructorResolver();
	ctx.addConstructorResolver(dummy);
	assertEquals(2, ctx.getConstructorResolvers().size());

	List<ConstructorResolver> copy = new ArrayList<>();
	copy.addAll(ctx.getConstructorResolvers());
	assertTrue(ctx.removeConstructorResolver(dummy));
	assertFalse(ctx.removeConstructorResolver(dummy));
	assertEquals(1, ctx.getConstructorResolvers().size());

	ctx.setConstructorResolvers(copy);
	assertEquals(2, ctx.getConstructorResolvers().size());
}
 
Example #5
Source File: ConstructorInvocationTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testAddingConstructorResolvers() {
	StandardEvaluationContext ctx = new StandardEvaluationContext();

	// reflective constructor accessor is the only one by default
	List<ConstructorResolver> constructorResolvers = ctx.getConstructorResolvers();
	assertEquals(1, constructorResolvers.size());

	ConstructorResolver dummy = new DummyConstructorResolver();
	ctx.addConstructorResolver(dummy);
	assertEquals(2, ctx.getConstructorResolvers().size());

	List<ConstructorResolver> copy = new ArrayList<>();
	copy.addAll(ctx.getConstructorResolvers());
	assertTrue(ctx.removeConstructorResolver(dummy));
	assertFalse(ctx.removeConstructorResolver(dummy));
	assertEquals(1, ctx.getConstructorResolvers().size());

	ctx.setConstructorResolvers(copy);
	assertEquals(2, ctx.getConstructorResolvers().size());
}
 
Example #6
Source File: ConstructorReference.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Go through the list of registered constructor resolvers and see if any can find a
 * constructor that takes the specified set of arguments.
 * @param typeName the type trying to be constructed
 * @param argumentTypes the types of the arguments supplied that the constructor must take
 * @param state the current state of the expression
 * @return a reusable ConstructorExecutor that can be invoked to run the constructor or null
 * @throws SpelEvaluationException if there is a problem locating the constructor
 */
private ConstructorExecutor findExecutorForConstructor(String typeName,
		List<TypeDescriptor> argumentTypes, ExpressionState state) throws SpelEvaluationException {

	EvaluationContext evalContext = state.getEvaluationContext();
	List<ConstructorResolver> ctorResolvers = evalContext.getConstructorResolvers();
	for (ConstructorResolver ctorResolver : ctorResolvers) {
		try {
			ConstructorExecutor ce = ctorResolver.resolve(state.getEvaluationContext(), typeName, argumentTypes);
			if (ce != null) {
				return ce;
			}
		}
		catch (AccessException ex) {
			throw new SpelEvaluationException(getStartPosition(), ex,
					SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM, typeName,
					FormatHelper.formatMethodForMessage("", argumentTypes));
		}
	}
	throw new SpelEvaluationException(getStartPosition(), SpelMessage.CONSTRUCTOR_NOT_FOUND, typeName,
			FormatHelper.formatMethodForMessage("", argumentTypes));
}
 
Example #7
Source File: ConstructorReference.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Go through the list of registered constructor resolvers and see if any can find a
 * constructor that takes the specified set of arguments.
 * @param typeName the type trying to be constructed
 * @param argumentTypes the types of the arguments supplied that the constructor must take
 * @param state the current state of the expression
 * @return a reusable ConstructorExecutor that can be invoked to run the constructor or null
 * @throws SpelEvaluationException if there is a problem locating the constructor
 */
private ConstructorExecutor findExecutorForConstructor(String typeName,
		List<TypeDescriptor> argumentTypes, ExpressionState state) throws SpelEvaluationException {

	EvaluationContext evalContext = state.getEvaluationContext();
	List<ConstructorResolver> ctorResolvers = evalContext.getConstructorResolvers();
	for (ConstructorResolver ctorResolver : ctorResolvers) {
		try {
			ConstructorExecutor ce = ctorResolver.resolve(state.getEvaluationContext(), typeName, argumentTypes);
			if (ce != null) {
				return ce;
			}
		}
		catch (AccessException ex) {
			throw new SpelEvaluationException(getStartPosition(), ex,
					SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM, typeName,
					FormatHelper.formatMethodForMessage("", argumentTypes));
		}
	}
	throw new SpelEvaluationException(getStartPosition(), SpelMessage.CONSTRUCTOR_NOT_FOUND, typeName,
			FormatHelper.formatMethodForMessage("", argumentTypes));
}
 
Example #8
Source File: StandardEvaluationContext.java    From java-technology-stack with MIT License 5 votes vote down vote up
private List<ConstructorResolver> initConstructorResolvers() {
	List<ConstructorResolver> resolvers = this.constructorResolvers;
	if (resolvers == null) {
		resolvers = new ArrayList<>(1);
		resolvers.add(new ReflectiveConstructorResolver());
		this.constructorResolvers = resolvers;
	}
	return resolvers;
}
 
Example #9
Source File: StandardEvaluationContext.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private synchronized void initializeConstructorResolvers() {
	if (this.constructorResolvers == null) {
		List<ConstructorResolver> defaultResolvers = new ArrayList<ConstructorResolver>();
		defaultResolvers.add(new ReflectiveConstructorResolver());
		this.constructorResolvers = defaultResolvers;
	}
}
 
Example #10
Source File: StandardEvaluationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void initializeConstructorResolvers() {
	if (this.constructorResolvers == null) {
		List<ConstructorResolver> defaultResolvers = new ArrayList<ConstructorResolver>();
		defaultResolvers.add(new ReflectiveConstructorResolver());
		this.constructorResolvers = defaultResolvers;
	}
}
 
Example #11
Source File: StandardEvaluationContext.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private List<ConstructorResolver> initConstructorResolvers() {
	List<ConstructorResolver> resolvers = this.constructorResolvers;
	if (resolvers == null) {
		resolvers = new ArrayList<>(1);
		resolvers.add(new ReflectiveConstructorResolver());
		this.constructorResolvers = resolvers;
	}
	return resolvers;
}
 
Example #12
Source File: StandardEvaluationContext.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void addConstructorResolver(ConstructorResolver resolver) {
	ensureConstructorResolversInitialized();
	this.constructorResolvers.add(this.constructorResolvers.size() - 1, resolver);
}
 
Example #13
Source File: SimpleEvaluationContext.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Return an empty list, always, since this context does not support the
 * use of type references.
 */
@Override
public List<ConstructorResolver> getConstructorResolvers() {
	return Collections.emptyList();
}
 
Example #14
Source File: StandardEvaluationContext.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public void setConstructorResolvers(List<ConstructorResolver> constructorResolvers) {
	this.constructorResolvers = constructorResolvers;
}
 
Example #15
Source File: StandardEvaluationContext.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public List<ConstructorResolver> getConstructorResolvers() {
	ensureConstructorResolversInitialized();
	return this.constructorResolvers;
}
 
Example #16
Source File: StandardEvaluationContext.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public void setConstructorResolvers(List<ConstructorResolver> constructorResolvers) {
	this.constructorResolvers = constructorResolvers;
}
 
Example #17
Source File: StandardEvaluationContext.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public boolean removeConstructorResolver(ConstructorResolver resolver) {
	ensureConstructorResolversInitialized();
	return this.constructorResolvers.remove(resolver);
}
 
Example #18
Source File: StandardEvaluationContext.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public void addConstructorResolver(ConstructorResolver resolver) {
	ensureConstructorResolversInitialized();
	this.constructorResolvers.add(this.constructorResolvers.size() - 1, resolver);
}
 
Example #19
Source File: StandardEvaluationContext.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public List<ConstructorResolver> getConstructorResolvers() {
	return initConstructorResolvers();
}
 
Example #20
Source File: StandardEvaluationContext.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public void addConstructorResolver(ConstructorResolver resolver) {
	addBeforeDefault(initConstructorResolvers(), resolver);
}
 
Example #21
Source File: StandardEvaluationContext.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public boolean removeConstructorResolver(ConstructorResolver resolver) {
	ensureConstructorResolversInitialized();
	return this.constructorResolvers.remove(resolver);
}
 
Example #22
Source File: StandardEvaluationContext.java    From java-technology-stack with MIT License 4 votes vote down vote up
public void setConstructorResolvers(List<ConstructorResolver> constructorResolvers) {
	this.constructorResolvers = constructorResolvers;
}
 
Example #23
Source File: StandardEvaluationContext.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public List<ConstructorResolver> getConstructorResolvers() {
	ensureConstructorResolversInitialized();
	return this.constructorResolvers;
}
 
Example #24
Source File: StandardEvaluationContext.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void setConstructorResolvers(List<ConstructorResolver> constructorResolvers) {
	this.constructorResolvers = constructorResolvers;
}
 
Example #25
Source File: StandardEvaluationContext.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public boolean removeConstructorResolver(ConstructorResolver resolver) {
	return initConstructorResolvers().remove(resolver);
}
 
Example #26
Source File: SimpleEvaluationContext.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return an empty list, always, since this context does not support the
 * use of type references.
 */
@Override
public List<ConstructorResolver> getConstructorResolvers() {
	return Collections.emptyList();
}
 
Example #27
Source File: StandardEvaluationContext.java    From java-technology-stack with MIT License 4 votes vote down vote up
public boolean removeConstructorResolver(ConstructorResolver resolver) {
	return initConstructorResolvers().remove(resolver);
}
 
Example #28
Source File: StandardEvaluationContext.java    From java-technology-stack with MIT License 4 votes vote down vote up
public void addConstructorResolver(ConstructorResolver resolver) {
	addBeforeDefault(initConstructorResolvers(), resolver);
}
 
Example #29
Source File: StandardEvaluationContext.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public List<ConstructorResolver> getConstructorResolvers() {
	return initConstructorResolvers();
}