1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.controller.config;
17
18 import org.apache.struts.config.ActionConfig;
19 import org.apache.struts.config.FormBeanConfig;
20 import org.apache.struts.config.ModuleConfig;
21 import org.seasar.tuigwaa.database.function.SearchExeFunction;
22 import org.seasar.tuigwaa.database.function.UpdateExeFunction;
23 import org.seasar.tuigwaa.model.core.TgwEntity;
24 import org.seasar.tuigwaa.util.TgwNameUtils;
25
26 import com.isenshi.util.TableMap;
27 import com.isenshi.util.UniqueNameGenerator;
28
29 public class ModuleConfigMetadata {
30
31 private String siteName;
32
33 private UniqueNameGenerator actionNameGenerator = new UniqueNameGenerator();
34
35 private UniqueNameGenerator formNameGenerator = new UniqueNameGenerator();
36
37 private TableMap searchActionNameTable = new TableMap();
38
39 private TableMap customActionNameTable = new TableMap();
40
41 private TableMap searchFormNameTable = new TableMap();
42
43 private TableMap customFormNameTable = new TableMap();
44
45 private ModuleConfig moduleConfig;
46
47 public ModuleConfigMetadata(String siteName, ModuleConfig moduleConfig) {
48 this.siteName = siteName;
49 this.moduleConfig = moduleConfig;
50 }
51
52 public ModuleConfig getModuleConfig() {
53 return moduleConfig;
54 }
55
56 public String getSiteName() {
57 return siteName;
58 }
59
60 public void addExtraModuleConfig(ModuleConfig extraModuleConfig){
61
62 }
63
64 public String generateSearchActionName(TgwEntity entity,
65 SearchExeFunction exeFunction) {
66 String actionName = TgwNameUtils.toSearchActionName(entity);
67 String generatedName = actionNameGenerator.nextUniqueName(actionName);
68 searchActionNameTable.put(generatedName, entity.getName(), exeFunction
69 .getName());
70 return generatedName;
71 }
72
73 public String generateCustomActionName(TgwEntity entity,
74 UpdateExeFunction updateExe) {
75 String actionName = TgwNameUtils.toCustomSaveActionName(entity);
76 String generatedName = actionNameGenerator.nextUniqueName(actionName);
77 customActionNameTable.put(generatedName, entity.getName(), updateExe
78 .getName());
79 return generatedName;
80 }
81
82 public String getSearchActionName(String entityName, String funcName) {
83 return (String) searchActionNameTable.get(entityName, funcName);
84 }
85
86 public String getCustomActionName(String entityName, String cformName) {
87 return (String) customActionNameTable.get(entityName, cformName);
88 }
89
90 public String generateSearchFormName(TgwEntity entity,
91 SearchExeFunction exeFunction) {
92 String searchFormName = TgwNameUtils.toSearchFormName(entity);
93 String generatedName = formNameGenerator.nextUniqueName(searchFormName);
94 searchFormNameTable.put(generatedName, entity.getName(), exeFunction
95 .getName());
96 return generatedName;
97 }
98
99 public String generateCusotmFormName(TgwEntity entity,
100 UpdateExeFunction updateExe) {
101 String customFormName = TgwNameUtils.toCustomFormName(entity);
102 String generatedName = formNameGenerator.nextUniqueName(customFormName);
103 customFormNameTable.put(generatedName, entity.getName(), updateExe
104 .getName());
105 return generatedName;
106 }
107
108 public String getSearchFormName(String entityName, String funcName) {
109 return (String) searchFormNameTable.get(entityName, funcName);
110 }
111
112 public String getCustomFormName(String entityName, String cformName) {
113 return (String) customFormNameTable.get(entityName, cformName);
114 }
115
116 public void removeEntityConfig(String siteName, String entityName) {
117 String formName = TgwNameUtils.toFormName(entityName);
118 String actionName = TgwNameUtils.toActionName(entityName);
119 removeActionAndForm(siteName, actionName, formName);
120 }
121
122 public void removeSearchConfig(TgwEntity entity, String funcName){
123 String actionName = getSearchActionName(entity.getName(), funcName);
124 String formName = getSearchFormName(entity.getName(), funcName);
125 removeActionAndForm(entity.getDomainName(), actionName, formName);
126 }
127
128 public void removeCustomFormConfig(TgwEntity entity, String cformName){
129 String actionName = getCustomActionName(entity.getName(), cformName);
130 String formName = getCustomFormName(entity.getName(), cformName);
131 removeActionAndForm(entity.getDomainName(), actionName, formName);
132 formName = TgwNameUtils.toCustomTableFormName(formName);
133 actionName = TgwNameUtils.toCustomTableSaveActionName(actionName);
134 removeActionAndForm(entity.getDomainName(), actionName, formName);
135 }
136
137 private void removeActionAndForm(String siteName, String actionName,
138 String formName) {
139 ModuleConfig moduleConfig = getModuleConfig();
140 if (moduleConfig == null) {
141 return;
142 }
143 FormBeanConfig formBeanConfig = moduleConfig
144 .findFormBeanConfig(formName);
145 ActionConfig actionConfig = moduleConfig.findActionConfig(actionName);
146
147 if (formBeanConfig != null) {
148 moduleConfig.removeFormBeanConfig(formBeanConfig);
149 }
150 if (actionConfig != null) {
151 moduleConfig.removeActionConfig(actionConfig);
152 }
153 }
154 }