Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.github.edgarespina.mwa;
  
  import java.util.EnumSet;
  import java.util.List;
  import java.util.Set;
  
 
All the changes made by MWA are here.

Author(s):
edgar.espina
Since:
0.1.3
 
 enum BeanPostProcessors {

  
Do nothing.
 
   DEFAULT {
     @Override
     public boolean matches(final Object bean) {
       return true;
     }
   },

  
 
   MESSAGE_CONVERTER_EXCEPTION_RESOLVER {
     @Override
     public boolean matches(final Object bean) {
       return bean instanceof MessageConverterHandlerExceptionResolver;
     }
 
     @Override
         final ApplicationContext contextfinal Object bean) {
       MessageConverterHandlerExceptionResolver exceptionResolver =
           (MessageConverterHandlerExceptionResolverbean;
       RequestMappingHandlerAdapter mapping =
           context.getBean(RequestMappingHandlerAdapter.class);
       exceptionResolver.setMessageConverters(mapping.getMessageConverters());
       return bean;
     }
   },

  
Add handler interceptors.
 
   ADD_HANDLER_INTERCEPTORS {
     @Override
     public boolean matches(final Object bean) {
       return bean instanceof AbstractHandlerMapping;
     }
 
     @Override
         final ApplicationContext contextfinal Object bean) {
       AbstractHandlerMapping handlerMapping = (AbstractHandlerMappingbean;
       List<HandlerInterceptorcandidates =
           Beans.lookFor(contextHandlerInterceptor.class);
       // Add model contributions.
       candidates.add(new ModelContributionInterceptor(Beans.lookFor(context,
           ModelContribution.class)));
       Object[] interceptors = new Object[candidates.size()];
       for (int i = 0; i < interceptors.lengthi++) {
         HandlerInterceptor interceptor = candidates.get(i);
         RequestMapping mapping =
             AnnotationUtils.findAnnotation(interceptor.getClass(),
                 RequestMapping.class);
         if (mapping != null && mapping.value().length > 0) {
           interceptors[i] =
               new MappedInterceptor(mapping.value(), interceptor);
         } else {
           interceptors[i] = interceptor;
         }
       }
       handlerMapping.setInterceptors(interceptors);
       return bean;
    }
  },

  
Add custom argument resolvers.
  ADD_ARGUMENT_RESOLVERS_RETURN_VALUE_HANDLERS {
    @Override
    public boolean matches(final Object bean) {
      return bean instanceof RequestMappingHandlerAdapter;
    }
    @Override
        final ApplicationContext contextfinal Object bean) {
      RequestMappingHandlerAdapter handlerMapping =
          (RequestMappingHandlerAdapterbean;
      // New applications should consider setting it to true.
      handlerMapping.setIgnoreDefaultModelOnRedirect(true);
      // Add custom argument resolvers
      Set<HandlerMethodArgumentResolverargumentResolvers =
              handlerMapping.getCustomArgumentResolvers());
      argumentResolvers.addAll(Beans.lookFor(context,
          HandlerMethodArgumentResolver.class));
      handlerMapping.setCustomArgumentResolvers(
          new ArrayList<HandlerMethodArgumentResolver>(argumentResolvers));
      // Add custom return value handlers
      Set<HandlerMethodReturnValueHandlerreturnValueHandlers =
              handlerMapping.getCustomReturnValueHandlers());
      returnValueHandlers.addAll(Beans.lookFor(context,
          HandlerMethodReturnValueHandler.class));
      handlerMapping.setCustomReturnValueHandlers(
          new ArrayList<HandlerMethodReturnValueHandler>(returnValueHandlers));
      // Find Jackson Converter
      List<HttpMessageConverter<?>> messageConverters =
          handlerMapping.getMessageConverters();
      MappingJacksonHttpMessageConverter jacksonMessageConverter =
          find(messageConvertersMappingJacksonHttpMessageConverter.class);
      ObjectMapper defaultObjectMapper =
          context.getBean(.ObjectMapper.class);
      jacksonMessageConverter.setObjectMapper(defaultObjectMapper);
      return bean;
    }
  };

  
Find the given bean type on the collection.

Parameters:
iterable The candidate collection.
beanType The bean type.
<T> The bean type.
Returns:
The bean or null if not found.
  @SuppressWarnings({"rawtypes""unchecked" })
  protected <T> T find(final Iterable iterablefinal Class<T> beanType) {
    for (Object bean : iterable) {
      if (beanType.isInstance(bean)) {
        return (T) bean;
      }
    }
    return null;
  }

  
True if the given post processor should be executed over the bean.

Parameters:
bean The candidate bean.
Returns:
True if the given post processor should be executed over the bean.
  public abstract boolean matches(Object bean);

  
Apply this BeanPostProcessor to the given new bean instance before any bean initialization callbacks (like InitializingBean's afterPropertiesSet or a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.

Parameters:
context The application context.
bean the new bean instance
Returns:
the bean instance to use, either the original or a wrapped one; if null, no subsequent BeanPostProcessors will be invoked
See also:
org.springframework.beans.factory.InitializingBean.afterPropertiesSet()
      final ApplicationContext contextfinal Object bean) {
    return bean;
  }

  
Apply this BeanPostProcessor to the given new bean instance before any bean initialization callbacks (like InitializingBean's afterPropertiesSet or a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.

Parameters:
context The application context.
bean the new bean instance
Returns:
the bean instance to use, either the original or a wrapped one; if null, no subsequent BeanPostProcessors will be invoked
See also:
org.springframework.beans.factory.InitializingBean.afterPropertiesSet()
      final Object bean) {
    return bean;
  }

  
Apply this BeanPostProcessor to the given new bean instance after any bean initialization callbacks (like InitializingBean's afterPropertiesSet or a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.

In case of a FactoryBean, this callback will be invoked for both the FactoryBean instance and the objects created by the FactoryBean (as of Spring 2.0). The post-processor can decide whether to apply to either the FactoryBean or created objects or both through corresponding bean instanceof FactoryBean checks.

This callback will also be invoked after a short-circuiting triggered by a org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation(java.lang.Class,java.lang.String) method, in contrast to all other BeanPostProcessor callbacks.

Parameters:
context The application context.
bean the new bean instance
Returns:
the bean instance to use, either the original or a wrapped one; if null, no subsequent BeanPostProcessors will be invoked
See also:
org.springframework.beans.factory.InitializingBean.afterPropertiesSet()
org.springframework.beans.factory.FactoryBean
      final Object bean) {
    return bean;
  }

  
Get a org.springframework.beans.factory.config.BeanPostProcessor for the given bean.

Parameters:
bean The candidate bean.
Returns:
A org.springframework.beans.factory.config.BeanPostProcessor for the given bean.
  public static BeanPostProcessors get(final Object bean) {
    Set<BeanPostProcessorsbeanPostProcessors =
        EnumSet.allOf(BeanPostProcessors.class);
    beanPostProcessors.remove();
    for (BeanPostProcessors beanPostProcessor : beanPostProcessors) {
      if (beanPostProcessor.matches(bean)) {
        return beanPostProcessor;
      }
    }
    return ;
  }
New to GrepCode? Check out our FAQ X