1
2
3
4
5
6
7 package org.asyrinx.joey.gen.command.rdb;
8
9 import java.util.Map;
10
11 import org.apache.commons.lang.StringUtils;
12 import org.asyrinx.joey.gen.model.Element;
13 import org.asyrinx.joey.gen.model.rdb.RdbEnumeration;
14 import org.asyrinx.joey.gen.model.rdb.Table;
15
16 /***
17 * @author takeshi
18 */
19 public class CopyAncestorOption extends RdbCommand {
20
21 /***
22 *
23 */
24 public CopyAncestorOption(Object optionKey) {
25 super();
26 this.optionKey = optionKey;
27 }
28
29 protected final Object optionKey;
30
31
32
33
34
35
36 public void visit(Table table) {
37 table.getOptions().put(optionKey, getOptionValue(table));
38 }
39
40
41
42
43
44
45 public void visit(RdbEnumeration enumeration) {
46 enumeration.getOptions().put(optionKey, getOptionValue(enumeration));
47 }
48
49 public String getOptionValue(Element element) {
50 final String result = getAncestorOptionValue(element);
51 if (result != null)
52 return result;
53 else
54 return (element.getParentElement() == null) ? null : element.getParentElement().getName();
55 }
56
57 protected String getAncestorOptionValue(Element element) {
58 String result = getValue(element.getOptions());
59 if (!StringUtils.isEmpty(result)) {
60 return result;
61 } else {
62 if (element.getParentElement() != null)
63 return getAncestorOptionValue(element.getParentElement());
64 else
65 return null;
66 }
67 }
68
69 private String getValue(Map options) {
70 final Object result = options.get(optionKey);
71 return (result != null) ? result.toString() : null;
72 }
73
74 }