Package org.springframework.expression

Examples of org.springframework.expression.MethodExecutor


        return getMethodExecutor((EvaluationContextExtensionAdapter) target, name, argumentTypes);
      }

      for (EvaluationContextExtensionAdapter adapter : adapters) {

        MethodExecutor executor = getMethodExecutor(adapter, name, argumentTypes);

        if (executor != null) {
          return executor;
        }
      }
View Full Code Here


        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,
View Full Code Here

    List<MethodResolver> mResolvers = eContext.getMethodResolvers();
    if (mResolvers != null) {
      for (MethodResolver methodResolver : mResolvers) {
        try {
          MethodExecutor cEx = methodResolver.resolve(
              eContext, contextObject, name, argumentTypes);
          if (cEx != null) {
            return cEx;
          }
        }
View Full Code Here

      this.target = object;
      this.arguments = arguments;
    }

    public TypedValue getValue() {
      MethodExecutor executorToUse = cachedExecutor;
      if (executorToUse != null) {
        try {
          return executorToUse.execute(evaluationContext, target, 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
          cachedExecutor = null;
        }
      }

      // either there was no accessor or it no longer existed
      executorToUse = findAccessorForMethod(name, getTypes(arguments), target, evaluationContext);
      cachedExecutor = executorToUse;
      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

        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,
View Full Code Here

    List<MethodResolver> mResolvers = eContext.getMethodResolvers();
    if (mResolvers != null) {
      for (MethodResolver methodResolver : mResolvers) {
        try {
          MethodExecutor cEx = methodResolver.resolve(
              state.getEvaluationContext(), contextObject, name, argumentTypes);
          if (cEx != null) {
            return cEx;
          }
        }
View Full Code Here

        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) {
        // this is OK - it may have gone stale due to a class change,
        // let's try to get a new one and call it before giving up
        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) {
      throw new SpelEvaluationException( getStartPosition(), ae, SpelMessage.EXCEPTION_DURING_METHOD_INVOCATION,
          this.name, state.getActiveContextObject().getValue().getClass().getName(), ae.getMessage());
    }
View Full Code Here

    List<MethodResolver> mResolvers = eContext.getMethodResolvers();
    if (mResolvers != null) {
      for (MethodResolver methodResolver : mResolvers) {
        try {
          MethodExecutor cEx = methodResolver.resolve(
              state.getEvaluationContext(), contextObject, name, argumentTypes);
          if (cEx != null) {
            return cEx;
          }
        }
View Full Code Here


    List<TypeDescriptor> argumentTypes = new ArrayList<TypeDescriptor>();
    argumentTypes.add(TypeDescriptor.forObject(arguments));
    ReflectiveMethodResolver resolver = new ReflectiveMethodResolver();
    MethodExecutor executor = resolver.resolve(context, target, "checkCompleteness", argumentTypes);

    Object result = executor.execute(context, target, arguments);
    System.out.println("Result: " + result);
  }
View Full Code Here

    List<TypeDescriptor> args = new ArrayList<TypeDescriptor>();
    args.add(TypeDescriptor.forObject(new Integer(42)));

    ConversionPriority1 target = new ConversionPriority1();
    MethodExecutor me = new ReflectiveMethodResolver(true).resolve(emptyEvalContext, target, "getX", args);
    // MethodInvoker chooses getX(int i) when passing Integer
    final int actual = (Integer) me.execute(emptyEvalContext, target, new Integer(42)).getValue();
    // Compiler chooses getX(Number i) when passing Integer
    final int compiler = target.getX(INTEGER);
    // Fails!
    assertEquals(compiler, actual);

    ConversionPriority2 target2 = new ConversionPriority2();
    MethodExecutor me2 = new ReflectiveMethodResolver(true).resolve(emptyEvalContext, target2, "getX", args);
    // MethodInvoker chooses getX(int i) when passing Integer
    int actual2 = (Integer) me2.execute(emptyEvalContext, target2, new Integer(42)).getValue();
    // Compiler chooses getX(Number i) when passing Integer
    int compiler2 = target2.getX(INTEGER);
    // Fails!
    assertEquals(compiler2, actual2);
View Full Code Here

TOP

Related Classes of org.springframework.expression.MethodExecutor

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.