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      /***
    24       *
    25       */
    26      public CheckNameDuplication() {
    27          super();
    28      }
    29
    30      abstract protected Iterator getTargets(Element targetParent);
    31
    32      public void checkDuplication(Element targetParent) {
    33          final Set elementNames = new HashSet();
    34          for (Iterator i = getTargets(targetParent); i.hasNext();) {
    35              final Element element = (Element) i.next();
    36              if (elementNames.contains(element.getName()))
    37                  addError(element, element.getName() + " is duplicated.");
    38              else
    39                  elementNames.add(element.getName());
    40          }
    41      }
    42
    43      public static class Tables extends CheckNameDuplication {
    44          public void visit(Database database) {
    45              super.checkDuplication(database);
    46          }
    47
    48          protected Iterator getTargets(Element targetParent) {
    49              return ((Database) targetParent).getTables().iterator();
    50          }
    51      }
    52
    53      public static class Columns extends CheckNameDuplication {
    54          public void visit(Table table) {
    55              super.checkDuplication(table);
    56          }
    57
    58          protected Iterator getTargets(Element targetParent) {
    59              return ((Table) targetParent).getColumns().iterator();
    60          }
    61      }
    62
    63      public static class Enumerations extends CheckNameDuplication {
    64          public void visit(Database database) {
    65              super.checkDuplication(database);
    66          }
    67
    68          protected Iterator getTargets(Element targetParent) {
    69              return ((Database) targetParent).getEnumerations().iterator();
    70          }
    71      }
    72
    73      public static class EnumerationEntries extends CheckNameDuplication {
    74          public void visit(RdbEnumeration enumeration) {
    75              super.checkDuplication(enumeration);
    76          }
    77
    78          protected Iterator getTargets(Element targetParent) {
    79              return ((RdbEnumeration) targetParent).iterator();
    80          }
    81      }
    82  }