All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.bitsensor.plugins.shaded.org.springframework.amqp.rabbit.support.ValueExpression Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2014-2017 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.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.bitsensor.plugins.shaded.io.bitsensor.plugins.shaded.org.springframework.amqp.rabbit.support;

import io.bitsensor.plugins.shaded.org.springframework.core.convert.TypeDescriptor;
import io.bitsensor.plugins.shaded.org.springframework.expression.EvaluationContext;
import io.bitsensor.plugins.shaded.org.springframework.expression.EvaluationException;
import io.bitsensor.plugins.shaded.org.springframework.expression.Expression;
import io.bitsensor.plugins.shaded.org.springframework.expression.TypedValue;
import io.bitsensor.plugins.shaded.org.springframework.util.Assert;

/**
 * A very simple hardcoded implementation of the {@link io.bitsensor.plugins.shaded.org.springframework.expression.Expression}
 * interface that represents an immutable value.
 * It is used as value holder in the context of expression evaluation.
 *
 * @param  - The expected value type.
 *
 * @author Artem Bilan
 * @since 1.4
 */
public class ValueExpression implements Expression {

	/** Fixed value of this expression */
	private final V value;

	private final Class aClass;

	private final TypedValue typedResultValue;

	private final TypeDescriptor typeDescriptor;

	@SuppressWarnings("unchecked")
	public ValueExpression(V value) {
		Assert.notNull(value, "'value' must not be null");
		this.value = value;
		this.aClass = (Class) this.value.getClass();
		this.typedResultValue = new TypedValue(this.value);
		this.typeDescriptor = this.typedResultValue.getTypeDescriptor();
	}

	@Override
	public V getValue() throws EvaluationException {
		return this.value;
	}

	@Override
	public V getValue(Object rootObject) throws EvaluationException {
		return this.value;
	}

	@Override
	public V getValue(EvaluationContext context) throws EvaluationException {
		return this.value;
	}

	@Override
	public V getValue(EvaluationContext context, Object rootObject) throws EvaluationException {
		return this.value;
	}

	@Override
	public  T getValue(Object rootObject, Class desiredResultType) throws EvaluationException {
		return getValue(desiredResultType);
	}

	@Override
	public  T getValue(Class desiredResultType) throws EvaluationException {
		return io.bitsensor.plugins.shaded.org.springframework.expression.common.ExpressionUtils
				.convertTypedValue(null, this.typedResultValue, desiredResultType);
	}

	@Override
	public  T getValue(EvaluationContext context, Object rootObject, Class desiredResultType)
			throws EvaluationException {
		return getValue(context, desiredResultType);
	}

	@Override
	public  T getValue(EvaluationContext context, Class desiredResultType) throws EvaluationException {
		return io.bitsensor.plugins.shaded.org.springframework.expression.common.ExpressionUtils
				.convertTypedValue(context, this.typedResultValue, desiredResultType);
	}

	@Override
	public Class getValueType() throws EvaluationException {
		return this.aClass;
	}

	@Override
	public Class getValueType(Object rootObject) throws EvaluationException {
		return this.aClass;
	}

	@Override
	public Class getValueType(EvaluationContext context) throws EvaluationException {
		return this.aClass;
	}

	@Override
	public Class getValueType(EvaluationContext context, Object rootObject) throws EvaluationException {
		return this.aClass;
	}

	@Override
	public TypeDescriptor getValueTypeDescriptor() throws EvaluationException {
		return this.typeDescriptor;
	}

	@Override
	public TypeDescriptor getValueTypeDescriptor(Object rootObject) throws EvaluationException {
		return this.typeDescriptor;
	}

	@Override
	public TypeDescriptor getValueTypeDescriptor(EvaluationContext context) throws EvaluationException {
		return this.typeDescriptor;
	}

	@Override
	public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject)
			throws EvaluationException {
		return this.typeDescriptor;
	}

	@Override
	public boolean isWritable(EvaluationContext context) throws EvaluationException {
		return false;
	}

	@Override
	public boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException {
		return false;
	}

	@Override
	public boolean isWritable(Object rootObject) throws EvaluationException {
		return false;
	}

	@Override
	public void setValue(EvaluationContext context, Object value) throws EvaluationException {
		setValue(context, null, value);
	}

	@Override
	public void setValue(Object rootObject, Object value) throws EvaluationException {
		setValue(null, rootObject, value);
	}

	@Override
	public void setValue(EvaluationContext context, Object rootObject, Object value) throws EvaluationException {
		throw new EvaluationException(this.value.toString(), "Cannot call setValue() on a ValueExpression");
	}

	@Override
	public String getExpressionString() {
		return this.value.toString();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy