1
2
3
4
5
6 package org.weda.property.impl;
7
8 import java.beans.IntrospectionException;
9 import org.weda.property.PropertyListenerResult;
10 import org.weda.property.PropertyOperationException;
11 import org.weda.property.PropertySetOperationListener;
12
13 /**
14 *
15 * @author Mikhail Titov
16 */
17 public class PropertySetOperation
18 extends AbstractPropertyOperation<PropertySetOperationListener>
19 {
20
21
22
23
24
25
26
27 public PropertySetOperation(Class propOwnerClass, String propertyName)
28 throws IntrospectionException
29 {
30 super(propOwnerClass, propertyName, false);
31
32
33
34
35
36
37
38 }
39
40 public Object invoke(Object obj, Object propValue)
41 throws PropertyOperationException
42 {
43 try{
44 PropertyListenerResult res = null;
45 if (listeners!=null)
46 for (PropertySetOperationListener listener: listeners)
47 res = listener.beforeSet(obj, propertyName, propValue);
48 if (res!=null)
49 propValue=res.getValue();
50 method.invoke(obj, propValue);
51 if (listeners!=null)
52 for (PropertySetOperationListener listener: listeners)
53 listener.afterSet(obj, propertyName, propValue);
54 return null;
55 }catch(Exception e){
56 throw new PropertyOperationException(
57 String.format(
58 "Can't execute SET operation on property (%s) " +
59 "for instance of class (%s)"
60 , propertyName, obj.getClass().getName())
61 , e);
62 }
63 }
64 }