BeanGenerator_2

4547 ワード

public class BeanGenerator {
	/**
	 *  
	 */
	private final static String BEAN_NAME = "${beanName}";
	private final static String BEAN_SINCE = "${since}";
	private final static String BEAN_VERSION = "${version}";
	private final static String BEAN_AUTHOR = "${author}";
	private final static String BEAN_NAME_ONE_LOWER_CASE = "${beanNameOneLowerCase}";
	/**
	 *  
	 */
	private final static String BEAN_NOTE = "${beanNote}";
	private final static String BEAN_NOTE_ONE_LOWER_CASE = "${beanNoteOneLowerCase}";
	/**
	 *  
	 */
	private final static String PARAMETER_FOR_BEGIN = "${parameterBegin}";
	/**
	 *  
	 */
	private final static String PARAMETER_FOR_END = "${parameterEnd}";
	/**
	 *  
	 */
	private final static String PARAMETER_NAME = "${parameterName}";
	private final static String PARAMETER_NAME_ONE_LOWER_CASE = "${parameterNameOneLowerCase}";
	private final static String PARAMETER_NAME_ONE_UPPER_CASE = "${parameterNameOneUpperCase}";
	private final static String PARAMETER_NAME_ALL_LOWER_CASE = "${parameterNameAllLowerCase}";
	private final static String PARAMETER_NAME_ALL_UPPER_CASE = "${parameterNameAllUpperCase}";
	/**
	 *  
	 */
	private final static String PARAMETER_NOTE = "${parameterNote}";
	private final static String PARAMETER_NOTE_ONE_LOWER_CASE = "${parameterNoteOneLowerCase}";
	private final static String PARAMETER_NOTE_ONE_UPPER_CASE = "${parameterNoteOneUpperCase}";
	private final static String PARAMETER_NOTE_ALL_LOWER_CASE = "${parameterNoteAllLowerCase}";
	private final static String PARAMETER_NOTE_ALL_UPPER_CASE = "${parameterNoteAllUpperCase}";
	/**
	 *  
	 */
	private final static String PARAMETER_CLASS = "${parameterClass}";
	private final static String PARAMETER_CLASS_ONE_LOWER_CASE = "${parameterClassOneLowerCase}";
	private final static String PARAMETER_CLASS_ONE_UPPER_CASE = "${parameterClassOneUpperCase}";
	private final static String PARAMETER_CLASS_ALL_LOWER_CASE = "${parameterClassAllLowerCase}";
	private final static String PARAMETER_CLASS_ALL_UPPER_CASE = "${parameterClassAllUpperCase}";
	
	private final static String BEAN_ALL_PARAMETERS_SET = "${allParametersSet}";
	private final static String BEAN_ALL_PARAMETERS = "${allParameters}";
	private final static String BEAN_ALL_PARAMETERS_STR = "${allParametersStr}";
	private final static String BEAN_ALL_PARAMETERS_COMMENT = "${allParametersComment}";

	private String importBeanExcelPath = "";

	private String outputBasePath = "";

	private String[] templatePaths = {

	};

	private List<Bean> beans;

	private HSSFWorkbook hssfWorkbook;

	private HSSFSheet hssfSheet;

	private HSSFRow hssfRow;

	private HSSFCell hssfCell;

	private BufferedReader bufferedReader;

	public BeanGenerator(String[] templatePaths, String importBeanExcelPath,
			String outputBasePath) throws IOException {
		this.templatePaths = templatePaths;
		this.importBeanExcelPath = importBeanExcelPath;
		this.outputBasePath = outputBasePath;
		init();
	}

	public void init() throws IOException {
		File file = new File(importBeanExcelPath);
		FileInputStream fileInputStream = new FileInputStream(file);
		hssfWorkbook = new HSSFWorkbook(fileInputStream);
		if(hssfWorkbook.getNumberOfSheets()>1){
			beans = new ArrayList<Bean>(hssfWorkbook.getNumberOfSheets()-1);
		}else{
			throw new IOException("workbook has no table sheets.");
		}
	}

	/**
	 *  , EXCEL cell 
	 * @param row
	 * @param col
	 * @return
	 */
	private String cellValue(int row, int col) {
		String value = null;
		hssfRow = hssfSheet.getRow(row);
		if (Util.isNull(hssfRow))
			return null;
		hssfCell = hssfRow.getCell((short) col);
		if (Util.isNull(hssfCell))
			return null;
		value = hssfCell.getStringCellValue();
		return value.trim();
	}