OSDN Git Service

initial commit
[xdf/git-repos.git] / xdf / src / main / java / jp / ac / aiit / xdf / application / interceptors / ActionInterceptor.java
1 package jp.ac.aiit.xdf.application.interceptors;
2
3
4
5 import jp.ac.aiit.xdf.application.Application;
6 import jp.ac.aiit.xdf.core.action.Action;
7 import jp.ac.aiit.xdf.core.action.factory.ActionFactory;
8 import jp.ac.aiit.xdf.core.model.ObjectModel;
9 import jp.ac.aiit.xdf.core.selector.Selector;
10
11 /**
12  * 画面定義XMLに記述されたアクションの設定に基づき、コンポーネントとアクションの結びつけを行う。
13  * 
14  * @author Pin Yuan
15  */
16 public class ActionInterceptor implements UIDesignInterceptor {
17
18         @Override
19         public void intercept(UIDesignResource resource) {
20                 
21                 ObjectModel om = resource.getModel();
22                 parseAction(om);
23         }
24         
25         private void parseAction(ObjectModel rootModel) {
26                 ActionFactory factory = Application.getInstance().getActionFactory();
27                 
28                 for(ObjectModel actionModel : Selector.find("action", rootModel)) {
29                         
30                         if( actionModel.hasAttr("target") ) {
31                                 Action action = factory.createAction( (String) actionModel.attr("classname") );
32                                 String event = (String)actionModel.attr("event");
33                                 
34                                 String targetSelector = (String) actionModel.attr("target");
35                                 for(ObjectModel target : Selector.find(targetSelector, rootModel) ) {
36                                         target.setAction(action, event);
37                                 }
38                         }
39                 }
40         }
41 }