View Javadoc

1   package org.apache.maven.hibernate.beans;
2   
3   /* ====================================================================
4    *   Copyright 2001-2004 The Apache Software Foundation.
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  
20  import net.sf.hibernate.tool.hbm2java.CodeGenerator;
21  
22  /**
23   * @author <a href="paulkearney@gmail.com">Paul Kearney</a> 
24   * @version $Id$
25   */
26  public class CodeGenerationBean extends CommonOperationsBean {
27      
28      private static final String OUTPUT_SWITCH = "--output=";
29      
30      private String outputdir = null;
31      
32      public void execute() {
33          
34          // Construct output directory argument    
35          StringBuffer switchArg= new StringBuffer();
36          switchArg.append(OUTPUT_SWITCH).append(getOutputdir());
37          
38          // Get list of files that are to be used to generate POJOs
39          final String[] files = getFileNames();
40          
41          // Require new array to combine command args with hbm files array
42          String[] args  = new String[files.length + 1];
43          // Add command arg to new array
44          args[0] = switchArg.toString();
45          // Copy list of hbm files to new array
46          System.arraycopy(files, 0, args, 1, files.length);
47                          
48          // Generate POJOs
49          CodeGenerator generator = new CodeGenerator(); 
50          generator.main(args);  
51          
52      }    
53      
54      public String getOutputdir() {
55          return this.outputdir;
56      }
57          
58      public void setOutputdir(String outputdir) {        
59          this.outputdir = outputdir;
60      }    
61  }