public TypeConverter getTypeConverter() { return this.relatedContext.getTypeConverter(); }
public TypeConverter getTypeConverter() { return this.relatedContext.getTypeConverter(); }
public Object convertValue(Object value, TypeDescriptor targetTypeDescriptor) throws EvaluationException { Object result = this.relatedContext.getTypeConverter().convertValue( value, TypeDescriptor.forObject(value), targetTypeDescriptor); if (result == null) { throw new IllegalStateException("Null conversion result for value [" + value + "]"); } return result; }
@Nullable public Object convertValue(TypedValue value, TypeDescriptor targetTypeDescriptor) throws EvaluationException { Object val = value.getValue(); return this.relatedContext.getTypeConverter().convertValue( val, TypeDescriptor.forObject(val), targetTypeDescriptor); }
@Override public TypedValue execute(EvaluationContext context, Object... arguments) throws AccessException { try { ReflectionHelper.convertArguments( context.getTypeConverter(), arguments, this.ctor, this.varargsPosition); if (this.ctor.isVarArgs()) { arguments = ReflectionHelper.setupArgumentsForVarargsInvocation( this.ctor.getParameterTypes(), arguments); } ReflectionUtils.makeAccessible(this.ctor); return new TypedValue(this.ctor.newInstance(arguments)); } catch (Exception ex) { throw new AccessException("Problem invoking constructor: " + this.ctor, ex); } }
@Override public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List<TypeDescriptor> arguments) throws AccessException { if (name.equals("hasRole")) { return new HasRoleExecutor(context.getTypeConverter()); } return null; } }
public Object convertValue(Object value, TypeDescriptor targetTypeDescriptor) throws EvaluationException { Object result = this.relatedContext.getTypeConverter().convertValue( value, TypeDescriptor.forObject(value), targetTypeDescriptor); if (result == null) { throw new IllegalStateException("Null conversion result for value [" + value + "]"); } return result; }
/** * Determines if there is a type converter available in the specified context and * attempts to use it to convert the supplied value to the specified type. Throws an * exception if conversion is not possible. * @param context the evaluation context that may define a type converter * @param typedValue the value to convert and a type descriptor describing it * @param targetType the type to attempt conversion to * @return the converted value * @throws EvaluationException if there is a problem during conversion or conversion * of the value to the specified type is not supported */ @SuppressWarnings("unchecked") @Nullable public static <T> T convertTypedValue( @Nullable EvaluationContext context, TypedValue typedValue, @Nullable Class<T> targetType) { Object value = typedValue.getValue(); if (targetType == null) { return (T) value; } if (context != null) { return (T) context.getTypeConverter().convertValue( value, typedValue.getTypeDescriptor(), TypeDescriptor.valueOf(targetType)); } if (ClassUtils.isAssignableValue(targetType, value)) { return (T) value; } throw new EvaluationException("Cannot convert value '" + value + "' to type '" + targetType.getName() + "'"); }
@Override public TypedValue execute(EvaluationContext context, Object target, Object... arguments) throws AccessException { try { this.argumentConversionOccurred = ReflectionHelper.convertArguments( context.getTypeConverter(), arguments, this.originalMethod, this.varargsPosition); if (this.originalMethod.isVarArgs()) { arguments = ReflectionHelper.setupArgumentsForVarargsInvocation( this.originalMethod.getParameterTypes(), arguments); } ReflectionUtils.makeAccessible(this.methodToInvoke); Object value = this.methodToInvoke.invoke(target, arguments); return new TypedValue(value, new TypeDescriptor(new MethodParameter(this.originalMethod, -1)).narrow(value)); } catch (Exception ex) { throw new AccessException("Problem invoking method: " + this.methodToInvoke, ex); } }
@Nullable public Object convertValue(TypedValue value, TypeDescriptor targetTypeDescriptor) throws EvaluationException { Object val = value.getValue(); return this.relatedContext.getTypeConverter().convertValue( val, TypeDescriptor.forObject(val), targetTypeDescriptor); }
if (typeDescriptor != null) { try { possiblyConvertedNewValue = context.getTypeConverter().convertValue( newValue, TypeDescriptor.forObject(newValue), typeDescriptor);
/** * Convert operand value to string using registered converter or using * {@code toString} method. * @param value typed value to be converted * @param state expression state * @return {@code TypedValue} instance converted to {@code String} */ private static String convertTypedValueToString(TypedValue value, ExpressionState state) { TypeConverter typeConverter = state.getEvaluationContext().getTypeConverter(); TypeDescriptor typeDescriptor = TypeDescriptor.valueOf(String.class); if (typeConverter.canConvert(value.getTypeDescriptor(), typeDescriptor)) { return String.valueOf(typeConverter.convertValue(value.getValue(), value.getTypeDescriptor(), typeDescriptor)); } return String.valueOf(value.getValue()); }
TypeConverter typeConverter = context.getTypeConverter(); Class<?> type = (targetObject instanceof Class ? (Class<?>) targetObject : targetObject.getClass()); ArrayList<Method> methods = new ArrayList<>(getMethods(type, targetObject));
@Override public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException { if (!name.equals("flibbles")) { throw new RuntimeException("Assertion Failed! name should be flibbles"); } try { flibbles = (Integer) context.getTypeConverter().convertValue(newValue, TypeDescriptor.forObject(newValue), TypeDescriptor.valueOf(Integer.class)); } catch (EvaluationException ex) { throw new AccessException("Cannot set flibbles to an object of type '" + newValue.getClass() + "'"); } } }
@Override public TypedValue execute(EvaluationContext context, Object... arguments) throws AccessException { try { ReflectionHelper.convertArguments( context.getTypeConverter(), arguments, this.ctor, this.varargsPosition); if (this.ctor.isVarArgs()) { arguments = ReflectionHelper.setupArgumentsForVarargsInvocation( this.ctor.getParameterTypes(), arguments); } ReflectionUtils.makeAccessible(this.ctor); return new TypedValue(this.ctor.newInstance(arguments)); } catch (Exception ex) { throw new AccessException("Problem invoking constructor: " + this.ctor, ex); } }
TypeConverter converter = state.getEvaluationContext().getTypeConverter(); boolean argumentConversionOccurred = ReflectionHelper.convertAllArguments(converter, functionArgs, method); if (method.isVarArgs()) {
TypeConverter typeConverter = context.getTypeConverter(); Class<?> type = context.getTypeLocator().findType(typeName); Constructor<?>[] ctors = type.getConstructors();
@Override public TypedValue execute(EvaluationContext context, Object target, Object... arguments) throws AccessException { try { this.argumentConversionOccurred = ReflectionHelper.convertArguments( context.getTypeConverter(), arguments, this.originalMethod, this.varargsPosition); if (this.originalMethod.isVarArgs()) { arguments = ReflectionHelper.setupArgumentsForVarargsInvocation( this.originalMethod.getParameterTypes(), arguments); } ReflectionUtils.makeAccessible(this.methodToInvoke); Object value = this.methodToInvoke.invoke(target, arguments); return new TypedValue(value, new TypeDescriptor(new MethodParameter(this.originalMethod, -1)).narrow(value)); } catch (Exception ex) { throw new AccessException("Problem invoking method: " + this.methodToInvoke, ex); } }
/** * Convert operand value to string using registered converter or using * {@code toString} method. * @param value typed value to be converted * @param state expression state * @return {@code TypedValue} instance converted to {@code String} */ private static String convertTypedValueToString(TypedValue value, ExpressionState state) { TypeConverter typeConverter = state.getEvaluationContext().getTypeConverter(); TypeDescriptor typeDescriptor = TypeDescriptor.valueOf(String.class); if (typeConverter.canConvert(value.getTypeDescriptor(), typeDescriptor)) { return String.valueOf(typeConverter.convertValue(value.getValue(), value.getTypeDescriptor(), typeDescriptor)); } return String.valueOf(value.getValue()); }
TypeConverter typeConverter = state.getEvaluationContext().getTypeConverter(); SpelMessage.MULTIDIM_ARRAY_INITIALIZER_NOT_SUPPORTED); TypeConverter typeConverter = state.getEvaluationContext().getTypeConverter(); InlineList initializer = (InlineList) getChild(1);