001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id:$
023: *
024: */
025:
026: package com.bostechcorp.cbesb.common.util.generators;
027:
028: import java.util.HashMap;
029:
030: import com.bostechcorp.cbesb.common.util.TemplateProcessorIO;
031:
032: public abstract class AbstractGenerator {
033:
034: private Integer typeId; // tells what type of template will be generated
035:
036: private TemplateProcessorIO io; // I/O class
037:
038: protected HashMap paths;
039:
040: public abstract String getTemplateName();
041:
042: public HashMap getHolders() {
043: return io.getHolders();
044: }
045:
046: //protected abstract void setHolders();
047:
048: protected abstract void setPaths();
049:
050: /**
051: * Parent class for each type of code generator.
052: *
053: * @param fileOut -
054: * name of the output source file
055: * @param packageName
056: * ,className, methodName - contain the names of the
057: * method/class/package to be inputed intro the generated source
058: * file
059: */
060:
061: public AbstractGenerator(String fileOut) {
062: HashMap<String, String> m = new HashMap<String, String>();
063: paths = new HashMap<String, String>();
064: io = new TemplateProcessorIO("", fileOut, m);
065: typeId = 0;
066: setPaths();
067: setTranslateOnce(false);
068: }
069:
070: /**
071: * @return the io
072: */
073: protected TemplateProcessorIO getIo() {
074: return io;
075: }
076:
077: /**
078: * @param io
079: */
080: protected void setIo(TemplateProcessorIO io) {
081: this .io = io;
082: }
083:
084: protected void setFileIn(String file) {
085: getIo().setFileIn(file);
086: }
087:
088: public Integer getTypeId() {
089: return typeId;
090: }
091:
092: protected void setTypeId(Integer typeId) {
093: this .typeId = typeId;
094: }
095:
096: public void generateFile() throws Exception {
097: getIo().filterFile();
098: }
099:
100: public void setTranslateOnce(boolean b) {
101: getIo().setTranslateOnce(b);
102: }
103:
104: @SuppressWarnings("unchecked")
105: public void addHolder(String name, String translation) {
106: getIo().getHolders().put(name, translation);
107: }
108:
109: }
|