1 package jp.ac.aiit.xdf.component.swing.mappers;
6 import java.util.Map.Entry;
8 import jp.ac.aiit.xdf.component.ComponentMapper;
9 import jp.ac.aiit.xdf.component.swing.attribute.AttributeProcessingUnit;
10 import jp.ac.aiit.xdf.component.swing.event.SwingEventHandler;
11 import jp.ac.aiit.xdf.core.action.Action;
12 import jp.ac.aiit.xdf.core.action.EventHandler;
13 import jp.ac.aiit.xdf.core.model.ObjectModel;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * Swing用のコンポーネントマッパのテンプレートクラス
20 * このテンプレートクラスでは、Swingコンポーネントを生成するために必要な共通部分をテンプレート化し、
21 * 非共通部分をサブクラスで実装させる構成(テンプレートメソッドパターン)になっている。
23 * @author Shunichi Takagi
25 public abstract class SwingComponentMapperTemplate implements ComponentMapper {
26 private static final Logger log = LoggerFactory.getLogger(SwingComponentMapperTemplate.class);
27 protected Map<String, AttributeProcessingUnit> processingUnits;
28 protected Map<String, EventHandler> processingAction;
30 protected ObjectModel model;
32 private boolean realized;
33 protected Object component;
35 protected List<SwingEventHandler> eventhandlers;
40 public SwingComponentMapperTemplate() {
41 this.processingUnits = initProcessingUnits();
42 this.processingAction = intiProcessingAction();
46 public void setModel(ObjectModel model) {
51 public ObjectModel getModel() {
56 public Object getComponent() {
61 public boolean isRealized() {
66 public void realize() {
67 this.component = newComponent();
69 //ObjectModelに設定された属性を実コンポーネントに反映
70 Map<String, Object> map = model.attrMaps();
71 for(Entry<String, Object> entry : map.entrySet()) {
72 AttributeProcessingUnit unit = processingUnits.get(entry.getKey());
74 unit.invokeSet(component, entry.getKey(), entry.getValue());
79 Map<String, Action> actions = model.getActions();
80 for (Entry<String, Action> action : actions.entrySet()){
81 EventHandler handler = processingAction.get(action.getKey());
83 handler.setEvent(this.model, this.component, action.getValue());
85 log.debug("アクション登録失敗です。 <タグ名:"+ this.model.tagname() + "> <ID:" + this.model.id() + "> <アクション:"+ action.getKey() +">");
89 processingChildComponents();
90 //SwingEventHandler.setEvent(model, (Component) component);
96 public Object typeConvert(String name, String value) {
97 AttributeProcessingUnit unit = processingUnits.get(name);
101 return unit.typeConvert(value);
106 public Object getAttr(String name) {
107 AttributeProcessingUnit unit = processingUnits.get(name);
111 return unit.invokeGet(this.component, name);
116 public void setAttr(String name, Object value){
117 AttributeProcessingUnit unit = processingUnits.get(name);
119 unit.invokeSet(component, name, value);
124 public void setRealize(boolean realize){
125 this.realized = realize;
128 protected abstract Object newComponent();
129 protected abstract void processingChildComponents();
130 protected abstract Map<String, AttributeProcessingUnit> initProcessingUnits();
131 protected abstract Map<String, EventHandler> intiProcessingAction();