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:38:38
    6    */
    7   package org.asyrinx.joey.gen.command.rdb2java.standard;
    8
    9   import java.util.Iterator;
    10
    11  import org.apache.commons.lang.StringUtils;
    12  import org.asyrinx.joey.gen.command.rdb.CopyAncestorOption;
    13  import org.asyrinx.joey.gen.command.rdb2java.PackagingStrategy;
    14  import org.asyrinx.joey.gen.model.Element;
    15  import org.asyrinx.joey.gen.model.java.Entity;
    16  import org.asyrinx.joey.gen.model.java.JavaEnumeration;
    17  import org.asyrinx.joey.gen.model.java.PackageType;
    18
    19  /***
    20   * @author takeshi
    21   */
    22  public class SimplePackaging implements PackagingStrategy {
    23
    24      /***
    25       *
    26       */
    27      public SimplePackaging() {
    28          super();
    29      }
    30
    31      private CopyAncestorOption copyPackageNames = new CopyAncestorOption(JavaOptions.JAVA_PACKAGE);
    32
    33      /*
    34       * (non-Javadoc)
    35       *
    36       * @see org.asyrinx.joey.gen.command.rdb2java.standard.PackagingStrategy#getPackageName(org.asyrinx.joey.gen.model.Element)
    37       */
    38      public String getPackageName(Element element) {
    39          return copyPackageNames.getOptionValue(element);
    40      }
    41
    42      public static final String PACKAGE_TEMPLATE_SYMBOL = "${packageType}";
    43
    44      /*
    45       * (non-Javadoc)
    46       *
    47       * @see org.asyrinx.joey.gen.command.rdb2java.standard.PackagingStrategy#preparePackageNames(org.asyrinx.joey.gen.model.java.Entity)
    48       */
    49      public void preparePackageNames(Entity entity) {
    50          final String template = entity.getPackageTemplate();
    51          for (Iterator i = PackageType.getElements().iterator(); i.hasNext();) {
    52              fiPackageType packageType = (PackageType) i/next()/package-summary.html">nal PackageType packageType = (PackageType) i.next();
    53              entity.setPackage(packageType.getName(), genPackageName(template, packageType));
    54          }
    55      }
    56
    57      /***
    58       * @param template
    59       * @param packageType
    60       * @return
    61       */
    62      privatePackageType packageType) {/package-summary.html">ong> String genPackageName(final String template, final PackageType packageType) {
    63          final</strong> String packageName = StringUtils.replace(template, PACKAGE_TEMPLATE_SYMBOL, packageType.getName());
    64          return</strong> packageName;
    65      }
    66
    67      /*
    68       * (non-Javadoc)
    69       *
    70       * @see org.asyrinx.joey.gen.command.rdb2java.standard.PackagingStrategy#preparePackageName(org.asyrinx.joey.gen.model.java.JavaEnumeration)
    71       */
    72      public void preparePackageName(JavaEnumeration enum) {
    73          enum.setPackageName(genPackageName(enum.getPackageName(), PackageType.ENTITY));
    74      }
    75
    76  }