View Javadoc

1   /*
2    * PropertySetOperation.java
3    * Created on 22 Май 2006 г., 0:19
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  //    @InjectHivemindObject()
21  //    private static ObjectDescriptorRegistry descRegistry;
22  //    @InjectHivemindObject()
23  //    private static AuditableObjectRegistry auditRegistry;
24      
25  //    private boolean auditUpdate = false;
26      
27      public PropertySetOperation(Class propOwnerClass, String propertyName) 
28          throws IntrospectionException
29      {
30          super(propOwnerClass, propertyName, false);
31  //        if (auditRegistry.isAuditEnabled()){
32  //            Set<String> props = 
33  //                    auditRegistry.getAuditableObjectProperties(
34  //                        AuditOperation.UPDATE, propOwnerClass);
35  //            if (props!=null && props.contains(propertyName))
36  //                auditUpdate = true;
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  }