org.springframework.expression.common.ExpressionUtils Java Examples

The following examples show how to use org.springframework.expression.common.ExpressionUtils. 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: ConstructorReference.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void populateByteArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	byte[] newByteArray = (byte[]) newArray;
	for (int i = 0; i < newByteArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newByteArray[i] = ExpressionUtils.toByte(typeConverter, typedValue);
	}
}
 
Example #2
Source File: ConstructorReference.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void populateByteArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	byte[] newByteArray = (byte[]) newArray;
	for (int i = 0; i < newByteArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newByteArray[i] = ExpressionUtils.toByte(typeConverter, typedValue);
	}
}
 
Example #3
Source File: ConstructorReference.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void populateFloatArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	float[] newFloatArray = (float[]) newArray;
	for (int i = 0; i < newFloatArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newFloatArray[i] = ExpressionUtils.toFloat(typeConverter, typedValue);
	}
}
 
Example #4
Source File: ConstructorReference.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void populateDoubleArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	double[] newDoubleArray = (double[]) newArray;
	for (int i = 0; i < newDoubleArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newDoubleArray[i] = ExpressionUtils.toDouble(typeConverter, typedValue);
	}
}
 
Example #5
Source File: ConstructorReference.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void populateShortArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	short[] newShortArray = (short[]) newArray;
	for (int i = 0; i < newShortArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newShortArray[i] = ExpressionUtils.toShort(typeConverter, typedValue);
	}
}
 
Example #6
Source File: ConstructorReference.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void populateLongArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	long[] newLongArray = (long[]) newArray;
	for (int i = 0; i < newLongArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newLongArray[i] = ExpressionUtils.toLong(typeConverter, typedValue);
	}
}
 
Example #7
Source File: ConstructorReference.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void populateCharArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	char[] newCharArray = (char[]) newArray;
	for (int i = 0; i < newCharArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newCharArray[i] = ExpressionUtils.toChar(typeConverter, typedValue);
	}
}
 
Example #8
Source File: ConstructorReference.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void populateBooleanArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	boolean[] newBooleanArray = (boolean[]) newArray;
	for (int i = 0; i < newBooleanArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newBooleanArray[i] = ExpressionUtils.toBoolean(typeConverter, typedValue);
	}
}
 
Example #9
Source File: ConstructorReference.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void populateIntArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	int[] newIntArray = (int[]) newArray;
	for (int i = 0; i < newIntArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newIntArray[i] = ExpressionUtils.toInt(typeConverter, typedValue);
	}
}
 
Example #10
Source File: SpelExpression.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T getValue(Class<T> expectedResultType) throws EvaluationException {
	if (this.compiledAst != null) {
		try {
			TypedValue contextRoot =
					(this.evaluationContext != null ? this.evaluationContext.getRootObject() : null);
			Object result = this.compiledAst.getValue(
					(contextRoot != null ? contextRoot.getValue() : null), this.evaluationContext);
			if (expectedResultType == null) {
				return (T) result;
			}
			else {
				return ExpressionUtils.convertTypedValue(
						getEvaluationContext(), new TypedValue(result), expectedResultType);
			}
		}
		catch (Throwable ex) {
			// If running in mixed mode, revert to interpreted
			if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) {
				this.interpretedCount = 0;
				this.compiledAst = null;
			}
			else {
				// Running in SpelCompilerMode.immediate mode - propagate exception to caller
				throw new SpelEvaluationException(ex, SpelMessage.EXCEPTION_RUNNING_COMPILED_EXPRESSION);
			}
		}
	}

	ExpressionState expressionState = new ExpressionState(getEvaluationContext(), this.configuration);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(
			expressionState.getEvaluationContext(), typedResultValue, expectedResultType);
}
 
Example #11
Source File: SpelExpression.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T getValue(Object rootObject, Class<T> expectedResultType) throws EvaluationException {
	if (this.compiledAst != null) {
		try {
			Object result = this.compiledAst.getValue(rootObject, null);
			if (expectedResultType == null) {
				return (T)result;
			}
			else {
				return ExpressionUtils.convertTypedValue(
						getEvaluationContext(), new TypedValue(result), expectedResultType);
			}
		}
		catch (Throwable ex) {
			// If running in mixed mode, revert to interpreted
			if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) {
				this.interpretedCount = 0;
				this.compiledAst = null;
			}
			else {
				// Running in SpelCompilerMode.immediate mode - propagate exception to caller
				throw new SpelEvaluationException(ex, SpelMessage.EXCEPTION_RUNNING_COMPILED_EXPRESSION);
			}
		}
	}

	ExpressionState expressionState =
			new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(
			expressionState.getEvaluationContext(), typedResultValue, expectedResultType);
}
 
