View Javadoc

1   /*
2    * joey-gen and its relative products are published under the terms
3    * of the Apache Software License.
4    * 
5    * Created on 2004/12/27 17:56:49
6    */
7   package org.asyrinx.joey.gen.model.pattern;
8   
9   import org.asyrinx.joey.gen.model.command.ValidationError;
10  import org.asyrinx.joey.gen.model.rdb.Column;
11  import org.asyrinx.joey.gen.model.rdb.Table;
12  import org.asyrinx.joey.gen.model.rdb.TablePattern;
13  import org.asyrinx.joey.gen.model.rdb.TablePatternParam;
14  
15  /***
16   * @author takeshi
17   */
18  public class SingleColumnPattern implements Pattern {
19  
20      public SingleColumnPattern(String defaultColumnName, String columnType, String label) {
21          this(defaultColumnName, columnType, null, label);
22      }
23  
24      public SingleColumnPattern(String defaultColumnName, String columnType, String enum,
25              String label) {
26          this.defaultColumnName = defaultColumnName;
27          this.columnType = columnType;
28          this.enum = enum;
29          this.label = label;
30      }
31  
32      final String defaultColumnName;
33  
34      final String columnType;
35  
36      final String enum;
37  
38      final String label;
39  
40      public void expand(TablePattern tablePattern) {
41          final TablePatternParam param;
42          if (tablePattern.isEmpty()) {
43              param = new TablePatternParam(tablePattern, "columnName", null);
44              param.setValue(this.defaultColumnName);
45          } else {
46              param = tablePattern.getParam("columnName");
47              if (param == null)
48                  throw new ValidationError("param named 'columnName' was not found", tablePattern);
49          }
50          final String columnName = param.getValue();
51          final Table table = tablePattern.getParent();
52          final Column column = new Column(table, columnName, columnType);
53          column.setLabel(this.label);
54          column.setRequired(true);
55          column.setEnum(this.enum);
56      }
57  
58      public boolean isTarget(String templatePath) {
59          return "om/service".equals(templatePath);
60      }
61  }