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/10 9:43:18
    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.command.rdb2java.standard.JavaOptions;
    13  import org.asyrinx.joey.gen.model.Element;
    14  import org.asyrinx.joey.gen.model.rdb.RdbEnumeration;
    15  import org.asyrinx.joey.gen.model.rdb.Table;
    16
    17  /***
    18   * @author takeshi
    19   */
    20  public class CopyPackageNames extends RdbCommand {
    21
    22      /***
    23       *
    24       */
    25      public CopyPackageNames() {
    26          super();
    27      }
    28
    29      /*
    30       * (non-Javadoc)
    31       *
    32       * @see org.asyrinx.joey.gen.command.rdb.RdbCommand#visit(org.asyrinx.joey.gen.model.rdb.Table)
    33       */
    34      public void visit(Table table) {
    35          table.getOptions().put(JavaOptions.JAVA_PACKAGE, toPackageName(table));
    36      }
    37
    38      /*
    39       * (non-Javadoc)
    40       *
    41       * @see org.asyrinx.joey.gen.command.rdb.RdbCommand#visit(org.asyrinx.joey.gen.model.rdb.RdbEnumeration)
    42       */
    43      public void visit(RdbEnumeration enumeration) {
    44          enumeration.getOptions().put(JavaOptions.JAVA_PACKAGE, toPackageName(enumeration));
    45      }
    46
    47      public String getPackage(Map options) {
    48          final Object result = options.get(JavaOptions.JAVA_PACKAGE);
    49          return (result != null) ? result.toString() : null;
    50      }
    51
    52      /*
    53       * (non-Javadoc)
    54       *
    55       * @see org.asyrinx.joey.gen.command.rdb2java.standard.PackagingStrategy#toPackageName(org.apache.commons.lang.enum.Enum)
    56       */
    57      public String toPackageName(RdbEnumeration enum) {
    58          final String result = toPackageNameImpl(enum);
    59          if (result != null)
    60              return result;
    61          else
    62              return (enum.getParent() == null) ? null : enum.getParent().getName();
    63      }
    64
    65      /*
    66       * (non-Javadoc)
    67       *
    68       * @see org.asyrinx.joey.gen.command.rdb2java.standard.PackagingStrategy#toPackageName(org.asyrinx.joey.gen.model.rdb.Table)
    69       */
    70      public String toPackageName(Table table) {
    71          final String result = toPackageNameImpl(table);
    72          if (result != null)
    73              return result;
    74          else
    75              return (table.getParent() == null) ? null : table.getParent().getName();
    76      }
    77
    78      protected String toPackageNameImpl(Element element) {
    79          String result = getPackage(element.getOptions());
    80          if (!StringUtils.isEmpty(result)) {
    81              return result;
    82          } else {
    83              if (element.getParentElement() != null)
    84                  return toPackageNameImpl(element.getParentElement());
    85              else
    86                  return null;
    87          }
    88      }
    89  }