Package org.springframework.expression.spel

Examples of org.springframework.expression.spel.SpelEvaluationException


  @Override
  public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
    BeanResolver beanResolver = state.getEvaluationContext().getBeanResolver();
    if (beanResolver==null) {
      throw new SpelEvaluationException(getStartPosition(),SpelMessage.NO_BEAN_RESOLVER_REGISTERED, beanname);
    }
    try {
       TypedValue bean = new TypedValue(beanResolver.resolve(state.getEvaluationContext(),beanname));
       return bean;
    } catch (AccessException ae) {
      throw new SpelEvaluationException( getStartPosition(), ae, SpelMessage.EXCEPTION_DURING_BEAN_RESOLUTION,
        beanname, ae.getMessage());
    }
  }
View Full Code Here


    if (currentContext.getValue() == null) {
      if (nullSafe) {
        return ValueRef.NullValueRef.instance;
      }
      else {
        throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_CALL_ON_NULL_OBJECT_NOT_ALLOWED,
            FormatHelper.formatMethodForMessage(name, getTypes(arguments)));
      }
    }

    return new MethodValueRef(state,state.getEvaluationContext(),state.getActiveContextObject().getValue(),arguments);
View Full Code Here

    if (currentContext.getValue() == null) {
      if (this.nullSafe) {
        return TypedValue.NULL;
      }
      else {
        throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_CALL_ON_NULL_OBJECT_NOT_ALLOWED,
            FormatHelper.formatMethodForMessage(name, getTypes(arguments)));
      }
    }

    MethodExecutor executorToUse = this.cachedExecutor;
    if (executorToUse != null) {
      try {
        return executorToUse.execute(
            state.getEvaluationContext(), state.getActiveContextObject().getValue(), arguments);
      }
      catch (AccessException ae) {
        // Two reasons this can occur:
        // 1. the method invoked actually threw a real exception
        // 2. the method invoked was not passed the arguments it expected and has become 'stale'

        // In the first case we should not retry, in the second case we should see if there is a
        // better suited method.

        // To determine which situation it is, the AccessException will contain a cause.
        // If the cause is an InvocationTargetException, a user exception was thrown inside the method.
        // Otherwise the method could not be invoked.
        throwSimpleExceptionIfPossible(state, ae);

        // at this point we know it wasn't a user problem so worth a retry if a better candidate can be found
        this.cachedExecutor = null;
      }
    }

    // either there was no accessor or it no longer existed
    executorToUse = findAccessorForMethod(this.name, getTypes(arguments), state);
    this.cachedExecutor = executorToUse;
    try {
      return executorToUse.execute(
          state.getEvaluationContext(), state.getActiveContextObject().getValue(), arguments);
    } catch (AccessException ae) {
      // Same unwrapping exception handling as above in above catch block
      throwSimpleExceptionIfPossible(state, ae);
      throw new SpelEvaluationException( getStartPosition(), ae, SpelMessage.EXCEPTION_DURING_METHOD_INVOCATION,
          this.name, state.getActiveContextObject().getValue().getClass().getName(), ae.getMessage());
    }
  }
View Full Code Here

          if (cEx != null) {
            return cEx;
          }
        }
        catch (AccessException ex) {
          throw new SpelEvaluationException(getStartPosition(),ex, SpelMessage.PROBLEM_LOCATING_METHOD, name, contextObject.getClass());
        }
      }
    }
    throw new SpelEvaluationException(getStartPosition(),SpelMessage.METHOD_NOT_FOUND, FormatHelper.formatMethodForMessage(name, argumentTypes),
        FormatHelper.formatClassNameForMessage(contextObject instanceof Class ? ((Class<?>) contextObject) : contextObject.getClass()));
  }
View Full Code Here

      try {
        return executorToUse.execute(evaluationContext, target, arguments);
      } catch (AccessException ae) {
        // Same unwrapping exception handling as above in above catch block
        throwSimpleExceptionIfPossible(state, ae);
        throw new SpelEvaluationException( getStartPosition(), ae, SpelMessage.EXCEPTION_DURING_METHOD_INVOCATION,
            name, state.getActiveContextObject().getValue().getClass().getName(), ae.getMessage());
      }
    }
View Full Code Here

          if (cEx != null) {
            return cEx;
          }
        }
        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));
  }
