/** * Determine if a given {@link FacesWrapperFactory} is suitable by resolving generic arguments. * * @param factory the factory to test * @return <tt>true</tt> if the <tt>factory</tt> is supported, otherwise <tt>false</tt> */ @SuppressWarnings({"rawtypes", "unchecked"}) private boolean isFactorySupported(FacesWrapperFactory factory) { Class typeArg = GenericTypeResolver.resolveTypeArgument(factory.getClass(), FacesWrapperFactory.class); if (typeArg == null) { Class targetClass = AopUtils.getTargetClass(factory); if (targetClass != factory.getClass()) { typeArg = GenericTypeResolver.resolveTypeArgument(targetClass, FacesWrapperFactory.class); } } return (typeArg == null || typeArg.isAssignableFrom(this.typeClass)); }
@SuppressWarnings("unchecked") private ApplicationContextInitializer<ConfigurableApplicationContext> loadInitializer( String className, ConfigurableApplicationContext wac) { try { Class<?> initializerClass = ClassUtils.forName(className, wac.getClassLoader()); Class<?> initializerContextClass = GenericTypeResolver.resolveTypeArgument( initializerClass, ApplicationContextInitializer.class); if (initializerContextClass != null) { Assert.isAssignable( initializerContextClass, wac.getClass(), String.format( "Could not add context initializer [%s] since its generic parameter [%s] " + "is not assignable from the type of application context used by this " + "framework servlet [%s]: ", initializerClass.getName(), initializerContextClass.getName(), wac.getClass().getName())); } return BeanUtils.instantiateClass(initializerClass, ApplicationContextInitializer.class); } catch (Exception ex) { throw new IllegalArgumentException( String.format( "Could not instantiate class [%s] specified " + "via 'contextInitializerClasses' init-param", className), ex); } }
private List<ConnectInterceptor<?>> interceptingConnectionsTo( ConnectionFactory<?> connectionFactory) { Class<?> serviceType = GenericTypeResolver.resolveTypeArgument( connectionFactory.getClass(), ConnectionFactory.class); List<ConnectInterceptor<?>> typedInterceptors = connectInterceptors.get(serviceType); if (typedInterceptors == null) { typedInterceptors = Collections.emptyList(); } return typedInterceptors; }
@SuppressWarnings("unchecked") private void initApiProxy() { Class<?> apiType = GenericTypeResolver.resolveTypeArgument(serviceProvider.getClass(), ServiceProvider.class); if (apiType.isInterface()) { apiProxy = (A) Proxy.newProxyInstance( apiType.getClassLoader(), new Class[] {apiType}, new ApiInvocationHandler()); } }
@SuppressWarnings("unchecked") public AbstractMethodAnnotationPostProcessor(ConfigurableListableBeanFactory beanFactory) { Assert.notNull(beanFactory, "'beanFactory' must not be null"); this.messageHandlerAttributes.add(SEND_TIMEOUT_ATTRIBUTE); this.beanFactory = beanFactory; ConversionService conversionService = this.beanFactory.getConversionService(); if (conversionService != null) { this.conversionService = conversionService; } else { this.conversionService = DefaultConversionService.getSharedInstance(); } this.channelResolver = new BeanFactoryChannelResolver(beanFactory); this.annotationType = (Class<T>) GenericTypeResolver.resolveTypeArgument( this.getClass(), MethodAnnotationPostProcessor.class); }
@Override @SuppressWarnings({"rawtypes", "unchecked"}) public void afterPropertiesSet() { // code borrowed from AbstractAuthorizeTag ApplicationContext appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); Map<String, SecurityExpressionHandler> handlers = appContext.getBeansOfType(SecurityExpressionHandler.class); for (SecurityExpressionHandler h : handlers.values()) { if (FilterInvocation.class.equals( GenericTypeResolver.resolveTypeArgument(h.getClass(), SecurityExpressionHandler.class))) { handler = h; break; } } if (handler == null) { throw new IllegalStateException( "No visible WebSecurityExpressionHandler instance " + "could be found in the application context"); } super.afterPropertiesSet(); }