Examples of MethodCallback


Examples of org.springframework.util.ReflectionUtils.MethodCallback

                    }
                }
            }
        };

        MethodCallback methodCallback = new ReflectionUtils.MethodCallback() {
            public void doWith(Method method) throws IllegalArgumentException,
                    IllegalAccessException {
                if (method.isSynthetic()) {
                    return;
                }
                if (!Modifier.isPublic(method.getModifiers())) {
                    return;
                }
                if (Modifier.isStatic(method.getModifiers())
                        && method.getReturnType() != Void.class) {
                    if (method.getParameterTypes().length == 0) {
                        String name = method.getName();
                        if (name.indexOf('$') == -1) {
                            if (name.length() > 3 && name.startsWith("get")
                                    && Character.isUpperCase(name.charAt(3))) {
                                name = name.substring(3);
                            } else if (name.length() > 2
                                    && name.startsWith("is")
                                    && Character.isUpperCase(name.charAt(2))
                                    && (method.getReturnType() == Boolean.class ||
                                        method.getReturnType() == boolean.class)) {
                                name = name.substring(2);
                            }
                            PropertyFetcher fetcher = new GetterPropertyFetcher(
                                    method, true);
                            staticFetchers.put(name, fetcher);
                            staticFetchers.put(StringUtils.uncapitalize(name), fetcher);
                        }
                    }
                }
            }
        };

        List<Class<?>> allClasses = resolveAllClasses(clazz);
        for (Class<?> c : allClasses) {
            Field[] fields = c.getDeclaredFields();
            for (Field field : fields) {
                try {
                    fieldCallback.doWith(field);
                } catch (IllegalAccessException ex) {
                    throw new IllegalStateException(
                            "Shouldn't be illegal to access field '"
                                    + field.getName() + "': " + ex);
                }
            }
            Method[] methods = c.getDeclaredMethods();
            for (Method method : methods) {
                try {
                    methodCallback.doWith(method);
                } catch (IllegalAccessException ex) {
                    throw new IllegalStateException(
                            "Shouldn't be illegal to access method '"
                                    + method.getName() + "': " + ex);
                }
View Full Code Here

Examples of org.springframework.util.ReflectionUtils.MethodCallback

    }

    if (clazz.isInterface()) {
      final List<Method> methods = new ArrayList<Method>();

      ReflectionUtils.doWithMethods(clazz, new MethodCallback() {
        @Override
        public void doWith(Method method) throws IllegalArgumentException,
            IllegalAccessException {
          methods.add(method);
        }
View Full Code Here

Examples of org.springframework.util.ReflectionUtils.MethodCallback

  private MethodInvocationRecoverer<?> getRecoverer(Object target, Method method) {
    if (target instanceof MethodInvocationRecoverer) {
      return (MethodInvocationRecoverer<?>) target;
    }
    final AtomicBoolean foundRecoverable = new AtomicBoolean(false);
    ReflectionUtils.doWithMethods(target.getClass(), new MethodCallback() {
      @Override
      public void doWith(Method method) throws IllegalArgumentException,
          IllegalAccessException {
        if (AnnotationUtils.findAnnotation(method, Recover.class) != null) {
          foundRecoverable.set(true);
View Full Code Here

Examples of org.springframework.util.ReflectionUtils.MethodCallback

    }
   
    public boolean hasAnnotatedMethods(Class<?> clazz) {
      final AtomicBoolean found = new AtomicBoolean(false);
      ReflectionUtils.doWithMethods(clazz,
          new MethodCallback() {
            @Override
            public void doWith(Method method) throws IllegalArgumentException,
                IllegalAccessException {
              if (found.get()) {
                return;
View Full Code Here

Examples of org.springframework.util.ReflectionUtils.MethodCallback

  private void init(Object target, Method method) {
    final Map<Class<? extends Throwable>, Method> types = new HashMap<Class<? extends Throwable>, Method>();
    final Method failingMethod = method;
    ReflectionUtils.doWithMethods(failingMethod.getDeclaringClass(),
        new MethodCallback() {
          @Override
          public void doWith(Method method) throws IllegalArgumentException,
              IllegalAccessException {
            Recover recover = AnnotationUtils.findAnnotation(method,
                Recover.class);
View Full Code Here

Examples of org.springframework.util.ReflectionUtils.MethodCallback

    Mockito.when(quoteRepository.findBySymbol("VMW")).thenReturn(quote);
  }

  @Test
  public void test() {
    ReflectionUtils.doWithMethods(TradingServiceImpl.class, new MethodCallback() {
      @Override
      public void doWith(Method method) throws IllegalArgumentException,
          IllegalAccessException {
        if ("updateQuoteMarketData".equals(method.getName())) {
          method.setAccessible(true);
View Full Code Here

Examples of org.springframework.util.ReflectionUtils.MethodCallback

  @Override
  public Object postProcessAfterInitialization(final Object bean, String beanName) {
    if (!this.nonAnnotatedClasses.contains(bean.getClass())) {
      final Set<Method> annotatedMethods = new LinkedHashSet<Method>(1);
      Class<?> targetClass = AopUtils.getTargetClass(bean);
      ReflectionUtils.doWithMethods(targetClass, new MethodCallback() {
        @Override
        public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
          for (Scheduled scheduled :
              AnnotationUtils.getRepeatableAnnotation(method, Schedules.class, Scheduled.class)) {
            processScheduled(scheduled, method, bean);
View Full Code Here

Examples of org.springframework.util.ReflectionUtils.MethodCallback

        }
      }, filter);
    }

    if (members == Members.METHODS || members == Members.ALL) {
      doWithMethods(targetClass, new MethodCallback() {
        @Override
        public void doWith(final Method method) throws IllegalAccessException {
          withMethod(bean, beanName, targetClass, method);
        }
      }, filter);
View Full Code Here

Examples of org.springframework.util.ReflectionUtils.MethodCallback

  public Object postProcessAfterInitialization(final Object bean, String beanName) throws BeansException {
    Class<?> targetClass = AopUtils.getTargetClass(bean);
    if (targetClass == null) {
      return bean;
    }
    ReflectionUtils.doWithMethods(targetClass, new MethodCallback() {
      public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
        Scheduled annotation = AnnotationUtils.getAnnotation(method, Scheduled.class);
        if (annotation != null) {
          Assert.isTrue(void.class.equals(method.getReturnType()),
              "Only void-returning methods may be annotated with @Scheduled.");
View Full Code Here

Examples of org.springframework.util.ReflectionUtils.MethodCallback

    // use an int array just so we can have a final variable
    // contains the beanNames resolved based on the method signature
    final Set<String> noArgMethodsSeen = new HashSet<String>();

    ReflectionUtils.doWithMethods(configurationClass, new MethodCallback() {
      public void doWith(Method m) throws IllegalArgumentException, IllegalAccessException {
        Bean beanAnnotation = AnnotationUtils.findAnnotation(m, Bean.class);
        // Determine bean name
        String beanName = beanNamingStrategy.getBeanName(m);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.