View Javadoc

1   package org.appfuse.mojo.exporter;
2   
3   /*
4    * Copyright 2005 Johann Reyes.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.apache.maven.plugin.MojoExecutionException;
20  import org.appfuse.mojo.HibernateExporterMojo;
21  import org.codehaus.mojo.hibernate3.HibernateUtils;
22  import org.hibernate.tool.hbm2x.Exporter;
23  import org.hibernate.tool.hbm2x.GenericExporter;
24  
25  /**
26   * Generic exporter that can be controlled by a user provided template or class.
27   *
28   * @author <a href="mailto:jreyes@hiberforum.org">Johann Reyes</a>
29   * @version $Id$
30   * @goal hbmtemplate
31   */
32  public class GenericExporterMojo extends HibernateExporterMojo {
33      /**
34       * Default constructor.
35       */
36      public GenericExporterMojo() {
37          addDefaultComponent("target/appfuse/generic", "jdbcconfiguration", false);
38          addDefaultComponent("target/appfuse/generic", "jdbcconfiguration", true);
39      }
40  
41  // --------------------- Interface ExporterMojo ---------------------
42  
43      /**
44       * Returns <b>hbmtemplate</b>.
45       *
46       * @return String goal's name
47       */
48      public String getName() {
49          return "hbmtemplate";
50      }
51  
52      /**
53       * @see org.appfuse.mojo.HibernateExporterMojo#configureExporter(org.hibernate.tool.hbm2x.Exporter)
54       */
55      protected Exporter configureExporter(Exporter exporter) throws MojoExecutionException {
56          super.configureExporter(exporter);
57  
58          if (exporter instanceof GenericExporter) {
59              GenericExporter ge = (GenericExporter) exporter;
60              ge.setFilePattern(getComponentProperty("filepattern"));
61              ge.setTemplateName(getComponentProperty("template"));
62          }
63  
64          return exporter;
65      }
66  
67      /**
68       * Instantiates a org.hibernate.tool.hbm2x.Exporter object.
69       *
70       * @return Exporter
71       */
72      protected Exporter createExporter() {
73          String exporterClass = getComponentProperty("exporterclass");
74          if (exporterClass != null) {
75              Exporter exporter = (Exporter) HibernateUtils.getClass(exporterClass);
76              if (exporter != null) {
77                  getLog().info("Using exporter class " + exporterClass);
78                  return exporter;
79              } else {
80                  getLog().error("Could not create custom exporter class: " + exporterClass);
81              }
82          }
83          getLog().info("Using exporter class org.hibernate.tool.hbm2x.GenericExporter");
84          return new GenericExporter();
85      }
86  }