@@ -64,46 +64,6 @@ private static Method makeAccessible(final Method method)
6464 return method ;
6565 }
6666
67- private static boolean tryToReplaceCollectionContent (final Collection <Object > target ,
68- final Collection <Object > value )
69- {
70- if (target == null )
71- {
72- return false ;
73- }
74- try
75- {
76- target .clear ();
77- target .addAll (value );
78- return true ;
79- }
80- catch (final Exception unmodifiable )
81- {
82- logger .debug ("Failed to replace content of existing Collection" , unmodifiable );
83- return false ;
84- }
85- }
86-
87- private static boolean tryToReplaceMapContent (final Map <Object , Object > target ,
88- final Map <Object , Object > value )
89- {
90- if (target == null )
91- {
92- return false ;
93- }
94- try
95- {
96- target .clear ();
97- target .putAll (value );
98- return true ;
99- }
100- catch (final Exception unmodifiable )
101- {
102- logger .debug ("Failed to replace content of existing Map" , unmodifiable );
103- return false ;
104- }
105- }
106-
10767 public final Set <String > getCategories ()
10868 {
10969 return categories ;
@@ -124,6 +84,58 @@ public void setExcluded(final boolean excluded)
12484 this .excluded = excluded ;
12585 }
12686
87+ public String getPropertyName ()
88+ {
89+ return this .propertyName ;
90+ }
91+
92+ /**
93+ * @return The annotations of the getter used to access this property.
94+ */
95+ public Set <Annotation > getReadMethodAnnotations ()
96+ {
97+ return new LinkedHashSet <Annotation >(Arrays .asList (readMethod .getAnnotations ()));
98+ }
99+
100+ public <T extends Annotation > T getReadMethodAnnotation (final Class <T > annotationClass )
101+ {
102+ final Set <? extends Annotation > annotations = getReadMethodAnnotations ();
103+ assert (annotations != null ) : "Something is wrong here. " +
104+ "The contract of getReadAnnotations() guarantees a non-null return value." ;
105+ for (final Annotation annotation : annotations )
106+ {
107+ if (annotationClass .isAssignableFrom (annotation .annotationType ()))
108+ {
109+ return annotationClass .cast (annotation );
110+ }
111+ }
112+ return null ;
113+ }
114+
115+ public BeanPropertyElementSelector getElementSelector ()
116+ {
117+ return new BeanPropertyElementSelector (this .propertyName );
118+ }
119+
120+ public Object get (final Object target )
121+ {
122+ if (target == null )
123+ {
124+ return null ;
125+ }
126+ try
127+ {
128+ return readMethod .invoke (target );
129+ }
130+ catch (final Exception e )
131+ {
132+ final BeanPropertyReadException ex = new BeanPropertyReadException (e );
133+ ex .setPropertyName (propertyName );
134+ ex .setTargetType (target .getClass ());
135+ throw ex ;
136+ }
137+ }
138+
127139 public void set (final Object target , final Object value )
128140 {
129141 if (target == null )
@@ -142,24 +154,14 @@ else if (writeMethod == null)
142154 }
143155 }
144156
145- private void logFailedSet (final Object value )
157+ public void unset (final Object target )
146158 {
147- logger . info ( "Couldn't set new value '{}' for property '{}'" , value , propertyName );
159+ set ( target , null );
148160 }
149161
150- private void invokeWriteMethod ( final Object target , final Object value )
162+ private void logFailedSet ( final Object value )
151163 {
152- try
153- {
154- writeMethod .invoke (target , value );
155- }
156- catch (final Exception e )
157- {
158- final BeanPropertyWriteException ex = new BeanPropertyWriteException (e , value );
159- ex .setPropertyName (propertyName );
160- ex .setTargetType (getType ());
161- throw ex ;
162- }
164+ logger .info ("Couldn't set new value '{}' for property '{}'" , value , propertyName );
163165 }
164166
165167 private void tryToReplaceContentOfCollectionTypes (final Object target , final Object value )
@@ -181,66 +183,64 @@ private void tryToReplaceContentOfCollectionTypes(final Object target, final Obj
181183 logFailedSet (value );
182184 }
183185
184- public Object get (final Object target )
186+ private void invokeWriteMethod (final Object target , final Object value )
185187 {
186- if (target == null )
187- {
188- return null ;
189- }
190188 try
191189 {
192- return readMethod .invoke (target );
190+ writeMethod .invoke (target , value );
193191 }
194192 catch (final Exception e )
195193 {
196- final BeanPropertyReadException ex = new BeanPropertyReadException ( e );
194+ final BeanPropertyWriteException ex = new BeanPropertyWriteException ( e , value );
197195 ex .setPropertyName (propertyName );
198- ex .setTargetType (target . getClass ());
196+ ex .setTargetType (getType ());
199197 throw ex ;
200198 }
201199 }
202200
203- public void unset (final Object target )
204- {
205- set (target , null );
206- }
207-
208- public Class <?> getType ()
209- {
210- return this .type ;
211- }
212-
213- public String getPropertyName ()
214- {
215- return this .propertyName ;
216- }
217-
218- public BeanPropertyElementSelector getElementSelector ()
201+ private static boolean tryToReplaceCollectionContent (final Collection <Object > target ,
202+ final Collection <Object > value )
219203 {
220- return new BeanPropertyElementSelector (this .propertyName );
204+ if (target == null )
205+ {
206+ return false ;
207+ }
208+ try
209+ {
210+ target .clear ();
211+ target .addAll (value );
212+ return true ;
213+ }
214+ catch (final Exception unmodifiable )
215+ {
216+ logger .debug ("Failed to replace content of existing Collection" , unmodifiable );
217+ return false ;
218+ }
221219 }
222220
223- /**
224- * @return The annotations of the getter used to access this property.
225- */
226- public Set <Annotation > getReadMethodAnnotations ()
221+ private static boolean tryToReplaceMapContent (final Map <Object , Object > target ,
222+ final Map <Object , Object > value )
227223 {
228- return new LinkedHashSet <Annotation >(Arrays .asList (readMethod .getAnnotations ()));
224+ if (target == null )
225+ {
226+ return false ;
227+ }
228+ try
229+ {
230+ target .clear ();
231+ target .putAll (value );
232+ return true ;
233+ }
234+ catch (final Exception unmodifiable )
235+ {
236+ logger .debug ("Failed to replace content of existing Map" , unmodifiable );
237+ return false ;
238+ }
229239 }
230240
231- public < T extends Annotation > T getReadMethodAnnotation ( final Class <T > annotationClass )
241+ public Class <?> getType ( )
232242 {
233- final Set <? extends Annotation > annotations = getReadMethodAnnotations ();
234- assert (annotations != null ) : "Something is wrong here. " +
235- "The contract of getReadAnnotations() guarantees a non-null return value." ;
236- for (final Annotation annotation : annotations )
237- {
238- if (annotationClass .isAssignableFrom (annotation .annotationType ()))
239- {
240- return annotationClass .cast (annotation );
241- }
242- }
243- return null ;
243+ return this .type ;
244244 }
245245
246246 @ Override
0 commit comments