2424
2525import java .lang .annotation .Annotation ;
2626import java .lang .reflect .Method ;
27- import java .util .Arrays ;
2827import java .util .Collection ;
28+ import java .util .Collections ;
2929import java .util .LinkedHashSet ;
3030import java .util .Map ;
3131import java .util .Set ;
3232import java .util .TreeSet ;
3333
34+ import static java .util .Arrays .asList ;
35+
3436/**
3537 * @author Daniel Bechler
3638 */
37- public class BeanPropertyAccessor implements PropertyAwareAccessor
39+ public class PropertyAccessor implements PropertyAwareAccessor
3840{
39- private static final Logger logger = LoggerFactory .getLogger (BeanPropertyAccessor .class );
41+ private static final Logger logger = LoggerFactory .getLogger (PropertyAccessor .class );
4042
4143 private final String propertyName ;
4244 private final Class <?> type ;
4345 private final Method readMethod ;
4446 private final Method writeMethod ;
45- private Set <String > categories = new TreeSet <String >();
46- private boolean excluded ;
4747
48- public BeanPropertyAccessor (final String propertyName , final Method readMethod , final Method writeMethod )
48+ public PropertyAccessor (final String propertyName , final Method readMethod , final Method writeMethod )
4949 {
5050 Assert .notNull (propertyName , "propertyName" );
5151 Assert .notNull (readMethod , "readMethod" );
@@ -57,31 +57,28 @@ public BeanPropertyAccessor(final String propertyName, final Method readMethod,
5757
5858 private static Method makeAccessible (final Method method )
5959 {
60- if (method != null )
60+ if (method != null && ! method . isAccessible () )
6161 {
62+ logger .debug ("Making method accessible: {}" , method .toString ());
6263 method .setAccessible (true );
6364 }
6465 return method ;
6566 }
6667
67- public final Set <String > getCategories ()
68+ public final Set <String > getCategoriesFromAnnotation ()
6869 {
69- return categories ;
70- }
71-
72- public final void setCategories (final Set <String > categories )
73- {
74- this .categories = categories ;
75- }
76-
77- public boolean isExcluded ()
78- {
79- return excluded ;
70+ final ObjectDiffProperty annotation = readMethod .getAnnotation (ObjectDiffProperty .class );
71+ if (annotation != null )
72+ {
73+ return new TreeSet <String >(asList (annotation .categories ()));
74+ }
75+ return Collections .emptySet ();
8076 }
8177
82- public void setExcluded ( final boolean excluded )
78+ public boolean isExcludedByAnnotation ( )
8379 {
84- this .excluded = excluded ;
80+ final ObjectDiffProperty annotation = readMethod .getAnnotation (ObjectDiffProperty .class );
81+ return annotation != null && annotation .excluded ();
8582 }
8683
8784 public String getPropertyName ()
@@ -94,7 +91,7 @@ public String getPropertyName()
9491 */
9592 public Set <Annotation > getReadMethodAnnotations ()
9693 {
97- return new LinkedHashSet <Annotation >(Arrays . asList (readMethod .getAnnotations ()));
94+ return new LinkedHashSet <Annotation >(asList (readMethod .getAnnotations ()));
9895 }
9996
10097 public <T extends Annotation > T getReadMethodAnnotation (final Class <T > annotationClass )
@@ -129,7 +126,7 @@ public Object get(final Object target)
129126 }
130127 catch (final Exception e )
131128 {
132- final BeanPropertyReadException ex = new BeanPropertyReadException (e );
129+ final PropertyReadException ex = new PropertyReadException (e );
133130 ex .setPropertyName (propertyName );
134131 ex .setTargetType (target .getClass ());
135132 throw ex ;
@@ -191,7 +188,7 @@ private void invokeWriteMethod(final Object target, final Object value)
191188 }
192189 catch (final Exception e )
193190 {
194- final BeanPropertyWriteException ex = new BeanPropertyWriteException (e , value );
191+ final PropertyWriteException ex = new PropertyWriteException (e , value );
195192 ex .setPropertyName (propertyName );
196193 ex .setTargetType (getType ());
197194 throw ex ;
0 commit comments