View Javadoc

1   /*
2    * MessagesAspect.java
3    * Created on 13 Июнь 2006 г., 16:00
4    */
5   
6   package org.weda.enhance.impl;
7   
8   import java.lang.reflect.Field;
9   import org.jboss.aop.joinpoint.FieldReadInvocation;
10  import org.weda.enhance.impl.AspectHelperImpl;
11  
12  /**
13   *
14   * @author Mikhail Titov
15   */
16  public class MessagesAspect {
17      
18      public Object resolveMessages(FieldReadInvocation joinPoint) 
19          throws Throwable 
20      {
21          Object res = joinPoint.invokeNext();
22          if (res==null){
23              Object callee = joinPoint.getTargetObject();
24              synchronized(joinPoint.getField()){
25                  Field field = joinPoint.getField();
26                  res = field.get(callee);
27                  if (res==null){
28                      res = AspectHelperImpl.INSTANCE.getMessagesRegistry()
29                                  .getMessagesForObject(callee);
30                      field.set(callee, res);
31                  }
32              }
33          }
34          return res;
35      }
36  }