package org.apache.maven.hibernate.beans;

/* ====================================================================
 *   Copyright 2001-2004 The Apache Software Foundation.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * ====================================================================
 */

import net.sf.hibernate.tool.hbm2java.CodeGenerator;

/**
 * @author <a href="paulkearney@gmail.com">Paul Kearney</a> 
 * @version $Id$
 */
public class CodeGenerationBean extends CommonOperationsBean {
    
    private static final String OUTPUT_SWITCH = "--output=";
    
    private String outputdir = null;
    
    public void execute() {
        
        // Construct output directory argument    
        StringBuffer switchArg= new StringBuffer();
        switchArg.append(OUTPUT_SWITCH).append(getOutputdir());
        
        // Get list of files that are to be used to generate POJOs
        final String[] files = getFileNames();
        
        // Require new array to combine command args with hbm files array
        String[] args  = new String[files.length + 1];
        // Add command arg to new array
        args[0] = switchArg.toString();
        // Copy list of hbm files to new array
        System.arraycopy(files, 0, args, 1, files.length);
                        
        // Generate POJOs
        CodeGenerator generator = new CodeGenerator(); 
        generator.main(args);  
        
    }    
    
    public String getOutputdir() {
        return this.outputdir;
    }
        
    public void setOutputdir(String outputdir) {        
        this.outputdir = outputdir;
    }    
}
