Java Code Examples for org.springframework.util.ClassUtils#hasMethod()
The following examples show how to use
org.springframework.util.ClassUtils#hasMethod() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CubaMethodValidationInterceptor.java From cuba with Apache License 2.0 | 6 votes |
protected boolean isFactoryBeanMetadataMethod(Method method) { Class<?> clazz = method.getDeclaringClass(); // Call from interface-based proxy handle, allowing for an efficient check? if (clazz.isInterface()) { return ((clazz == FactoryBean.class || clazz == SmartFactoryBean.class) && !method.getName().equals("getObject")); } // Call from CGLIB proxy handle, potentially implementing a FactoryBean method? Class<?> factoryBeanType = null; if (SmartFactoryBean.class.isAssignableFrom(clazz)) { factoryBeanType = SmartFactoryBean.class; } else if (FactoryBean.class.isAssignableFrom(clazz)) { factoryBeanType = FactoryBean.class; } return (factoryBeanType != null && !method.getName().equals("getObject") && ClassUtils.hasMethod(factoryBeanType, method.getName(), method.getParameterTypes())); }
Example 2
Source File: ReplyEventTest.java From line-bot-sdk-java with Apache License 2.0 | 6 votes |
@Test public void eventWithReplyTokenShouldBeImplementReplySupportTest() { final List<Class<?>> eventClasses = getAllEventClass(); Preconditions.checkState(!eventClasses.isEmpty(), "Event classes are empty. Maybe scanning bug."); log.info("eventClasses = {}", eventClasses); for (Class<?> eventClass : eventClasses) { final boolean hasReplyTokenMethod = ClassUtils.hasMethod(eventClass, "getReplyToken"); if (hasReplyTokenMethod) { assertThat(ReplyEvent.class) .isAssignableFrom(eventClass); } } }
Example 3
Source File: MethodValidationInterceptor.java From java-technology-stack with MIT License | 6 votes |
private boolean isFactoryBeanMetadataMethod(Method method) { Class<?> clazz = method.getDeclaringClass(); // Call from interface-based proxy handle, allowing for an efficient check? if (clazz.isInterface()) { return ((clazz == FactoryBean.class || clazz == SmartFactoryBean.class) && !method.getName().equals("getObject")); } // Call from CGLIB proxy handle, potentially implementing a FactoryBean method? Class<?> factoryBeanType = null; if (SmartFactoryBean.class.isAssignableFrom(clazz)) { factoryBeanType = SmartFactoryBean.class; } else if (FactoryBean.class.isAssignableFrom(clazz)) { factoryBeanType = FactoryBean.class; } return (factoryBeanType != null && !method.getName().equals("getObject") && ClassUtils.hasMethod(factoryBeanType, method.getName(), method.getParameterTypes())); }
Example 4
Source File: AutowireUtils.java From java-technology-stack with MIT License | 5 votes |
/** * Determine whether the given bean property is excluded from dependency checks. * <p>This implementation excludes properties defined by CGLIB. * @param pd the PropertyDescriptor of the bean property * @return whether the bean property is excluded */ public static boolean isExcludedFromDependencyCheck(PropertyDescriptor pd) { Method wm = pd.getWriteMethod(); if (wm == null) { return false; } if (!wm.getDeclaringClass().getName().contains("$$")) { // Not a CGLIB method so it's OK. return false; } // It was declared by CGLIB, but we might still want to autowire it // if it was actually declared by the superclass. Class<?> superclass = wm.getDeclaringClass().getSuperclass(); return !ClassUtils.hasMethod(superclass, wm.getName(), wm.getParameterTypes()); }
Example 5
Source File: AutowireUtils.java From blog_demos with Apache License 2.0 | 5 votes |
/** * Return whether the setter method of the given bean property is defined * in any of the given interfaces. * @param pd the PropertyDescriptor of the bean property * @param interfaces the Set of interfaces (Class objects) * @return whether the setter method is defined by an interface */ public static boolean isSetterDefinedInInterface(PropertyDescriptor pd, Set<Class<?>> interfaces) { Method setter = pd.getWriteMethod(); if (setter != null) { Class<?> targetClass = setter.getDeclaringClass(); for (Class<?> ifc : interfaces) { if (ifc.isAssignableFrom(targetClass) && ClassUtils.hasMethod(ifc, setter.getName(), setter.getParameterTypes())) { return true; } } } return false; }
Example 6
Source File: AutowireUtils.java From blog_demos with Apache License 2.0 | 5 votes |
/** * Determine whether the given bean property is excluded from dependency checks. * <p>This implementation excludes properties defined by CGLIB. * @param pd the PropertyDescriptor of the bean property * @return whether the bean property is excluded */ public static boolean isExcludedFromDependencyCheck(PropertyDescriptor pd) { Method wm = pd.getWriteMethod(); if (wm == null) { return false; } if (!wm.getDeclaringClass().getName().contains("$$")) { // Not a CGLIB method so it's OK. return false; } // It was declared by CGLIB, but we might still want to autowire it // if it was actually declared by the superclass. Class<?> superclass = wm.getDeclaringClass().getSuperclass(); return !ClassUtils.hasMethod(superclass, wm.getName(), wm.getParameterTypes()); }
Example 7
Source File: CglibAopProxy.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Check whether the given method is declared on any of the given interfaces. */ private static boolean implementsInterface(Method method, Set<Class<?>> ifcs) { for (Class<?> ifc : ifcs) { if (ClassUtils.hasMethod(ifc, method.getName(), method.getParameterTypes())) { return true; } } return false; }
Example 8
Source File: AutowireUtils.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Return whether the setter method of the given bean property is defined * in any of the given interfaces. * @param pd the PropertyDescriptor of the bean property * @param interfaces the Set of interfaces (Class objects) * @return whether the setter method is defined by an interface */ public static boolean isSetterDefinedInInterface(PropertyDescriptor pd, Set<Class<?>> interfaces) { Method setter = pd.getWriteMethod(); if (setter != null) { Class<?> targetClass = setter.getDeclaringClass(); for (Class<?> ifc : interfaces) { if (ifc.isAssignableFrom(targetClass) && ClassUtils.hasMethod(ifc, setter.getName(), setter.getParameterTypes())) { return true; } } } return false; }
Example 9
Source File: AutowireUtils.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Determine whether the given bean property is excluded from dependency checks. * <p>This implementation excludes properties defined by CGLIB. * @param pd the PropertyDescriptor of the bean property * @return whether the bean property is excluded */ public static boolean isExcludedFromDependencyCheck(PropertyDescriptor pd) { Method wm = pd.getWriteMethod(); if (wm == null) { return false; } if (!wm.getDeclaringClass().getName().contains("$$")) { // Not a CGLIB method so it's OK. return false; } // It was declared by CGLIB, but we might still want to autowire it // if it was actually declared by the superclass. Class<?> superclass = wm.getDeclaringClass().getSuperclass(); return !ClassUtils.hasMethod(superclass, wm.getName(), wm.getParameterTypes()); }
Example 10
Source File: DisposableBeanAdapter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Check whether the given bean has any kind of destroy method to call. * @param bean the bean instance * @param beanDefinition the corresponding bean definition */ public static boolean hasDestroyMethod(Object bean, RootBeanDefinition beanDefinition) { if (bean instanceof DisposableBean || closeableInterface.isInstance(bean)) { return true; } String destroyMethodName = beanDefinition.getDestroyMethodName(); if (AbstractBeanDefinition.INFER_METHOD.equals(destroyMethodName)) { return (ClassUtils.hasMethod(bean.getClass(), CLOSE_METHOD_NAME) || ClassUtils.hasMethod(bean.getClass(), SHUTDOWN_METHOD_NAME)); } return StringUtils.hasLength(destroyMethodName); }
Example 11
Source File: AutowireUtils.java From java-technology-stack with MIT License | 5 votes |
/** * Return whether the setter method of the given bean property is defined * in any of the given interfaces. * @param pd the PropertyDescriptor of the bean property * @param interfaces the Set of interfaces (Class objects) * @return whether the setter method is defined by an interface */ public static boolean isSetterDefinedInInterface(PropertyDescriptor pd, Set<Class<?>> interfaces) { Method setter = pd.getWriteMethod(); if (setter != null) { Class<?> targetClass = setter.getDeclaringClass(); for (Class<?> ifc : interfaces) { if (ifc.isAssignableFrom(targetClass) && ClassUtils.hasMethod(ifc, setter.getName(), setter.getParameterTypes())) { return true; } } } return false; }
Example 12
Source File: CglibAopProxy.java From spring-analysis-note with MIT License | 5 votes |
/** * Check whether the given method is declared on any of the given interfaces. */ private static boolean implementsInterface(Method method, Set<Class<?>> ifcs) { for (Class<?> ifc : ifcs) { if (ClassUtils.hasMethod(ifc, method.getName(), method.getParameterTypes())) { return true; } } return false; }
Example 13
Source File: DisposableBeanAdapter.java From java-technology-stack with MIT License | 5 votes |
/** * Check whether the given bean has any kind of destroy method to call. * @param bean the bean instance * @param beanDefinition the corresponding bean definition */ public static boolean hasDestroyMethod(Object bean, RootBeanDefinition beanDefinition) { if (bean instanceof DisposableBean || bean instanceof AutoCloseable) { return true; } String destroyMethodName = beanDefinition.getDestroyMethodName(); if (AbstractBeanDefinition.INFER_METHOD.equals(destroyMethodName)) { return (ClassUtils.hasMethod(bean.getClass(), CLOSE_METHOD_NAME) || ClassUtils.hasMethod(bean.getClass(), SHUTDOWN_METHOD_NAME)); } return StringUtils.hasLength(destroyMethodName); }
Example 14
Source File: CglibAopProxy.java From java-technology-stack with MIT License | 5 votes |
/** * Check whether the given method is declared on any of the given interfaces. */ private static boolean implementsInterface(Method method, Set<Class<?>> ifcs) { for (Class<?> ifc : ifcs) { if (ClassUtils.hasMethod(ifc, method.getName(), method.getParameterTypes())) { return true; } } return false; }
Example 15
Source File: RequestBodyArgumentResolver.java From mPass with Apache License 2.0 | 5 votes |
/** * 判断类对应方法的参数是否有requestbody注解 * @param clazz * @param refParam * @return */ private boolean hasRequestBodyAnnotation(Class<?> clazz, MethodParameter refParam) { if (ClassUtils.hasMethod(clazz, refParam.getExecutable().getName(), refParam.getExecutable().getParameterTypes())) { Method tmpMethod = ClassUtils.getMethod(clazz, refParam.getExecutable().getName(), refParam.getExecutable().getParameterTypes()); MethodParameter supperParam = new MethodParameter(tmpMethod, refParam.getParameterIndex()); if (supperParam.hasParameterAnnotation(RequestBody.class)) { return true; } } return false; }
Example 16
Source File: RequestBodyArgumentResolver.java From mPaaS with Apache License 2.0 | 5 votes |
/** * 判断类对应方法的参数是否有requestbody注解 * @param clazz * @param refParam * @return */ private boolean hasRequestBodyAnnotation(Class<?> clazz, MethodParameter refParam) { if (ClassUtils.hasMethod(clazz, refParam.getExecutable().getName(), refParam.getExecutable().getParameterTypes())) { Method tmpMethod = ClassUtils.getMethod(clazz, refParam.getExecutable().getName(), refParam.getExecutable().getParameterTypes()); MethodParameter supperParam = new MethodParameter(tmpMethod, refParam.getParameterIndex()); if (supperParam.hasParameterAnnotation(RequestBody.class)) { return true; } } return false; }
Example 17
Source File: AutowireUtils.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Return whether the setter method of the given bean property is defined * in any of the given interfaces. * @param pd the PropertyDescriptor of the bean property * @param interfaces the Set of interfaces (Class objects) * @return whether the setter method is defined by an interface */ public static boolean isSetterDefinedInInterface(PropertyDescriptor pd, Set<Class<?>> interfaces) { Method setter = pd.getWriteMethod(); if (setter != null) { Class<?> targetClass = setter.getDeclaringClass(); for (Class<?> ifc : interfaces) { if (ifc.isAssignableFrom(targetClass) && ClassUtils.hasMethod(ifc, setter.getName(), setter.getParameterTypes())) { return true; } } } return false; }
Example 18
Source File: DisposableBeanAdapter.java From spring-analysis-note with MIT License | 5 votes |
/** * Check whether the given bean has any kind of destroy method to call. * @param bean the bean instance * @param beanDefinition the corresponding bean definition */ public static boolean hasDestroyMethod(Object bean, RootBeanDefinition beanDefinition) { if (bean instanceof DisposableBean || bean instanceof AutoCloseable) { return true; } String destroyMethodName = beanDefinition.getDestroyMethodName(); if (AbstractBeanDefinition.INFER_METHOD.equals(destroyMethodName)) { return (ClassUtils.hasMethod(bean.getClass(), CLOSE_METHOD_NAME) || ClassUtils.hasMethod(bean.getClass(), SHUTDOWN_METHOD_NAME)); } return StringUtils.hasLength(destroyMethodName); }
Example 19
Source File: AutowireUtils.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Determine whether the given bean property is excluded from dependency checks. * <p>This implementation excludes properties defined by CGLIB. * @param pd the PropertyDescriptor of the bean property * @return whether the bean property is excluded */ public static boolean isExcludedFromDependencyCheck(PropertyDescriptor pd) { Method wm = pd.getWriteMethod(); if (wm == null) { return false; } if (!wm.getDeclaringClass().getName().contains("$$")) { // Not a CGLIB method so it's OK. return false; } // It was declared by CGLIB, but we might still want to autowire it // if it was actually declared by the superclass. Class<?> superclass = wm.getDeclaringClass().getSuperclass(); return !ClassUtils.hasMethod(superclass, wm.getName(), wm.getParameterTypes()); }
Example 20
Source File: WebRequestDataBinder.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * Bind the parameters of the given request to this binder's target, * also binding multipart files in case of a multipart request. * <p>This call can create field errors, representing basic binding * errors like a required field (code "required"), or type mismatch * between value and bean property (code "typeMismatch"). * <p>Multipart files are bound via their parameter name, just like normal * HTTP parameters: i.e. "uploadedFile" to an "uploadedFile" bean property, * invoking a "setUploadedFile" setter method. * <p>The type of the target property for a multipart file can be Part, MultipartFile, * byte[], or String. The latter two receive the contents of the uploaded file; * all metadata like original file name, content type, etc are lost in those cases. * @param request request with parameters to bind (can be multipart) * @see org.springframework.web.multipart.MultipartRequest * @see org.springframework.web.multipart.MultipartFile * @see javax.servlet.http.Part * @see #bind(org.springframework.beans.PropertyValues) */ public void bind(WebRequest request) { MutablePropertyValues mpvs = new MutablePropertyValues(request.getParameterMap()); if (isMultipartRequest(request) && request instanceof NativeWebRequest) { MultipartRequest multipartRequest = ((NativeWebRequest) request).getNativeRequest(MultipartRequest.class); if (multipartRequest != null) { bindMultipart(multipartRequest.getMultiFileMap(), mpvs); } else if (ClassUtils.hasMethod(HttpServletRequest.class, "getParts")) { HttpServletRequest serlvetRequest = ((NativeWebRequest) request).getNativeRequest(HttpServletRequest.class); new Servlet3MultipartHelper(isBindEmptyMultipartFiles()).bindParts(serlvetRequest, mpvs); } } doBind(mpvs); }