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/10/27 2:31:31
    6    */
    7   package org.asyrinx.joey.gen.command.rdb2java.standard;
    8
    9   import java.util.Iterator;
    10  import java.util.List;
    11
    12  import org.asyrinx.brownie.core.lang.StringUtils;
    13  import org.asyrinx.joey.gen.command.rdb2java.NamingStrategy;
    14  import org.asyrinx.joey.gen.model.Element;
    15  import org.asyrinx.joey.gen.model.rdb.Column;
    16  import org.asyrinx.joey.gen.model.rdb.Databases;
    17  import org.asyrinx.joey.gen.model.rdb.RdbEnumeration;
    18  import org.asyrinx.joey.gen.model.rdb.Table;
    19
    20  /***
    21   * @author takeshi
    22   */
    23  public class BasicNaming implements NamingStrategy {
    24
    25      /***
    26       *
    27       */
    28      public BasicNaming() {
    29          super();
    30      }
    31
    32      private char separator = '_';
    33
    34      protected String doUnderscoreBasedNaming(String schemaName) {
    35          final StringBuffer result = new StringBuffer();
    36          final List parts = StringUtils.tokenize(schemaName, String.valueOf(getSeparator()));
    37          for (Iterator i = parts.iterator(); i.hasNext();) {
    38              String namePart = i.next().toString().toLowerCase();
    39              result.append(StringUtils.capitalize(namePart));
    40          }
    41          return result.toString();
    42      }
    43
    44      protected String toName(Element element) {
    45          final Object optionName = element.getOptions().get(JavaOptions.JAVA_NAME);
    46          return (optionName != null) ? optionName.toString() : doUnderscoreBasedNaming(element.getName());
    47      }
    48
    49      private final String[] EnumPropertyDeleteTargets = new String[] { "Id", "Cd", "Code", "No" };
    50
    51      /*
    52       * (non-Javadoc)
    53       *
    54       * @see org.asyrinx.joey.gen.command.rdb2java.standard.NamingStrategy#toEnumPropertyName(java.lang.String)
    55       */
    56      public String toEnumPropertyName(String name) {
    57          for (int i = 0; i < EnumPropertyDeleteTargets.length; i++) {
    58              if (name.endsWith(EnumPropertyDeleteTargets[i])) {
    59                  return name.substring(0, name.length() - EnumPropertyDeleteTargets[i].length());
    60              }
    61          }
    62          return name + "Enum";
    63      }
    64
    65      /*
    66       * (non-Javadoc)
    67       *
    68       * @see org.asyrinx.joey.gen.command.rdb2java.standard.NamingStrategy#toClassName(org.asyrinx.joey.gen.model.rdb.Table)
    69       */
    70      public String toAppDomainName(Databases databases) {
    71          return toName(databases);
    72      }
    73
    74      /*
    75       * (non-Javadoc)
    76       *
    77       * @see org.asyrinx.joey.gen.command.rdb2java.standard.NamingStrategy#toEnumerationName(org.asyrinx.joey.gen.model.rdb.RdbEnumeration)
    78       */
    79      public String toEnumerationName(RdbEnumeration enumeration) {
    80          return null;
    81      }
    82
    83      /*
    84       * (non-Javadoc)
    85       *
    86       * @see org.asyrinx.joey.gen.command.rdb2java.standard.NamingStrategy#toClassName(org.asyrinx.joey.gen.model.rdb.Table)
    87       */
    88      public String toClassName(Table table) {
    89          return toName(table);
    90      }
    91
    92      /*
    93       * (non-Javadoc)
    94       *
    95       * @see org.asyrinx.joey.gen.command.rdb2java.standard.NamingStrategy#toPropertyName(org.asyrinx.joey.gen.model.rdb.Column)
    96       */
    97      public String toPropertyName(Column column) {
    98          return StringUtils.uncapitalize(toName(column));
    99      }
    100
    101     /***
    102      * @return Returns the separator.
    103      */
    104     public char getSeparator() {
    105         return separator;
    106     }
    107
    108     /***
    109      * @param separator
    110      *            The separator to set.
    111      */
    112     public void setSeparator(char separator) {
    113         this.separator = separator;
    114     }
    115 }