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.custom.code;
027:
028: import com.bostechcorp.cbesb.common.util.EsbPathHelper;
029: import com.bostechcorp.cbesb.common.util.generators.AbstractGenerator;
030:
031: public abstract class AbstractCodeGenerator extends AbstractGenerator {
032:
033: public abstract String getTemplateName();
034:
035: public final String methodNameKey = "#method#";
036: public final String classNameKey = "#class#";
037: public final String packageNameKey = "#package#";
038:
039: public final String groovyPathKey = "groovyPath";
040: public final String javaPathKey = "javaPath";
041:
042: public AbstractCodeGenerator(String fileOut) {
043: super (fileOut);
044: }
045:
046: /**
047: * @param methodName to be inputed to the new source file
048: */
049: @SuppressWarnings("unchecked")
050: public void setMethodName(String methodName) {
051: getHolders().put(this .methodNameKey, methodName);
052: }
053:
054: /**
055: * @param packageName to be input into the new source file
056: */
057: @SuppressWarnings("unchecked")
058: public void setPackageName(String packageName) {
059: getIo().getHolders().put(this .packageNameKey,
060: "package " + packageName + ";");
061: }
062:
063: /**
064: * @param className to be input into the new source file
065: */
066: @SuppressWarnings("unchecked")
067: public void setClassName(String className) {
068: getIo().getHolders().put(this .classNameKey, className);
069: }
070:
071: public String getGroovyFile() {
072: return paths.get(groovyPathKey) + getTemplateName();
073: }
074:
075: public String getJavaFile() {
076: return paths.get(javaPathKey) + getTemplateName();
077: }
078:
079: public void generateFile() throws Exception {
080: getIo().filterFile();
081: }
082:
083: @SuppressWarnings("unchecked")
084: @Override
085: protected void setPaths() {
086: paths.put(this .groovyPathKey, EsbPathHelper.getCbesbHomeDir()
087: + "/config/template/custom.code/groovy" + "/");
088: paths.put(this .javaPathKey, EsbPathHelper.getCbesbHomeDir()
089: + "/config/template/custom.code/java" + "/");
090:
091: //System.out.println("Map size ="+paths.size());
092: /*
093: for (Iterator iter = getHolders().entrySet().iterator(); iter.hasNext();)
094: {
095: Map.Entry entry = (Map.Entry) iter.next();
096: String key = (String) entry.getKey();
097: String value = (String) entry.getValue();
098: System.out.println("KxV="+key+" X " + value);
099: }
100: */
101: }
102: }
|