Package org.springframework.expression.spel

Examples of org.springframework.expression.spel.SpelEvaluationException


      if (closeMatch != null) {
        return new ReflectiveMethodExecutor(closeMatch, null);
      }
      else if (matchRequiringConversion != null) {
        if (multipleOptions) {
          throw new SpelEvaluationException(SpelMessage.MULTIPLE_POSSIBLE_METHODS, name);
        }
        return new ReflectiveMethodExecutor(matchRequiringConversion, argsToConvert);
      }
      else {
        return null;
View Full Code Here


              }
              result.put(entry.getKey(),entry.getValue());
              lastKey = entry.getKey();
            }
          } else {
            throw new SpelEvaluationException(selectionCriteria.getStartPosition(),
                SpelMessage.RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN);// ,selectionCriteria.stringifyAST());
          }
        } finally {
          state.popActiveContextObject();
        }
      }
      if ((variant == FIRST || variant == LAST) && result.size() == 0) {
        return new TypedValue(null);
      }
      if (variant == LAST) {
        Map resultMap = new HashMap();
        Object lastValue = result.get(lastKey);
        resultMap.put(lastKey,lastValue);
        return new TypedValue(resultMap);
      }
      return new TypedValue(result);
    } else if ((operand instanceof Collection) || ObjectUtils.isArray(operand)) {
      List<Object> data = new ArrayList<Object>();
      Collection<?> c = (operand instanceof Collection) ?
          (Collection<?>) operand : Arrays.asList(ObjectUtils.toObjectArray(operand));
      data.addAll(c);
      List<Object> result = new ArrayList<Object>();
      int idx = 0;
      for (Object element : data) {
        try {
          state.pushActiveContextObject(new TypedValue(element));
          state.enterScope("index", idx);
          Object o = selectionCriteria.getValueInternal(state).getValue();
          if (o instanceof Boolean) {
            if (((Boolean) o).booleanValue() == true) {
              if (variant == FIRST) {
                return new TypedValue(element);
              }
              result.add(element);
            }
          } else {
            throw new SpelEvaluationException(selectionCriteria.getStartPosition(),
                SpelMessage.RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN);// ,selectionCriteria.stringifyAST());
          }
          idx++;
        } finally {
          state.exitScope();
          state.popActiveContextObject();
        }
      }
      if ((variant == FIRST || variant == LAST) && result.size() == 0) {
        return TypedValue.NULL;
      }
      if (variant == LAST) {
        return new TypedValue(result.get(result.size() - 1));
      }
      if (operand instanceof Collection) {
        return new TypedValue(result);
      }
      else {
        Class<?> elementType = ClassUtils.resolvePrimitiveIfNecessary(op.getTypeDescriptor().getElementTypeDescriptor().getType());
        Object resultArray = Array.newInstance(elementType, result.size());
        System.arraycopy(result.toArray(), 0, resultArray, 0, result.size());
        return new TypedValue(resultArray);
      }
    } else {
      if (operand==null) {
        if (nullSafe) {
          return TypedValue.NULL;
        } else {
          throw new SpelEvaluationException(getStartPosition(), SpelMessage.INVALID_TYPE_FOR_SELECTION,
              "null");
        }
      } else {
        throw new SpelEvaluationException(getStartPosition(), SpelMessage.INVALID_TYPE_FOR_SELECTION,
            operand.getClass().getName());
      }       
    }
  }