Example #12
Source File: SpelExpression.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T getValue(EvaluationContext context, Class<T> expectedResultType) throws EvaluationException {
	Assert.notNull(context, "EvaluationContext is required");

	if (this.compiledAst != null) {
		try {
			TypedValue contextRoot = context.getRootObject();
			Object result = this.compiledAst.getValue(contextRoot.getValue(), context);
			if (expectedResultType != null) {
				return ExpressionUtils.convertTypedValue(context, new TypedValue(result), expectedResultType);
			}
			else {
				return (T) result;
			}
		}
		catch (Throwable ex) {
			// If running in mixed mode, revert to interpreted
			if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) {
				this.interpretedCount = 0;
				this.compiledAst = null;
			}
			else {
				// Running in SpelCompilerMode.immediate mode - propagate exception to caller
				throw new SpelEvaluationException(ex, SpelMessage.EXCEPTION_RUNNING_COMPILED_EXPRESSION);
			}
		}
	}

	ExpressionState expressionState = new ExpressionState(context, this.configuration);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(context, typedResultValue, expectedResultType);
}
 
Example #13
Source File: SpelExpression.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T getValue(EvaluationContext context, Object rootObject, Class<T> expectedResultType)
		throws EvaluationException {

	Assert.notNull(context, "EvaluationContext is required");

	if (this.compiledAst != null) {
		try {
			Object result = this.compiledAst.getValue(rootObject, context);
			if (expectedResultType != null) {
				return ExpressionUtils.convertTypedValue(context, new TypedValue(result), expectedResultType);
			}
			else {
				return (T) result;
			}
		}
		catch (Throwable ex) {
			// If running in mixed mode, revert to interpreted
			if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) {
				this.interpretedCount = 0;
				this.compiledAst = null;
			}
			else {
				// Running in SpelCompilerMode.immediate mode - propagate exception to caller
				throw new SpelEvaluationException(ex, SpelMessage.EXCEPTION_RUNNING_COMPILED_EXPRESSION);
			}
		}
	}

	ExpressionState expressionState = new ExpressionState(context, toTypedValue(rootObject), this.configuration);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(context, typedResultValue, expectedResultType);
}
 
Example #14
Source File: ConstructorReference.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void populateByteArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	byte[] newByteArray = (byte[]) newArray;
	for (int i = 0; i < newByteArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newByteArray[i] = ExpressionUtils.toByte(typeConverter, typedValue);
	}
}
 
Example #15
Source File: ConstructorReference.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void populateFloatArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	float[] newFloatArray = (float[]) newArray;
	for (int i = 0; i < newFloatArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newFloatArray[i] = ExpressionUtils.toFloat(typeConverter, typedValue);
	}
}
 
Example #16
Source File: ConstructorReference.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void populateDoubleArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	double[] newDoubleArray = (double[]) newArray;
	for (int i = 0; i < newDoubleArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newDoubleArray[i] = ExpressionUtils.toDouble(typeConverter, typedValue);
	}
}
 
Example #17
Source File: ConstructorReference.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void populateShortArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	short[] newShortArray = (short[]) newArray;
	for (int i = 0; i < newShortArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newShortArray[i] = ExpressionUtils.toShort(typeConverter, typedValue);
	}
}
 
Example #18
Source File: ConstructorReference.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void populateLongArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	long[] newLongArray = (long[]) newArray;
	for (int i = 0; i < newLongArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newLongArray[i] = ExpressionUtils.toLong(typeConverter, typedValue);
	}
}
 
Example #19
Source File: ConstructorReference.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void populateCharArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	char[] newCharArray = (char[]) newArray;
	for (int i = 0; i < newCharArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newCharArray[i] = ExpressionUtils.toChar(typeConverter, typedValue);
	}
}
 
Example #20
Source File: ConstructorReference.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void populateBooleanArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	boolean[] newBooleanArray = (boolean[]) newArray;
	for (int i = 0; i < newBooleanArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newBooleanArray[i] = ExpressionUtils.toBoolean(typeConverter, typedValue);
	}
}
 
Example #21
Source File: ConstructorReference.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void populateIntArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	int[] newIntArray = (int[]) newArray;
	for (int i = 0; i < newIntArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newIntArray[i] = ExpressionUtils.toInt(typeConverter, typedValue);
	}
}
 
Example #22
Source File: SpelExpression.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T getValue(Class<T> expectedResultType) throws EvaluationException {
	if (this.compiledAst != null) {
		try {
			TypedValue contextRoot = evaluationContext == null ? null : evaluationContext.getRootObject();
			Object result = this.compiledAst.getValue(contextRoot == null ? null : contextRoot.getValue(), evaluationContext);
			if (expectedResultType == null) {
				return (T)result;
			}
			else {
				return ExpressionUtils.convertTypedValue(getEvaluationContext(), new TypedValue(result), expectedResultType);
			}
		}
		catch (Throwable ex) {
			// If running in mixed mode, revert to interpreted
			if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) {
				this.interpretedCount = 0;
				this.compiledAst = null;
			}
			else {
				// Running in SpelCompilerMode.immediate mode - propagate exception to caller
				throw new SpelEvaluationException(ex, SpelMessage.EXCEPTION_RUNNING_COMPILED_EXPRESSION);
			}
		}
	}
	ExpressionState expressionState = new ExpressionState(getEvaluationContext(), this.configuration);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(expressionState.getEvaluationContext(), typedResultValue, expectedResultType);
}
 
