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/11/09 16:32:12
6    */
7   package org.asyrinx.joey.gen.command.rdb;
8   
9   import java.util.HashSet;
10  import java.util.Iterator;
11  import java.util.Set;
12  
13  import org.asyrinx.joey.gen.model.Element;
14  import org.asyrinx.joey.gen.model.rdb.Database;
15  import org.asyrinx.joey.gen.model.rdb.RdbEnumeration;
16  import org.asyrinx.joey.gen.model.rdb.Table;
17  
18  /***
19   * @author takeshi
20   */
21  public abstract class CheckNameDuplication extends RdbCommand {
22  
23      abstract protected Iterator getTargets(Element targetParent);
24  
25      public void checkDuplication(Element targetParent) {
26          final Set elementNames = new HashSet();
27          for (Iterator i = getTargets(targetParent); i.hasNext();) {
28              final Element element = (Element) i.next();
29              if (elementNames.contains(element.getName()))
30                  addError(element, element.getName() + " is duplicated.");
31              elementNames.add(element.getName());
32          }
33      }
34  
35      public static class Tables extends CheckNameDuplication {
36          public void visit(Database database) {
37              super.checkDuplication(database);
38          }
39  
40          protected Iterator getTargets(Element targetParent) {
41              return ((Database) targetParent).getTables().iterator();
42          }
43      }
44  
45      public static class Columns extends CheckNameDuplication {
46          public void visit(Table table) {
47              super.checkDuplication(table);
48          }
49  
50          protected Iterator getTargets(Element targetParent) {
51              return ((Table) targetParent).getColumns().iterator();
52          }
53      }
54  
55      public static class Enumerations extends CheckNameDuplication {
56          public void visit(Database database) {
57              super.checkDuplication(database);
58          }
59  
60          protected Iterator getTargets(Element targetParent) {
61              return ((Database) targetParent).getEnumerations().iterator();
62          }
63      }
64  
65      public static class EnumerationEntries extends CheckNameDuplication {
66          public void visit(RdbEnumeration enumeration) {
67              super.checkDuplication(enumeration);
68          }
69  
70          protected Iterator getTargets(Element targetParent) {
71              return ((RdbEnumeration) targetParent).iterator();
72          }
73      }
74  }