View Full Code Here

              writeProperty(state, this.name, newList);
              result = readProperty(state, this.name);
            }
          }
          catch (InstantiationException ex) {
            throw new SpelEvaluationException(getStartPosition(), ex,
                SpelMessage.UNABLE_TO_CREATE_LIST_FOR_INDEXING);
          }
          catch (IllegalAccessException ex) {
            throw new SpelEvaluationException(getStartPosition(), ex,
                SpelMessage.UNABLE_TO_CREATE_LIST_FOR_INDEXING);
          }
        }
        else {
          try {
            if (isWritable(state)) {
              Map newMap = HashMap.class.newInstance();
              writeProperty(state, name, newMap);
              result = readProperty(state, this.name);
            }
          }
          catch (InstantiationException ex) {
            throw new SpelEvaluationException(getStartPosition(), ex,
                SpelMessage.UNABLE_TO_CREATE_MAP_FOR_INDEXING);
          }
          catch (IllegalAccessException ex) {
            throw new SpelEvaluationException(getStartPosition(), ex,
                SpelMessage.UNABLE_TO_CREATE_MAP_FOR_INDEXING);
          }
        }
      }
      else {
        // 'simple' object
        try {
          if (isWritable(state)) {
            Object newObject  = result.getTypeDescriptor().getType().newInstance();
            writeProperty(state, name, newObject);
            result = readProperty(state, this.name);
          }
        }
        catch (InstantiationException ex) {
          throw new SpelEvaluationException(getStartPosition(), ex,
              SpelMessage.UNABLE_TO_DYNAMICALLY_CREATE_OBJECT, result.getTypeDescriptor().getType());
        }
        catch (IllegalAccessException ex) {
          throw new SpelEvaluationException(getStartPosition(), ex,
              SpelMessage.UNABLE_TO_DYNAMICALLY_CREATE_OBJECT, result.getTypeDescriptor().getType());
        }       
      }
    }
    return result;
View Full Code Here

            return accessor.read(eContext, contextObject.getValue(), name);
          }
        }
      }
      catch (AccessException ae) {
        throw new SpelEvaluationException(ae, SpelMessage.EXCEPTION_DURING_PROPERTY_READ, name, ae.getMessage());
      }
    }
    if (contextObject.getValue() == null) {
      throw new SpelEvaluationException(SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE_ON_NULL, name);
    }
    else {
      throw new SpelEvaluationException(getStartPosition(), SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE, name,
          FormatHelper.formatClassNameForMessage(contextObjectClass));
    }
  }
View Full Code Here

            return;
          }
        }
      }
      catch (AccessException ae) {
        throw new SpelEvaluationException(getStartPosition(), ae, SpelMessage.EXCEPTION_DURING_PROPERTY_WRITE,
            name, ae.getMessage());
      }
    }
    if (contextObject.getValue()==null) {
      throw new SpelEvaluationException(getStartPosition(), SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL, name);
    }
    else {
      throw new SpelEvaluationException(getStartPosition(), SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE, name,
          FormatHelper.formatClassNameForMessage(contextObjectClass));
    }
  }
View Full Code Here

      if (operand==null) {
        if (this.nullSafe) {
          return TypedValue.NULL;
        }
        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

    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 {
      if (left instanceof Comparable) {
        return ((Comparable) left).compareTo(right);
      }
    } catch (ClassCastException cce) {
      throw new SpelEvaluationException(cce, SpelMessage.NOT_COMPARABLE, left.getClass(), right.getClass());
    }
   
    throw new SpelEvaluationException(SpelMessage.NOT_COMPARABLE, left.getClass(), right.getClass());
  }
View Full Code Here

    SpelNodeImpl rightOp = getRightOperand();
    Object left = leftOp.getValue(state, String.class);
    Object right = getRightOperand().getValueInternal(state).getValue();
    try {
      if (!(left instanceof String)) {
        throw new SpelEvaluationException(leftOp.getStartPosition(),
            SpelMessage.INVALID_FIRST_OPERAND_FOR_MATCHES_OPERATOR, left);
      }
      if (!(right instanceof String)) {
        throw new SpelEvaluationException(rightOp.getStartPosition(),
            SpelMessage.INVALID_SECOND_OPERAND_FOR_MATCHES_OPERATOR, right);
      }
      Pattern pattern = Pattern.compile((String) right);
      Matcher matcher = pattern.matcher((String) left);
      return BooleanTypedValue.forValue(matcher.matches());
    }
    catch (PatternSyntaxException pse) {
      throw new SpelEvaluationException(rightOp.getStartPosition(), pse, SpelMessage.INVALID_PATTERN, right);
    }
  }
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.