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 java.util.Iterator;
19
20 import org.seasar.tuigwaa.database.function.SearchExeFunction;
21 import org.seasar.tuigwaa.database.function.criteria.CriteriaFunction;
22 import org.seasar.tuigwaa.database.function.criteria.SubcriteriaFunction;
23 import org.seasar.tuigwaa.model.common.EntityUtils;
24 import org.seasar.tuigwaa.model.core.TgwAttribute;
25 import org.seasar.tuigwaa.model.core.TgwEntity;
26 import org.seasar.tuigwaa.system.Constants;
27 import org.seasar.tuigwaa.util.TgwNameUtils;
28
29 import com.isenshi.util.converter.ConverterResource;
30
31 public class SearchConfigGenerator extends ConfigGenerator {
32
33 private TgwEntity entity;
34
35 private static final String PROTO_FORM = "searchFormProto";
36
37 private static final String PROTO_ACTION = "actionSearch";
38
39 public SearchConfigGenerator(ConverterResource resource, TgwEntity entity,
40 ModuleConfigMetadata metadata) {
41 super(metadata, resource, null);
42 this.entity = entity;
43 }
44
45 public void generate(SearchExeFunction searchExeFunction) {
46 String formName = getModuleConfigMetadata().generateSearchFormName(
47 entity, searchExeFunction);
48 String actionName = getModuleConfigMetadata().generateSearchActionName(
49 entity, searchExeFunction);
50 generate(PROTO_FORM, formName, PROTO_ACTION, actionName);
51 addProperties(searchExeFunction);
52 }
53
54 private void addProperties(SearchExeFunction searchExeFunction) {
55 Iterator itr = searchExeFunction.getCriteriaListFunction()
56 .getFunctionList().iterator();
57 while (itr.hasNext()) {
58
59 CriteriaFunction function = (CriteriaFunction) itr.next();
60 String name = function.getName();
61
62 String fieldName = getNestedFieldName("", function);
63 TgwAttribute field = entity.getField(fieldName);
64
65 addProperty(name, EntityUtils.toJavaType(field));
66
67 if (EntityUtils.needConverter(field)) {
68 String src = TgwNameUtils.toConverterFieldName(name);
69 addConverterResource(field, src, name);
70 }
71 }
72 addProperty(Constants.PARAM_PAGENAME, "java.lang.String");
73 }
74
75 private String getNestedFieldName(String prefix, CriteriaFunction function) {
76 if (function instanceof SubcriteriaFunction) {
77 return getNestedFieldName(prefix + function.getField() + ".",
78 ((SubcriteriaFunction) function).getSequentialFunction());
79 }
80 return prefix + function.getField();
81 }
82 }