Example #23
Source File: SpelExpression.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T getValue(Object rootObject, Class<T> expectedResultType) throws EvaluationException {
	if (this.compiledAst != null) {
		try {
			Object result = this.compiledAst.getValue(rootObject, null);
			if (expectedResultType == null) {
				return (T)result;
			}
			else {
				return ExpressionUtils.convertTypedValue(getEvaluationContext(), new TypedValue(result), expectedResultType);
			}
		}
		catch (Throwable ex) {
			// If running in mixed mode, revert to interpreted
			if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) {
				this.interpretedCount = 0;
				this.compiledAst = null;
			}
			else {
				// Running in SpelCompilerMode.immediate mode - propagate exception to caller
				throw new SpelEvaluationException(ex, SpelMessage.EXCEPTION_RUNNING_COMPILED_EXPRESSION);
			}
		}
	}
	ExpressionState expressionState = new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(expressionState.getEvaluationContext(), typedResultValue, expectedResultType);
}
 
Example #24
Source File: SpelExpression.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T getValue(EvaluationContext context, Class<T> expectedResultType) throws EvaluationException {
	if (this.compiledAst != null) {
		try {
			TypedValue contextRoot = context == null ? null : context.getRootObject();
			Object result = this.compiledAst.getValue(contextRoot==null?null:contextRoot.getValue(),context);
			if (expectedResultType != null) {
				return ExpressionUtils.convertTypedValue(context, new TypedValue(result), expectedResultType);
			}
			else {
				return (T) result;
			}
		}
		catch (Throwable ex) {
			// If running in mixed mode, revert to interpreted
			if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) {
				this.interpretedCount = 0;
				this.compiledAst = null;
			}
			else {
				// Running in SpelCompilerMode.immediate mode - propagate exception to caller
				throw new SpelEvaluationException(ex, SpelMessage.EXCEPTION_RUNNING_COMPILED_EXPRESSION);
			}
		}
	}
	ExpressionState expressionState = new ExpressionState(context, this.configuration);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(context, typedResultValue, expectedResultType);
}
 
Example #25
Source File: SpelExpression.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T getValue(EvaluationContext context, Object rootObject, Class<T> expectedResultType) throws EvaluationException {
	if (this.compiledAst != null) {
		try {
			Object result = this.compiledAst.getValue(rootObject,context);
			if (expectedResultType != null) {
				return ExpressionUtils.convertTypedValue(context, new TypedValue(result), expectedResultType);
			}
			else {
				return (T) result;
			}
		}
		catch (Throwable ex) {
			// If running in mixed mode, revert to interpreted
			if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) {
				this.interpretedCount = 0;
				this.compiledAst = null;
			}
			else {
				// Running in SpelCompilerMode.immediate mode - propagate exception to caller
				throw new SpelEvaluationException(ex, SpelMessage.EXCEPTION_RUNNING_COMPILED_EXPRESSION);
			}
		}
	}
	ExpressionState expressionState = new ExpressionState(context, toTypedValue(rootObject), this.configuration);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(context, typedResultValue, expectedResultType);
}
 
Example #26
Source File: ConstructorReference.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void populateByteArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	byte[] newByteArray = (byte[]) newArray;
	for (int i = 0; i < newByteArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newByteArray[i] = ExpressionUtils.toByte(typeConverter, typedValue);
	}
}
 
Example #27
Source File: ConstructorReference.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void populateFloatArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	float[] newFloatArray = (float[]) newArray;
	for (int i = 0; i < newFloatArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newFloatArray[i] = ExpressionUtils.toFloat(typeConverter, typedValue);
	}
}
 
Example #28
Source File: ConstructorReference.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void populateDoubleArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	double[] newDoubleArray = (double[]) newArray;
	for (int i = 0; i < newDoubleArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newDoubleArray[i] = ExpressionUtils.toDouble(typeConverter, typedValue);
	}
}
 
Example #29
Source File: ConstructorReference.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void populateShortArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	short[] newShortArray = (short[]) newArray;
	for (int i = 0; i < newShortArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newShortArray[i] = ExpressionUtils.toShort(typeConverter, typedValue);
	}
}
 
Example #30
Source File: ConstructorReference.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void populateLongArray(ExpressionState state, Object newArray, TypeConverter typeConverter,
		InlineList initializer) {

	long[] newLongArray = (long[]) newArray;
	for (int i = 0; i < newLongArray.length; i++) {
		TypedValue typedValue = initializer.getChild(i).getTypedValue(state);
		newLongArray[i] = ExpressionUtils.toLong(typeConverter, typedValue);
	}
}