1 16 17 package org.springframework.beans.annotation; 18 19 import java.lang.annotation.Annotation ; 20 import java.lang.reflect.Method ; 21 import java.util.Arrays ; 22 import java.util.HashSet ; 23 import java.util.Set ; 24 25 import org.springframework.beans.BeanWrapper; 26 import org.springframework.beans.BeanWrapperImpl; 27 import org.springframework.util.ReflectionUtils; 28 29 35 public abstract class AnnotationBeanUtils { 36 37 42 public static void copyPropertiesToBean(Annotation ann, Object bean, String ... excludedProperties) { 43 Set <String > excluded = new HashSet <String >(Arrays.asList(excludedProperties)); 44 Method [] annotationProperties = ann.annotationType().getDeclaredMethods(); 45 46 BeanWrapper bw = new BeanWrapperImpl(bean); 47 for (Method annotationProperty : annotationProperties) { 48 String propertyName = annotationProperty.getName(); 49 50 if ((!excluded.contains(propertyName)) && bw.isWritableProperty(propertyName)) { 51 Object value = ReflectionUtils.invokeMethod(annotationProperty, ann); 52 bw.setPropertyValue(propertyName, value); 53 } 54 } 55 } 56 57 } 58 | Popular Tags |