View Full Code Here

   */
  private TypedValue createArray(ExpressionState state) throws EvaluationException {
    // First child gives us the array type which will either be a primitive or reference type
    Object intendedArrayType = getChild(0).getValue(state);
    if (!(intendedArrayType instanceof String)) {
      throw new SpelEvaluationException(getChild(0).getStartPosition(),
          SpelMessage.TYPE_NAME_EXPECTED_FOR_ARRAY_CONSTRUCTION, FormatHelper
              .formatClassNameForMessage(intendedArrayType.getClass()));
    }
    String type = (String) intendedArrayType;
    Class<?> componentType;
    TypeCode arrayTypeCode = TypeCode.forName(type);
    if (arrayTypeCode == TypeCode.OBJECT) {
      componentType = state.findType(type);
    }
    else {
      componentType = arrayTypeCode.getType();
    }
    Object newArray;
    if (!hasInitializer()) {
      // Confirm all dimensions were specified (for example [3][][5] is missing the 2nd dimension)
      for (SpelNodeImpl dimension : this.dimensions) {
        if (dimension == null) {
          throw new SpelEvaluationException(getStartPosition(), SpelMessage.MISSING_ARRAY_DIMENSION);
        }
      }
      TypeConverter typeConverter = state.getEvaluationContext().getTypeConverter();

      // Shortcut for 1 dimensional
      if (this.dimensions.length == 1) {
        TypedValue o = this.dimensions[0].getTypedValue(state);
        int arraySize = ExpressionUtils.toInt(typeConverter, o);
        newArray = Array.newInstance(componentType, arraySize);
      }
      else {
        // Multi-dimensional - hold onto your hat!
        int[] dims = new int[this.dimensions.length];
        for (int d = 0; d < this.dimensions.length; d++) {
          TypedValue o = this.dimensions[d].getTypedValue(state);
          dims[d] = ExpressionUtils.toInt(typeConverter, o);
        }
        newArray = Array.newInstance(componentType, dims);
      }
    }
    else {
      // There is an initializer
      if (this.dimensions.length > 1) {
        // There is an initializer but this is a multi-dimensional array (e.g. new int[][]{{1,2},{3,4}}) - this
        // is not currently supported
        throw new SpelEvaluationException(getStartPosition(),
            SpelMessage.MULTIDIM_ARRAY_INITIALIZER_NOT_SUPPORTED);
      }
      TypeConverter typeConverter = state.getEvaluationContext().getTypeConverter();
      InlineList initializer = (InlineList) getChild(1);
      // If a dimension was specified, check it matches the initializer length
      if (this.dimensions[0] != null) {
        TypedValue dValue = this.dimensions[0].getTypedValue(state);
        int i = ExpressionUtils.toInt(typeConverter, dValue);
        if (i != initializer.getChildCount()) {
          throw new SpelEvaluationException(getStartPosition(), SpelMessage.INITIALIZER_LENGTH_INCORRECT);
        }
      }
      // Build the array and populate it
      int arraySize = initializer.getChildCount();
      newArray = Array.newInstance(componentType, arraySize);
View Full Code Here

      if (operand==null) {
        if (this.nullSafe) {
          return ValueRef.NullValueRef.instance;
        }
        else {
          throw new SpelEvaluationException(getStartPosition(),
              SpelMessage.PROJECTION_NOT_SUPPORTED_ON_TYPE, "null");
        }
      }
      else {
        throw new SpelEvaluationException(getStartPosition(),
            SpelMessage.PROJECTION_NOT_SUPPORTED_ON_TYPE, operand.getClass().getName());
      }
    }
  }
View Full Code Here

    public void setValue(Object newValue) {
      // The exception position '0' isn't right but the overhead of creating
      // instances of this per node (where the node is solely for error reporting)
      // would be unfortunate.
      throw new SpelEvaluationException(0,SpelMessage.NOT_ASSIGNABLE,"null");
    }
View Full Code Here

    public TypedValue getValue() {
      return typedValue;
    }

    public void setValue(Object newValue) {
      throw new SpelEvaluationException(
          node.pos, SpelMessage.NOT_ASSIGNABLE, node.toStringAST());
    }
View Full Code Here

TOP

Related Classes of org.springframework.expression.spel.SpelEvaluationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.