View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.tuigwaa.controller.config;
17  
18  import java.util.Iterator;
19  import java.util.Map;
20  
21  import org.apache.commons.validator.Form;
22  import org.apache.commons.validator.FormSet;
23  import org.seasar.tuigwaa.model.core.TgwAttribute;
24  import org.seasar.tuigwaa.util.TgwNameUtils;
25  
26  import com.isenshi.util.converter.ConverterResource;
27  
28  public class TableConfigGenerator extends ConfigGenerator {
29  
30  	private static final String PROTO_FORM = "customTableFormProto";
31  
32  	private static final String PROTO_ACTION = "actionCTableSave";
33  
34  	private CustomFormConfigGenerator generator;
35  
36  	public TableConfigGenerator(CustomFormConfigGenerator cformGenerator,
37  			ConverterResource resource, ModuleConfigMetadata metadata,
38  			Map formSetChache) {
39  		super(metadata, resource, formSetChache);
40  		this.generator = cformGenerator;
41  	}
42  
43  	public void generate() {
44  		String formName = generator.getFormName();
45  		String actionName = generator.getActionName();
46  		formName = TgwNameUtils.toCustomTableFormName(formName);
47  		actionName = TgwNameUtils.toCustomTableSaveActionName(actionName);
48  		super.generate(PROTO_FORM, formName, PROTO_ACTION, actionName);
49  
50  		FormSet formSet = createFormSet();
51  		setValidator(formSet);
52  	}
53  
54  	private FormSet createFormSet() {
55  		FormSet fs = getFormSet(generator.getEntity().getDomainName(),
56  				getFormName());
57  		Form form = new Form();
58  		form.setName(getFormName());
59  		Iterator itr = generator.getEntity().getFieldIterator();
60  		while (itr.hasNext()) {
61  			TgwAttribute attr = (TgwAttribute) itr.next();
62  			String attrName = attr.getName();
63  			if (generator.hasField(attrName)) {
64  				ValidatorUtils.bindField(form, attr, "rowSet");
65  			}
66  		}
67  		fs.addForm(form);
68  		return fs;
69  	}
70  }