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: OperClass.java 9372 2007-09-29 08:06:00Z lzheng $
023: */
024: package com.bostechcorp.cbesb.common.trn.compiler;
025:
026: import java.util.Enumeration;
027: import java.util.Properties;
028:
029: import com.bostechcorp.cbesb.common.util.PropertyList;
030: import com.bostechcorp.cbesb.common.util.TabbingPrintWriter;
031: import com.bostechcorp.cbesb.common.util.macro.MacroUtil;
032:
033: public class OperClass extends AbstractOperation {
034: // for class and user operations
035: protected String className;
036:
037: protected int classIndex;
038:
039: protected Properties miscProperties = new Properties();
040:
041: protected PropertyList miscPropertyList = new PropertyList();
042:
043: protected Filter filter = new Filter();
044:
045: public OperClass(String name) {
046: super (name);
047: this .type = OpType.OPTYPE_CLASS;
048: this .className = name;
049:
050: }
051:
052: public int getClassIndex() {
053: return classIndex;
054: }
055:
056: public void setClassIndex(int classIndex) {
057: this .classIndex = classIndex;
058: }
059:
060: public String getClassName() {
061: return className;
062: }
063:
064: public void setClassName(String className) {
065: this .className = className;
066: }
067:
068: public Properties getMiscProperties() {
069: return miscProperties;
070: }
071:
072: public void setMiscProperties(Properties miscProperties) {
073: this .miscProperties = miscProperties;
074: }
075:
076: public PropertyList getMiscPropertyList() {
077: return miscPropertyList;
078: }
079:
080: public Filter getFilter() {
081: return filter;
082: }
083:
084: public void handleProperty(String propertyName, String propertyValue) {
085: miscProperties.put(propertyName, propertyValue);
086:
087: }
088:
089: public void handlePropertyList(String propertyListName,
090: String propertyName, String propertyValue) {
091:
092: miscPropertyList.putProperty(propertyListName, propertyName,
093: propertyValue);
094: if (propertyListName.equals("filter")) {
095: if (propertyName.equals("class"))
096: filter.setClassName(propertyValue);
097: else if (propertyName.endsWith("method"))
098: filter.setMethodName(propertyValue);
099:
100: }
101: }
102:
103: public void makeClassInstances(TabbingPrintWriter javaWriter,
104: String saName) {
105:
106: javaWriter.println("opClasses[" + this .getClassIndex()
107: + "] = new " + this .getClassName() + "();");
108: if (this .miscProperties != null) {
109: for (Enumeration e = this .miscProperties.propertyNames(); e
110: .hasMoreElements();) {
111: String name = (String) e.nextElement();
112: String value = MacroUtil.resolveBuiltinMacro(
113: this .miscProperties.getProperty(name), saName);
114: javaWriter.println("opClasses[" + this .classIndex
115: + "].addProperty(\"" + name + "\", \"" + value
116: + "\");");
117: }
118: }
119:
120: }
121:
122: @Override
123: public void endCode(TabbingPrintWriter javaWriter) {
124: javaWriter.println("// end " + this .className + " ");
125:
126: }
127:
128: @Override
129: public void startCode(TransformerCompiler compiler) {
130: TabbingPrintWriter javaWriter = compiler.javaWriter;
131:
132: javaWriter.println("// START " + this .className + " ");
133: javaWriter.println("inStrings = new String["
134: + this .sources.length + "];");
135: for (int i = 0; i < this .sources.length; i++)
136: javaWriter.println("inStrings[" + i + "] = dataAddresses["
137: + this .sources[i].getAddressIndex()
138: + "].getValue(sourceTree,metadataMap);");
139:
140: javaWriter.println("outStrings = new String["
141: + this .targets.length + "];");
142: javaWriter.println("opResult = opClasses[" + this .classIndex
143: + "].process(inStrings, outStrings);");
144: javaWriter.println("if (opResult) {");
145: javaWriter.addTab();
146:
147: this .filter.generateCode(javaWriter, compiler.getProjName());
148: for (int i = 0; i < this .targets.length; i++) {
149: javaWriter.println("dataAddresses["
150: + this .targets[i].getAddressIndex()
151: + "].setValue(targetDoc, outTree, outStrings[" + i
152: + "],metadataMap);");
153: }
154: javaWriter.delTab();
155: javaWriter.println("}");
156: }
157:
158: }
|