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.HashMap;
    10  import java.util.Iterator;
    11  import java.util.Map;
    12
    13  import org.apache.commons.lang.StringUtils;
    14  import org.asyrinx.joey.gen.JoeyOptions;
    15  import org.asyrinx.joey.gen.command.rdb.CopyAncestorOption;
    16  import org.asyrinx.joey.gen.command.rdb2java.PackagingStrategy;
    17  import org.asyrinx.joey.gen.model.Element;
    18  import org.asyrinx.joey.gen.model.java.Entity;
    19  import org.asyrinx.joey.gen.model.java.JavaEnumeration;
    20  import org.asyrinx.joey.gen.model.java.PackageType;
    21  import org.asyrinx.joey.gen.model.java.Type;
    22
    23  /***
    24   * @author takeshi
    25   */
    26  public class BasicPackaging implements PackagingStrategy {
    27
    28      /***
    29       *
    30       */
    31      public BasicPackaging(Map properties) {
    32          super();
    33          this.properties = properties;
    34      }
    35
    36      private final Map properties;
    37
    38      private CopyAncestorOption categoryResolver = new CopyAncestorOption(JavaOptions.CATEGORY);
    39
    40      public void preparePackageNames(Entity entity) {
    41          final Element original = entity.getOriginal();
    42          if (original == null)
    43              return;
    44          final String entityCategory = categoryResolver.getOptionValue(original);
    45          for (Iterator i = PackageType.getElements().iterator(); i.hasNext();) {
    46              fiPackageType packageType = (PackageType) i/next()/package-summary.html">nal PackageType packageType = (PackageType) i.next();
    47              final String template = (String) PACKAGE_TEMPLATES.get(packageType);
    48              final String packageName = getPackageHeader()
    49                      + StringUtils.replace(template, TEMPLATE_SYMBOL, entityCategory);
    50              entity.setPackage(packageType.getName(), packageName);
    51          }
    52      }
    53
    54      public void preparePackageName(JavaEnumeration enum) {
    55          final Element original = enum.getOriginal();
    56          if (original == null)
    57              return;
    58          final String entityCategory = categoryResolver.getOptionValue(original);
    59          final String template = (String) PACKAGE_TEMPLATES.get(PackageType.ENTITY);
    60          final</strong> String packageName = getPackageHeader() + StringUtils.replace(template, TEMPLATE_SYMBOL, entityCategory);
    61          enum.setPackageName(packageName);
    62      }
    63
    64      private static final String TEMPLATE_SYMBOL = "${category}";
    65
    66      private static final Map PACKAGE_TEMPLATES = initPackageTemplates();
    67
    68      private static Map initPackageTemplates() {
    69          final Map result = new HashMap();
    70          final String omHeader = "om." + TEMPLATE_SYMBOL;
    71          result.put(PackageType.ENTITY, omHeader + ".entity");
    72          result.put(PackageType.DAO, omHeader + ".dao");
    73          result.put(PackageType.DAO_HIBERNATE, omHeader + ".dao.hibernate");
    74          result.put(PackageType.SERVICE, omHeader + ".service");
    75          result.put(PackageType.SERVICE_IMPL, omHeader + ".service.impl");
    76          //
    77          result.put(PackageType.VIEW_SWING_COMPONENT, "swing.component." + TEMPLATE_SYMBOL);
    78          result.put(PackageType.VIEW_SWING_PAGE, "swing.mst." + TEMPLATE_SYMBOL);
    79          result.put(PackageType.VIEW_TAPESTRY_COMPONENT, "tapestry.component." + TEMPLATE_SYMBOL);
    80          result.put(PackageType.VIEW_TAPESTRY_PAGE, "tapestry.mst." + TEMPLATE_SYMBOL);
    81          //
    82          return result;
    83      }
    84
    85      public String getPackageHeader() {
    86          if (properties == null)
    87              return "";
    88          return (String) properties.get(JoeyOptions.OPTION_BASE_PACKAGE) + Type.PACKAGE_SEPARATER;
    89      }
    90  }